【2020.04.17】以Docker形式安装gitlab和gitlab-runner
环境
Centos7.2
Docker-CE
参考资料:
gitlab docker 官档:https://docs.gitlab.com/omnibus/docker/
docker安装gitlab
1.拉取最新gitlab ce镜像(社区版,非企业版)
docker pull gitlab/gitlab-ce:latest
2.启动gitlab容器
docker run -d \
--env GITLAB_OMNIBUS_CONFIG="external_url 'http://yourip:7458/'; gitlab_rails['gitlab_ssh_host'] = 'yourip'; gitlab_rails['gitlab_shell_ssh_port'] = 7457;" \
-p 7459:443 \
-p 7458:80 \
-p 7457:22 \
--name tzq_gitlab \
--restart always \
-v /data/gitlab/config:/etc/gitlab \
-v /data/gitlab/logs:/var/log/gitlab \
-v /data/gitlab/data:/var/opt/gitlab \
--privileged=true \
--net=host \
gitlab/gitlab-ce
如果想使用https的话需要配置证书,Mannually configuring HTTPS, 上面gitlab的环境变量需要显示加上 letsencrypt['enable'] = false;external_url 'https://yourip:7459/
4.登录gitlab
浏览器输入http://x.x.x.x:7458; 一开始需要创建密码,然后默认用户名为:root
docker安装gitlab-runner
1.
docker run -d --name tzq_gitlab_runner --restart always \ -v /srv/gitlab-runner/config:/etc/gitlab-runner \ -v /var/run/docker.sock:/var/run/docker.sock \ --net=host \ gitlab/gitlab-runner:latest
2.
docker exec -it tzq_gitlab_runner /bin/bash
3.
gitlab-runner register
然后输入你上面搭建的gitlab地址:http://x.x.x.x:7458
4.获取token
将token填入命令行窗口中,敲回车继续
5.给runner取个名字,随便取
6.再取个tag,逗号分隔,用于检索的
7.再选择一个gitlab-runner的执行者,我们是在docker上跑的
8.指明一个默认镜像,随便写个hub.docker.com上存在的,后面我们
9.至此gitlab-runner就在容器中跑起来了
10.修改config.toml配置,挂载宿主机docker
打开/srv/gitlab-runner/config/config.toml文件,找到你对应的runner实例配置
找到并修改为:volumes = ["/cache","/var/run/docker.sock:/var/run/docker.sock"]
pull_policy = "if-not-present"
然后重启runner,
docker restart gitlab-runner
11.如果你gitlab用了https并配了证书的话,runner也需要,请看:https://docs.gitlab.com/runner/install/docker.html#installing-trusted-ssl-server-certificates
gitlab-runner register --tls-ca-file /etc/gitlab-runner/certs/ca.crt
最后
gitlab会自动检测到你配置的gitlab-runner