Spring WebFlux continuous deployment (CI/CD)
Spring-Webflux-Tools
Simply use github web-hook and spring boot devtools to create automatic deployment for your spring webflux application. On your push to remote branch, application is refreshed with new code using devtools hot reload and restarts. Change propagation from your local to remote server is :
- easy
- fast
- simple
Pre requisites
- This is packaged as maven dependency and works with Java 14
- Your remote/server should have git
- Your remote/server should maven installed
How to use ?
- Add following repository to your pom.xml of maven project
<repository>
<id>github</id>
<name>grsdev7 maven github repo</name>
<url>https://maven.pkg.github.com/goro-79/artifacts</url>
</repository>
- Add following to your pom dependencies
<dependency>
<groupId>live.goro.common</groupId>
<artifactId>spring-webflux-deployer</artifactId>
<version>0.1</version>
</dependency>
- Define following functional api endpoint to your main spring boot application class or configuration class
@Bean
RouterFunction routers() {
return RefreshFns.router();
}
- Add vm argument -Dtest, because otherwise when we test on local system your changes can get lost
as this utility uses ‘git hard reset’. Check if your application is compiling and running ?
Now, Try to access api which this tool adds for hot deployments using
curl -X POST localhost:8080/refresh
Good news, Your app is ready. Push changes and redeploy your app on the remote machine. Try to hit the above end point again but now with address of your remote server.
Set up Github web-hook for your application’s repository and configure it to send post request to refresh endpoint which we just created. You can refer this official simple guide about creating web-hook: Tutorial on how to create webhook on your app repository
Now whenever you will push changes to github, you remote server will do refresh.
Happy Coding … :D
Note - You can check demo app here - demo