Overall step generalization

  • Prepare two VMS for minimum installation. If the IP address can ping the external network, install the Docker
  • One virtual machine runs GitLab and one runs GitLab Runner and Springboot projects
  • Type the Springboot project into the Systemctl system service
  • Write gitlab.ci to automatically build your SpringBoot project

The basic idea of automatic build is that when the dev branch is merged into the Master branch, the build is triggered and automatically published. Here are the steps

1. Build gitlab by Docker and Docker-compose

It uses an open source library

Github.com/sameersbn/d…

This step basic reference to this library can be built successfully

  • Make sure you have Docker and Docker-compose installed
  • Download the official docker-compose filewget https://raw.githubusercontent.com/sameersbn/docker-gitlab/master/docker-compose.ymlMake two changes

    Gitlab_port is the address of the port you are accessing, and gitlab_host is the IP address of the virtual machine that you are configuring. Your directory structure should look like this

    CD to the gitlab directory and run the commanddocker-compose upWait a few minutes after the Docker image installation completes, gitLab initialization, visit http://yourdomain:10080, and reset the password

    So now that I’ve built the project, I’m done with the first step of building the GitLab service and then I’m done with the second step

2. Register Gitlab-Runner to complete automatic construction of the project

  • New Dev branch

    Checkout your dev branch, dev branch only, master branch for CI build

  • Write gitlab – ci. Yml
pages:
  stage: deploy
  script:
    - cd /gitlab-project/demo
    - git pull
    - mvn package
    - systemctl restart demo
  only:
    - master
Copy the code

You can see that CI is only for the master branch, that is, when the dev branch merges into the master branch, the build is triggered

  • Before, it was said that two servers need to be prepared, one to build gitlab and the other to build Runner Gitlab-Runner is relatively simple, check how to install it, and input after installation
gitlab-ci-multi-runner register
Please enter the gitlab-ci coordinator URL (e.g. https://gitlab.com/):
Enter your Gitlab domain name here
# executor type shell
Copy the code

Domain names and tokens are at Specific Runners

Description=demo [Service] WorkingDirectory=/gitlab-project/demo PrivateTmp=true Type=simple ExecStart = / usr/Java/jdk1.8.0 _181 amd64 / bin/Java jar/gitlab - project/demo/target/demo - 0.0.1 - the SNAPSHOT. The jar -java.io.tmpdir=/gitlab-project/tmp --spring.config.location=/gitlab-project/demo/target/classes/application.yml ExecStop=kill -9 `ps -ef|grep java|grep -v grep|grep demo|awk '{print $2}'` [Install] WantedBy=multi-user.targetCopy the code

Gitlab-project /demo is the path of the demo project, you should git clone the project to the corresponding path before ci

3. Last step

Now an interface of the project returns data like this

Let’s change that

Select the corresponding job to check that the job is already running

A curl

Why don’t you guys try it?