環境:CentOS 7
目的:在 Docker container 中運行 Gitlab Runner,搭建 Gitlab-CI 環境linux
$ sudo yum install yum-utils device-mapper-persistent-data lvm2
$
$ sudo yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo
$ sudo yum install docker-ce
$
$ sudo systemctl enable docker
$ sudo systemctl start docker
複製代碼
安裝步驟:git
# For RHEL/CentOS/Fedora
$ curl -L https://packages.gitlab.com/install/repositories/runner/gitlab-runner/script.rpm.sh | sudo bash
複製代碼
# For RHEL/CentOS/Fedora
$ sudo yum install gitlab-runner
複製代碼
執行註冊命令:docker
$ docker run --rm -t -i -v /srv/gitlab-runner/config:/etc/gitlab-runner gitlab/gitlab-runner register \
--non-interactive \
--executor "docker" \
--docker-image alpine:3 \
--url "https://gitlab.com/" \
--registration-token "PROJECT_REGISTRATION_TOKEN" \
--description "docker-runner" \
--tag-list "docker,aws" \
--run-untagged \
--locked="false"
複製代碼
註冊完成後,以下配置文件會被 Runner 自動加載:centos
## 配置文件路徑爲: /srv/gitlab-runner/config
[[runners]]
name = "gitlab-runner"
url = "https://gitlab.com/"
token = "PROJECT_REGISTRATION_TOKEN"
executor = "docker"
[runners.docker]
tls_verify = false
image = "alpine:latest"
privileged = false
disable_entrypoint_overwrite = false
oom_kill_disable = false
disable_cache = false
volumes = ["/cache"]
shm_size = 0
[runners.cache]
[runners.cache.s3]
[runners.cache.gcs]
複製代碼
$ 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
複製代碼
參數說明:bash
-d
: 設置容器後臺運行--name
:容器名稱-restart
always:每次啓動容器就重啓 gitlab-runner-v
: 共享目錄掛載建立文檔示例請點擊這裏app
$ docker ps
查看容器運行狀況## gitlab-runner 是容器的名字,第一行命令 `--name gitlab-runner`
$ docker logs gitlab-runner
複製代碼
$ docker stop gitlab-runner && docker rm gitlab-runner
複製代碼