DEV Community

sanjay shivanna
sanjay shivanna

Posted on • Updated on

Spring boot +Docker+ Gitlab - Continuous Integration(CI)

A simple example to demonstrate, how we can use spring boot, docker and gitlab for build and test using maven, create an image and push it to gitlab repository.

Step 1 - Create a Gitlab account
If you already familiar with gitlab then feel free to skip this section, otherwise create a gitlab account by following this link Link

Step 2 - Create a New Project in Gitlab
Once you successfully created Gitlab account then create a new project

Alt Text

Step 3 - Create a New Spring boot project
Simple and easiest way to create spring boot project is to visit

Alt Text

Once you have the project created, use the choice of your editor to open the project.

Step 4 - Add Dockerfile and Update file
Docker file

FROM openjdk:13-alpine
Volume /tmp
ADD /target/*.jar springbootgitlab-0.0.1-SNAPSHOT.jar
ENTRYPOINT ["java","-jar","/springbootgitlab-0.0.1-SNAPSHOT.jar"]
Enter fullscreen mode Exit fullscreen mode

gitlab-ci yml file

image: gitlab/dind
  - docker:dind

  DOCKER_DRIVER: overlay
  USER_GITLAB: sanjaybsm
  APP_NAME: springbootgitlab
  REPO: springbootlabtest

  - build
  - test
  - docker

  image: maven:3-jdk-8
  stage: build
  script: "mvn clean package -B"
      - target/*.jar

  image: maven:3-jdk-8
  stage: test
  script: "mvn test"
      - target/*.jar

  stage: docker
    - docker login -u gitlab-ci-token -p $CI_JOB_TOKEN $CI_REGISTRY
    - docker build -t .
    - docker push
Enter fullscreen mode Exit fullscreen mode

please note test mvn test is added just as an example

For above project I used packaging as jar since my dockerfile and gitlab yml files configured like that.

Step 5 - Commit and Push to gitlab!
git add .
git commit -m "initial commit"
git push origin master

After above step, you should see your gitlab pipeline kicking in!!
Alt Text

and also you should see your image available in container registry!
Alt Text

Voila!! you have successfully used gitlab ci/cd pipeline to build, test, create image and push image to gitlab container registry!

In the next blog I will try to explain how we can download docker image from gitlab and run it from local machine!

Top comments (0)