安装Gitlab
wget http://139.155.0.213/cola/gitlab-ce-zh.tar
docker load -i gitlab-ce-zh.tar
mkdir -p /opt/docker/gitlab/
docker run -d \
--restart always \
--name gitlab \
-p 222:22 \
-p 80:80 \
-p 8443:443 \
-v /opt/docker/gitlab/etc:/etc/gitlab \
-v /opt/docker/gitlab/var/log:/var/log/gitlab \
-v /opt/docker/gitlab/var/opt:/var/opt/gitlab \
twang2218/gitlab-ce-zh:latest
备份与迁移
当容器出现问题,重新运行docker run生成新gitlab容器即可,刚开始需要初始化这是无法避免的
跳过 初始化是没有恢复命令、无法直接使用,所以需要gitlab进行初始化等待即可
# 备份所有数据,备份压缩成tar文件存放在/var/opt/gitlab/backups/
gitlab-rake gitlab:backup:create
# 停止服务,和数据迁移相关的,停止所有然后重启启动效率太低了,所以先停2个
gitlab-ctl stop unicorn
gitlab-ctl stop sidekiq
# 恢复数据,BACKUP是/var/opt/gitlab/backups/的文件,去掉后面的_gitlab_backup.tar
gitlab-rake gitlab:backup:restore BACKUP=1629775971_2021_08_24_11.1.4
#启动服务,之前2个停止的服务会被启动
gitlab-ctl start
chmod 777 授权允许
tar xvf uploads.tar.gz -C /var/opt/gitlab/gitlab-rails/uploads
tar xvf builds.tar.gz -C /var/opt/gitlab/gitlab-ci/builds
tar xvf pages.tar.gz -C /var/opt/gitlab/gitlab-rails/shared/pages
tar xvf artifacts.tar.gz -C /var/opt/gitlab/gitlab-rails/shared/artifacts
Gitlab runner
gitlab runner是CI/CD,配合Jenkins完成自动化构建
Gitlab查看URL、token
管理区域-概述-Runners,这是针对全局,查看URL、token
但是下面的案例中,我是对项目进行创建,进入项目-设置-CI/CD-Runners
安装 runner
docker run -d \
--restart always \
--name gitlab-runner \
-v /opt/docker/gitlab-runner/config:/etc/gitlab-runner \
-v /var/run/docker.sock:/var/run/docker.sock \
gitlab/gitlab-runner:latest
docker exec -it gitlab-runner bash
# 进入容器初始化
gitlab-runner register
gitlab-runner install
gitlab-runner start
初始化
Enter the GitLab instance URL (for example, https://gitlab.com/): #输入url
http://192.168.10.156/
Enter the registration token: #输入token,我这里是项目的token
sgpA9x6nBUf-Qw-1VYcx
Enter a description for the runner: #填写runner描述
[c12df8099e88]:
Enter tags for the runner (comma-separated): #填写runner的tags,用于在之后CI/CD操作时标识使用哪个runner来进行流水线
test
Registering runner... succeeded runner=sgpA9x6n
# 需要以哪种方式运行runner,这里我选择用docker方式运行runner
Enter an executor: parallels, ssh, docker+machine, shell, virtualbox, docker-ssh+machine, kubernetes, custom, docker, docker-ssh:
docker
Enter the default Docker image (for example, ruby:2.6): #选择版本
alpine:latest
Runner registered successfully. Feel free to start it, but if it's running already the config should be automatically reloaded!
管理区域-概述-Runners,查看runners