安装Gitlab

  1. wget http://139.155.0.213/cola/gitlab-ce-zh.tar
  2. docker load -i gitlab-ce-zh.tar
  3. mkdir -p /opt/docker/gitlab/
  4. docker run -d \
  5. --restart always \
  6. --name gitlab \
  7. -p 222:22 \
  8. -p 80:80 \
  9. -p 8443:443 \
  10. -v /opt/docker/gitlab/etc:/etc/gitlab \
  11. -v /opt/docker/gitlab/var/log:/var/log/gitlab \
  12. -v /opt/docker/gitlab/var/opt:/var/opt/gitlab \
  13. twang2218/gitlab-ce-zh:latest

备份与迁移

当容器出现问题,重新运行docker run生成新gitlab容器即可,刚开始需要初始化这是无法避免的

跳过 初始化是没有恢复命令、无法直接使用,所以需要gitlab进行初始化等待即可

  1. # 备份所有数据,备份压缩成tar文件存放在/var/opt/gitlab/backups/
  2. gitlab-rake gitlab:backup:create
  3. # 停止服务,和数据迁移相关的,停止所有然后重启启动效率太低了,所以先停2个
  4. gitlab-ctl stop unicorn
  5. gitlab-ctl stop sidekiq
  6. # 恢复数据,BACKUP是/var/opt/gitlab/backups/的文件,去掉后面的_gitlab_backup.tar
  7. gitlab-rake gitlab:backup:restore BACKUP=1629775971_2021_08_24_11.1.4
  8. #启动服务,之前2个停止的服务会被启动
  9. 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 - 图1

Gitlab查看URL、token

管理区域-概述-Runners,这是针对全局,查看URL、token

Gitlab - 图2

但是下面的案例中,我是对项目进行创建,进入项目-设置-CI/CD-Runners

Gitlab - 图3

安装 runner

  1. docker run -d \
  2. --restart always \
  3. --name gitlab-runner \
  4. -v /opt/docker/gitlab-runner/config:/etc/gitlab-runner \
  5. -v /var/run/docker.sock:/var/run/docker.sock \
  6. gitlab/gitlab-runner:latest
  7. docker exec -it gitlab-runner bash
  8. # 进入容器初始化
  9. gitlab-runner register

gitlab-runner install
gitlab-runner start

初始化

  1. Enter the GitLab instance URL (for example, https://gitlab.com/): #输入url
  2. http://192.168.10.156/
  3. Enter the registration token: #输入token,我这里是项目的token
  4. sgpA9x6nBUf-Qw-1VYcx
  5. Enter a description for the runner: #填写runner描述
  6. [c12df8099e88]:
  7. Enter tags for the runner (comma-separated): #填写runner的tags,用于在之后CI/CD操作时标识使用哪个runner来进行流水线
  8. test
  9. Registering runner... succeeded runner=sgpA9x6n
  10. # 需要以哪种方式运行runner,这里我选择用docker方式运行runner
  11. Enter an executor: parallels, ssh, docker+machine, shell, virtualbox, docker-ssh+machine, kubernetes, custom, docker, docker-ssh:
  12. docker
  13. Enter the default Docker image (for example, ruby:2.6): #选择版本
  14. alpine:latest
  15. Runner registered successfully. Feel free to start it, but if it's running already the config should be automatically reloaded!

管理区域-概述-Runners,查看runners

Gitlab - 图4


瓦雀