GitLab Spring-Boot Heroku Continuous Integration and Deployment – part 2 (Review Apps)

In the previous post Gitlab-CI-Spring-Boot-Heroku-Continuous-integration-and-Deployment/, Every commit to master branch , Gitlab CI will build and deploy the application to two different environments (dev and stage). This is great. How about creating a new dynamic environment for every new merge request (branch) ? . The Repository owner can review the merge request and provide you the immediate feedback. Yes ! That is called “Review Apps” Review Apps

Objective:

  • Developers create a new branch “feature-xyz” and start implementing the features which he is supposed to complete as part of the Agile development process.
  • Developers commits the code, test it locally before pushing the branch to remote repository.
  • As soon as the branch (feature-xyz) is pushed to repository, Gitlab CI will trigger the pipeline ,which will deploy the feature branches into a  new dynamic environment.
merge-request-environment

Merge Request Environment

When a merge request is created , the corresponding dynamic environment is shown in the page as shown above.

dynamic environments

All the dynamic environments are grouped under review

environments-review

All the deployed environments are grouped under “Review”

As I have four feature branches in my repository , four environments get deployed by Gitlab CI. Each dynamic environment will be deleted once the corresponding branch is deleted. It can also be stopped manually from the Gitlab UI.

 

The complete gitlab-ci.yml is shown below.

Review : Responsible for creating a new environment for every new branch

Stop_Review : Responsible for deleting the environment whenever the branch is deleted or manually stopped from Gitlab UI.

Gitlab Source Code of this repo

 

Advertisements

GitLab Spring-Boot Heroku Continuous Integration and Deployment – part 1

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 

  1. Gitlab free account https://gitlab.com/
  2. Heroku free account https://www.heroku.com

 

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

pipe-line-success

Pipeline-stages-builds

All the jobs in the same stage will be run parallel.

Below are the environments it gets deployed the application.

environments

Environments

 

Application URL’s

https://vel-ci-api-dev.herokuapp.com — Dev Environment.

https://vel-ci-api-stg.herokuapp.com/ — Staging Environment.