Another series – another way of CI/CD

In the past, Jenkins was the most commonly used method for CICD. Since I started to know CICD, Jenkins has been used in most projects.

A new approach to CICD was recently tried ———— using GITLAB CICD

Gitlab CICD

Gitlab Runner

With Jenkins, we install Jenkins on a machine that does some of the dirty work of packing. In the context of GITLAB CICD, we use Runner to do this part of the work. Runner is definitely worth a lot of space on its own, but as a primer, we need to know how to configure and use the basics.

Gitlab Runner configuration

Runner is essentially a service on a machine. First of all, you need to have a machine, which can be a different operating system, or even a virtual machine.

Detailed process of installationYou can refer to the documentation, I am looking for a Linux machine, the general process is as follows



The Token related information can be found in your project information.

After the configuration is complete, refresh the page and you can see the corresponding runner

Use Gitlab Runner

With Jenkins, we organize the entire pipeline using Jenkinsfile, and there is a similar file in Gitlab CICD called.gitlab-ci.yml.

GitLab actually provides shared Runners. You can also specify private Runners by yourself. The specified rules can be based on tags. My YML file looks something like this

stages: - maven-test - maven-build - docker-build before_script: - export IMAGE_TAG = $(echo - en $CI_COMMIT_REF_NAME | tr - c '[: alnum:] _. -' a '-') maven - test: image: maven: 3.3 JDK - eight stages: Maven-test script: "MVN clean PMD :check" tags: -aliyun maven-build: image: maven:3.3-jdk-8 stage: maven-build script:" MVN clean PMD :check" tags: -aliyun maven-build: image: maven:3.3-jdk-8 stage: maven-build script: ' mvn package -B' artifacts: paths: - target/*.jar tags: - aliyun only: - beta - release - tags docker-build: stage: docker-build script: - docker build -t registry.cn-shanghai.aliyuncs.com/yycao/demo:${IMAGE_TAG} . - docker login -u $CI_BUILD_USER -p $CI_BUILD_TOKEN registry.cn-shanghai.aliyuncs.com - docker push registry.cn-shanghai.aliyuncs.com/yycao/demo:${IMAGE_TAG} only: - beta - release - tags

Some of these fields relate to project security and can also be set within CICD

The simplest Java Spring project

Using one of Spring’s simplest projects as an example, it is simple to containerize. Docker file as follows

Jar FROM Java :8 VOLUME/TMP COPY /target/ demo-0.0.1-jar app.jar RUN sh-c 'touch /app.jar' ENV JAVA_OPTS=" ENTRYPOINT [ "sh", "-c", "java $JAVA_OPTS -Djava.security.egd=file:/dev/./urandom -jar /app.jar" ]

CI line

Finally, submit the code to the preset branch and the packaging will start automatically. CI part completed