gitlab与gitlab-runner安装配置
使用docker-compose安装,yml如下
构建一个网络平面
docker network create proxy --subnet 192.168.100.0/24 \
--gateway 192.168.100.1
version: '3.0'
services:
gitlab:
hostname: gitlab
environment:
TZ: 'Asia/Shanghai'
GITLAB_OMNIBUS_CONFIG: |
external_url 'http://192.168.100.18:3080'
gitlab_rails['time_zone'] = 'Asia/Shanghai'
gitlab_rails['gitlab_ssh_host'] = '192.168.100.18'
gitlab_rails['gitlab_shell_ssh_port'] = 3022
restart: always
privileged: true
logging:
driver: "json-file"
options:
max-size: "500m"
image: gitlab-ce:14.9.3
container_name: gitlab
hostname: gitlab
ports:
- '3080:80'
- '3022:22'
- '30443:30443'
volumes:
- /etc/gitlab:/etc/gitlab
- /var/log/gitlab:/var/log/gitlab
- /var/opt/gitlab:/var/opt/gitlab
networks:
proxy:
ipv4_address: 192.168.100.18
gitlab-runner:
image: gitlab/gitlab-runner:latest
container_name: gitlab-runner
hostname: gitlab-runner
privileged: true
volumes:
- /var/run/docker.sock:/var/run/docker.sock
- /etc/gitlab-runner/config:/etc/gitlab-runner
restart: always
networks:
proxy:
ipv4_address: 192.168.100.20
networks:
proxy:
external: true
启动之后等待gitlab健康即可登录,第一次登录的密码保存在文件内,24小时后删除。使用下面命令查看密码.在界面输入root+密码即可登录
cat /etc/gitlab/initial_root_password
配置runner
独享runner
runner分为共享runner和项目独享runner。
拿到第三步的token之后需要在gitlabrunner容器内进行注册,命令如下
gitlab-runner register \
--url http://192.168.100.18:3080/ \
--registration-token GR1348941ybKLBfnpsEjkGJmbLqy1 \
--docker-network-mode proxy \
--docker-pull-policy if-not-present \
url为上图中的注册地址
registration-token为第三步中的token
docker-network-mode 设置流水线创建的容器的网络模式,根据自己的设置,需要能访问到gitlab
docker-pull-policy docker镜像拉取策略
register还有 很多参数用于配置拉起的代码ci/cd环境的配置
共享runner
在管理中心的runner获取到一个token,在runner中使用命令注册自己
注册好之后可以在项目的cicd中看到这个共享runner
然后修改.gitlab-ci.yml中每个阶段的tags即可使用共享runner运行流水线