# 下载 $sudo wget -O /usr/local/bin/gitlab-runner https://gitlab-runner-downloads.s3.amazonaws.com/latest/binaries/gitlab-runner-linux-amd64 # 修改权限 $chmod +x /usr/local/bin/gitlab-runner # 添加gitlab-runner用户 $useradd --comment 'GitLab Runner' --create-home gitlab-runner --shell /bin/bash # 将gitlab-runner用户添加到docker组 $sudo usermod -aG docker gitlab-runner # 安装 $gitlab-runner install --user=gitlab-runner --working-directory=/home/gitlab-runner # 验证 $sudo -u gitlab-runner -H docker info 如图
注册
$sudo gitlab-runner register
查看配置信息
$cat /etc/gitlab-runner/config.toml concurrent = 1 check_interval = 0 [session_server] session_timeout = 1800 [[runners]] name = "my-runner" url = "https://gitlab.com/" token = "XXXXXXXXXXXXXXX" executor = "shell" [runners.cache] [runners.cache.s3] [runners.cache.gcs]
重启
# 重启gitlab-runner $gitlab-runner restart
配置项目
stages: - build before_script: - docker login -u "$DOCKER_USER" -p "$DOCKER_PASS" $DOCKER_ADDRESS build_image: stage: build script: - docker build -f Dockerfile -t "$DOCKER_ADDRESS/workspace/myimage" . - docker push "$DOCKER_ADDRESS/workspace/myimage"
参考
https://docs.gitlab.com/ce/ci/docker/using_docker_build.html
http://answ.me/post/build-docker-images-automatically-via-gitlab-ci/