Continuous integration

Continuous Integration (CI) refers to the frequent (multiple times a day) Integration of code into the trunk. Docker + Gitlab CI continuous integration (1) Docker + Gitlab CI continuous integration (2)

GitLab CI is a continuous integration service provided by GitLab. By default, it has three [stages]: Build, test, and deploy. Most projects use CI to run build tests

So how do you do it with GitLab CI?

1, first need to start a runner service

runnernamelybuildThe host of the build script

docker pull gitlab/gitlab-runner
Copy the code
docker run -d --name gitlab-runner --restart always   -v /srv/gitlab-runner/config:/etc/gitlab-runner   -v /var/run/docker.sock:/var/run/docker.sock   gitlab/gitlab-runner:latest
Copy the code

With the experience of the first two chapters, I soon started a runner service. How could it be related to our code?

Registered runner

docker exec -it gitlab-runner gitlab-ci-multi-runner register
Copy the code
# gitlab-runner register Please enter the gitlab-ci coordinator URL: # XXX Please enter the gitlab-ci token for this runner: // Build project provide token # XXXXXX Please enter the gitlab-ci description for this runner: # docker Please enter the gitlab-ci tags for this runner (comma separated): Job # zb Please enter the executor: docker, parallels, shell, kubernetes, docker-ssh, ssh, virtualbox, docker+machine, docker-ssh+machine: # docker Please enter the default docker image (e.g. ruby:2.1)Copy the code

Where do the URL and token of step 1 and step 2 come from?

Go to gilab to build the project, Settings —-> CI/CD ——> Runners, as shown below:

After registering step by step, gitLab will have our runner service

2. Create the project root directorygitlab-ci.ymlfile


cache:
  untracked: true
  paths:
    - node_modules/

stages:
  - build
  
npm_production:
  stage: build
  script:
  - pwd
  - docker build -t test-test .
  tags:
  - zb
  only:
  - master
Copy the code

This article is just a demonstration build of a new image named test-test. At this time, push code on master will trigger GitLab CI build and start zB runner to execute the script under script

After the construction is successful, this image will be available on the server. The rest of the work is to run based on this image. Jenkins can also be used to complete this step

If the article is not appropriate, welcome to criticize and correct ~