Basic concepts for CI/CD can be found in other posts, including Jobs, Pipeline, stages, etc. This article introduces the complete CI/CD setup environment.

  1. Installation, registration, and start the runner, docs.gitlab.com/runner/inst… , take installing Runner in GNU/ Linux as an example:
// Download RPM, Centos/red hat] # curl - LJO "https://gitlab-runner-downloads.s3.amazonaws.com/latest/rpm/gitlab-runner_amd64.rpm" / / installation ] # RPM -i gitlab - runner_amd64. RPM / / registered runner] # gitlab - runner register Enter tags for the runner (comma - separated) : wx-haha-go Registering runner... succeeded runner=_9zz4yAQ Enter an executor: custom, docker-ssh, parallels, shell, ssh, docker+machine, kubernetes, docker, virtualbox, docker-ssh+machine: shell Runner registered successfully. Feel free to start it, but if it's running already the config should be automatically reloaded! # gitlab-runner start Runtime Platform Arch =amd64 OS = Linux pid=11797 Revision =2ebc4dc4 version=13.9.0Copy the code

Executor is where a runner performs a build, such as a shell or docker.

  1. Write the automatic integration script.gitlab-ci.yml and place it in the project root directory
stages:
  - build
  - test
  - push
  - deploy

build_job:
  stage: build
  script:
    - make docker-build

test_job:
  stage: test
  script:
    - make test

push_job:
  stage: push
  script:
    - make docker-push

deploy-thanos-lab:
  stage: deploy
  when: manual
  script:
    - echo "deploy-thanos-lab job start..."
    - make deploy-test
    - echo "deploy-thanos-lab job end!"

deploy-thanos:
  stage: deploy
  when: manual
  only:
    - master
  script:
    - echo "deploy-thanos job start..."
    - make deploy-prod
    - echo "deploy-thanos job end!"
Copy the code

This allows you to see automatic integration in the GitLab CI/CD when the Git CI commits the master branch change, and can be manually deployed to test or online environments. Note: If shared runner is not needed, disable shared runner for this project.

mistakes

  1. Error reported during build phase of pipeline:
$ make docker-build
TAG=2021.03.01.45c222b docker-compose -f docker-compose.yml build
[31948] Failed to execute script docker-compose
Traceback (most recent call last):
  File "urllib3/connectionpool.py", line 677, in urlopen
  File "urllib3/connectionpool.py", line 392, in _make_request
  File "http/client.py", line 1252, in request
  File "http/client.py", line 1298, in _send_request
  File "http/client.py", line 1247, in endheaders
  File "http/client.py", line 1026, in _send_output
  File "http/client.py", line 966, in send
  File "docker/transport/unixconn.py", line 43, in connect
PermissionError: [Errno 13] Permission denied
Copy the code

Run gitlab-runner as root

Gitlab-runner uninstall # Delete gitlab-runner gitlab-runner install -- work-directory /home/gitlab-runner --user root # uninstall gitlab-runner install -- work-directory /home/gitlab-runner --user root # The installation and Settings - user (set to root) service gitlab - runner # restart restart gitlab - runner ps aux | grep gitlab - runner # check the runner to the userCopy the code
  1. Make docker-build
Get https://registry-1.docker.io/v2/library/golang/manifests/sha256:94c4191a12b9df4ebe8af4115acc8d9ae067dea5069904908584eb8f 4cef2e5d: Dial TCP: lookup Registry -1.docker. IO on 10.160.0.1:53: read UDP 10.160.31.195:48884->10.160.0.1:53: i/o timeout ERROR: Service 'server' failed to build make: *** [docker-build] Error 1Copy the code

Edit /etc/docker/daemon.json to configure docker using aliyun image

{
 "registry-mirrors":["https://6kx4zyno.mirror.aliyuncs.com"]
}
Copy the code

Restart the docker

[@hbhly_31_195 wx-haha-go]# systemctl daemon-reload
[@hbhly_31_195 wx-haha-go]# systemctl restart docker
Copy the code
  1. During the test phase of the pipeline, an error is reported
internal/pkg/config/config.go:6:2: The stat/search/nginx/html/go_project/pkg/mod/github.com/fsnotify/[email protected]/fen.go: permission denied router/router.go:5:2: The stat/search/nginx/html/go_project/pkg/mod/github.com/gin-contrib/[email protected]/pprof.go: permission denied internal/pkg/log/acccess.go:7:2: The stat/search/nginx/html/go_project/pkg/mod/github.com/gin-gonic/[email protected]/path.go: permission denied internal/pkg/myredis/myredis.go:5:2: The stat/search/nginx/html/go_project/pkg/mod/github.com/go-redis/redis/[email protected]/pool_test.go: permission deniedCopy the code

With 1