Gitlab has in built pipeline for continuous integration and deployment. For every commit to the master branch , Gitlab CI will build and deploy my code to two(dev and staging) different Environments.
Prerequisites
- Gitlab free account https://gitlab.com/
- Heroku free account https://www.heroku.com
- Created a new project in gitlab.com git@gitlab.com:velmuruganv/ci-api.git
- I have generated a new Spring-Boot application using http://start.spring.io/
- Add
.gitlab-ci.yml to the root of the project source code.
- Created a two new application(vel-ci-api-dev and vel-ci-api-stg) in heroku-dashboard
Below is the .gitlab-ci.yml I use to build and deploy the application dev and staging environments
before_script: - echo "Execute scripts which are required to bootstrap the application. !" after_script: - echo "Clean up activity can be done here !." cache: paths: - /root/.m2/repository stages: - build - deploy build: stage: build image: maven:3.3.9-jdk-8 script: - mvn clean package tags: - docker deploy_dev: stage: deploy image: ruby:2.3 script: - apt-get update -qy - apt-get install -y ruby-dev - gem install dpl - dpl --provider=heroku --app=vel-ci-api-dev --api-key=$HEROKU_API_KEY environment: name: dev url: https://vel-ci-api-dev.herokuapp.com only: - master tags: - docker deploy_staging: stage: deploy image: ruby:2.3 script: - apt-get update -qy - apt-get install -y ruby-dev - gem install dpl - dpl --provider=heroku --app=vel-ci-api-stg --api-key=$HEROKU_API_KEY environment: name: staging url: https://vel-ci-api-stg.herokuapp.com only: - master tags: - docker
I have two stages , build and deploy
build stage has only one job – build
deploy stage has two jobs – deploy_dev , deploy_staging
All the jobs in the same stage will be run parallel.
Below are the environments it gets deployed the application.
Application URL’s
https://vel-ci-api-dev.herokuapp.com — Dev Environment.
https://vel-ci-api-stg.herokuapp.com/ — Staging Environment.
Hello,
First of all thanks for creating this article on this subject.
I am trying to deploy a SpringBoot app (generating a RESTful API connected to a PostGreSQL database) using Gilab and Heroku (which are fairly new frameworks for me).
Concerning your article i have a question about the variable here $HEROKU_API_KEY.
Could you explain how and where you define that variable ?
Regards
LikeLike
sure, These variables are picked by the gitlab-ci-runners while executing the jobs defined in the gitlab-ci.yml file. To add a new variable follow the below steps.
Settings –> CI/CD pipeline , Look for a section “secret variables” as below.
http://imgur.com/a/A2JSb
LikeLike
Pingback: Review Apps for Spring-Boot using Gitlab CI & Heroku | Velmurugan Velayutham
Hi Vel,
Thank you very much for this great article. But I have a couple of questions.
1) my first question is about the runners, it looks like you didn’t register any runners. How does that possible ? Can you explain that part please ?
2) my second question is about RUBY, you used image ruby in the deploy_dev and staging jobs, why did you use Ruby, is there another one that we can use ?
Thanks in advance for your reply.
Best
LikeLike
If you have a repo in gitlab.com , by default runners are enabled. If you have your own gitlab server , then you need to install and configure the runners.
2. As i am deploying my spring boot application into Heroku , I need ruby packages. As per your deployment requirement, you can use any images that fits your needs.
Hope this clarifies your question!.
LikeLike