如何安装配置gitlab-runner

1. 安装gitlab-runner docker image

docker pull gitlab/gitlab-runner:alpine

 

2. 注册gitlab-runner

/opt/data/gitlab-runner是你主机的路径,你也可以换成其他的路径

 docker run --rm -t -i -v /opt/data/gitlab-runner/config:/etc/gitlab-runner gitlab/gitlab-runner:alpine register

按照提示输入所需参数,参数可以到gitlab页面的菜单里去查找,如下图: 

 

 

     url 就是gitlab的web服务地址, token是令牌, executor可以填docker

 

注册成功后,能够在下方看到你注册的runner

 

2. 用systemd和docker-compose来自动运行gitlab-runner

 service配置文件内容如下, /opt/data/docker/gitlab-runner是docker-compose.yml文件所在的路径

[Unit]
Description=Docker Compose gitlab Service
Requires=docker.service docker-compose-gitlab.service
After=docker.service docker-compose-gitlab.service

[Service]
Type=oneshot
RemainAfterExit=yes
WorkingDirectory=/opt/data/docker/gitlab-runner
ExecStart=/usr/local/bin/docker-compose up -d
ExecStop=/usr/local/bin/docker-compose down
TimeoutStartSec=0

[Install]
WantedBy=multi-user.target

  docker-compose.yml文件内容如下 

version: "3.8"
services:

  gitlab:
    image: gitlab/gitlab-runner:alpine
    restart: always
    volumes:
      - "/opt/sdb/data/gitlab-runner/config:/etc/gitlab-runner"
      - "/var/run/docker.sock:/var/run/docker.sock"

  注:/var/run/docker.sock一定要挂上,这样才能共享host的docker

posted on 2020-04-28 18:49  omage  阅读(108)  评论(0编辑  收藏  举报