Full Stack Software Development Blog
The final task to finishing off the server work is to wire up continuous integration and continuous deployment (CICD). I already have the CI piece of it working (see previous blog). Now to do the CD piece.
Step 1. Deploy Spring Boot application to Heroku
I followed the steps in the getting started on Heroku with Java tutorial.See https://devcenter.heroku.com/articles/getting-started-with-java
The only thing of interest is the Procfile
web: java -jar application/target/texastoc-application-1.0.jar --server.port=$PORT --spring.profiles.active=test com.texastoc.Application
As you can see the Spring Boot application is run as a jar.
Set the server port as instructed by Heroku.
Set the spring.profiles.active to test so the it would use the embedded H2 database (for now).
Step 2. Integrate CircleCI to deploy to Heroku
Next I followed the CircleCI instructions to integrate with Heroku.See https://circleci.com/integrations/heroku/
First I had to set a couple environment variables
- HEROKU_APP_NAME
- HEROKU_API_KEY
See https://github.com/gpratte/texastoc-v2-spring-boot/blob/master/.circleci/config.yml
Step 3. Spring Actuator
I needed to verify the deployment. What better way than to add a new endpoint (or two) to the server, push to github master and then curl the endpoint on the server deployed to Heroku.I added Spring Actuator and curled the health endpoint.
See https://docs.spring.io/spring-boot/docs/current/reference/html/production-ready.html to know more about Spring Actuator.