To prepare

Gitlab supports CI/CD and can set up CI/CD services with simple configuration.

.gitlab-ci.yml

CI configuration script, see gitlab documentation for specific syntax. Here are the simple configurations:

# Base image
image: node:latest

# define variables
variables:
  DOCKER_DRIVER: overlay
  DOCKER_IMAGE_NAME: $DOCKER_REGISTRY_URL/${CI_PROJECT_NAMESPACE}/$CI_PROJECT_NAME:$CI_PIPELINE_IID-$CI_COMMIT_SHORT_SHA
  WORK_HOME: .
  DOCKERFILE: ./Dockerfile
  MARATHON_CONFIG: ./marathon.json
  GITLAB_NPM_MODULES: /local_cache/npm/modules
  KUBECONFIG: /config
  HEALTH_CHECK_URL: /path/to/healthcheck/url

# Steps to perform
stages:
  - step-1
  - step-2
  - step-3

webpack-build:
  # step name
  stage: step-1
  tags:
  	The tag # runner
    - default
  # mirror used
  image: node:latest
  # Execute the script
  script:
    - env
    - npm uninstall yarn webpack webpack-cli -g
    - npm install [email protected] --force -g
    - yarn install
    - yarn run build
  artifacts:
    name: webpack_build
    paths:
    - $WORK_HOME/dist/*
    expire_in: 1 week
  only:
  	Execute only on master branch
    - master

Copy the code

gitlab-runner

Gitlab-runner is a host container for running CI/CD tasks and can be deployed on any operating system. In this paper, Docker of Windows was selected as the container of Gitlab-Runner.

Docker

In this paper, gitlab-Runner is installed in Windows Docker, and docker needs to be installed locally first. See the Docker tutorial for details.

After the installation is complete, switch to a Linux container; otherwise, the Gitlab-Runner image cannot be installed (The Gitlab-Runner image has no Windows version).

Action: Right click on the Docker icon and select Switch to Linux Containers…

Build gitlab-Runner environment in Windows Docker

Pull the mirror

docker pull gitlab/gitlab-runner
Copy the code

Check whether the image is successfully obtained by using Docker images

Start the container

Before starting the container, you need to know that some of the Gitlab-Runner configuration information needs to be stored. We can do this through data volume.

Start the container by mounting the local system data volume

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

On MAC systems, use /Users/Shared instead of/SRV

Start the container from the Docker data volume

  • Create a Docker data volume
docker volumn create gitlab-runner-config
Copy the code
  • Use the volume created to start the Gitlab-Runner container
docker run -d --name gitlab-runner --restart always \
    -v /var/run/docker.sock:/var/run/docker.sock \
    -v gitlab-runner-config:/etc/gitlab-runner \
    gitlab/gitlab-runner:latest
Copy the code

Check whether the operation is successful through docker PS

Registered gitlab – runner

  • Run registration commands according to different mount modes:
  1. Local system data volume mounting mode:
docker run --rm -it -v /srv/gitlab-runner/config:/etc/gitlab-runner gitlab/gitlab-runner register
Copy the code
  1. Docker data volumes are mounted
docker run --rm -it -v gitlab-runner-config:/etc/gitlab-runner gitlab/gitlab-runner register
Copy the code

Then enter the corresponding configuration in the GitLab repository as prompted. When selecting executor, select Docker and you will be asked to fill in a basic image. Docker: Latest is the latest image.

Restart Gitlab-Runner, and the configuration is complete.

The problem

Local Gitlab-runner “ERROR: error during connect: Get http://docker:2375/v1.40/info: dial tcp: lookup docker on 192.168.65.1:53: no such host”

Solution: gitlab.com/gitlab-org/…