8624. Continuously Deploy Spring Boot App to Heroku with Travis-CI
Heroku and Travis CI


Introduce how to deploy Spring Boot RESTful API to Heroku with Travis-CI.

1. Spring Boot

1.1 Source Files

Download the source files for this Spring Boot app. Create your own repository on GitHub and submit this project.

git clone https://github.com/jojozhuang/restful-api-springboot.git

1.2 Procfile

To teach Heroku how to deploy the app correctly, create a new file with name Procfile in the root path of our project. Submit this file to GitHub.

web: java $JAVA_OPTS -Dserver.port=$PORT -jar target/*.jar -Dspring.profiles.active=prod

1.3 Travis Config File

Create a file named ‘.travis.yml’ in the root folder. Submit this file to GitHub as well.

language: java
jdk:
 - oraclejdk8
deploy:
  provider: heroku
  api-key:
    secure: $HEROKU_API_KEY
  app: gamestore-api

2. Heroku

Login to Heroku https://www.heroku.com/, go to Dashboard -> New -> Create new app. Set app name ‘gamestore-api’, click ‘Create app’ button. image In addition, go to ‘Account settings’, copy the ‘API Key’. We will use it to setup continuous integration on Travis. image

In case, the continuous deployment doesn’t work. Try to deploy it to Heroku manually first.

cd restful-api-springboot
heroku create gamestore-api
git push heroku master

3. Travis

Login to https://travis-ci.com/, then go to ‘Profile’, click ‘Manage repositories on GitHub’. image You will be navigated to GitHub, select ‘restful-api-springboot’ and save. image Go back to Travis, refresh, ‘restful-api-springboot’ is integrated to Travis. image Click the ‘Settings’ of the new repository. Keep the default settings for ‘General’ and ‘Auto Cancellation’. image In the ‘Environment Variables’ section, paste your Heroku API Key in the field ‘Value’ and name it ‘HEROKU_API_KEY’, click ‘Add’ button. image

4. Deployment

Make any change to your Spring Boot app and submit it to Github. Once Travis notice the new submission, it starts to build the app according to the instructions configured in ‘.travis.yml’ file. image If the build is finished successfully, your site is deployed to Heroku. image

5. Testing

Go to Heroku, you should see the new app in the dashboard. image Click on it, and switch to ‘Setting’ tab. You should find the link, it is the root url of the RESTful API. image Access https://gamestore-api.herokuapp.com/api/products in browser, we see it returns data. image

6. References