Gitlab 流水线

Git 流水线

https://docs.gitlab.cn/runner/install/docker.html

Runner 注册后需要更改 volumes 配置

https://gitlab.com/gitlab-org/gitlab-runner/-/issues/4794

volumes = ["/var/run/docker.sock:/var/run/docker.sock", "/cache"]

将 docker.sock 卷添加到 config.toml 似乎有效。但不认为这是正确的方法,更多的是一种解决方法

.gitlab-ci.yml

image: docker:20.10.16

variables:
  # When you use the dind service, you must instruct Docker to talk with
  # the daemon started inside of the service. The daemon is available
  # with a network connection instead of the default
  # /var/run/docker.sock socket. Docker 19.03 does this automatically
  # by setting the DOCKER_HOST in
  # https://github.com/docker-library/docker/blob/d45051476babc297257df490d22cbd806f1b11e4/19.03/docker-entrypoint.sh#L23-L29
  #
  # The 'docker' hostname is the alias of the service container as described at
  # https://docs.gitlab.com/ee/ci/services/#accessing-the-services.
  #
  # Specify to Docker where to create the certificates. Docker
  # creates them automatically on boot, and creates
  # `/certs/client` to share between the service and job
  # container, thanks to volume mount from config.toml
  DOCKER_TLS_CERTDIR: "/certs"

services:
  - docker:20.10.16-dind

before_script:
  - docker info

build:
  stage: build
  script:
    - echo $(git rev-parse --short HEAD)
    - docker build -t gpt_chat:$(git rev-parse --short HEAD) .
    - echo "build success"

test: 
  stage: test
  script: 
    - docker rm -f gptchat
    - docker run -d -p 7860:7860 --name gptchat gpt_chat

获取git提交的id作为docker镜像的tag

docker build -t ketitongxue/fastgo:$(git rev-parse --short HEAD) .