gitlab-ci/cd(二)Docker安装gitlab Runner

docker如何安装gitlab

-------------记得修改external_url(就算8090端口url都不需要修改)
shell>docker run --detach \
--hostname gitlab.example.com \
--env GITLAB_OMNIBUS_CONFIG="external_url 'http://192.168.8.3/'" \
--publish 443:443 --publish 8090:80 --publish 2222:22 \
-v /etc/localtime:/etc/localtime \
--name gitlab \
--restart unless-stopped \
--volume /data/app/gitlab/config:/etc/gitlab \
--volume /data/app/gitlab/logs:/var/log/gitlab \
--volume /data/app/gitlab/data:/var/opt/gitlab \
gitlab/gitlab-ce:latest


--------------热更新config
shell>docker exec gitlab gitlab-ctl reconfigure

查看gitlab初始密码:docker exec -it gitlab grep ‘Password:’ /etc/gitlab/initial_root_password

gitlab ci/cd是用“gitlab runner”运行

  • gitlab runner
  • pipeline
  • stage
  • job
  • .gitlab-ci.yaml

Step1:安装gitlab-runner

方法一:helm安装

参考文档:https://help.aliyun.com/document_detail/106968.html 

方法二:docker安装

1、
shell>docker volume create gitlab-runner-config
2、
shell> docker run -d -p 8093:8093 --name gitlab-runner \
--restart unless-stopped \
-v /etc/localtime:/etc/localtime \
-v /data/app/gitlab-runner/config:/etc/gitlab-runner \
-v /data/app/gitlab-runner/data:/home/gitlab-runner \
-v /var/run/docker.sock:/var/run/docker.sock \
gitlab/gitlab-runner:latest
3、register。注意修改:url和registration-token
---参考文档:https://docs.gitlab.com/runner/register/index.html#docker

shell>docker run --rm -v /data/app/gitlab-runner/config:/etc/gitlab-runner gitlab/gitlab-runner register \
  --non-interactive \
  --executor "docker" \
  --docker-image alpine:latest \
  --url "https://gitlab.com/" \
  --registration-token "PROJECT_REGISTRATION_TOKEN" \
  --description "docker-runner" \
  --tag-list "docker,aws" \
  --run-untagged="true" \
  --locked="false" \
  --access-level="not_protected"

如何gitlab-runner安装在k8s中,则进入k8s容器执行以下命令

同理:url和registration-token都需要修改
shell>gitlab-runner register \
  --non-interactive \
  --url "https://gitlab.com/" \
  --registration-token "PROJECT_REGISTRATION_TOKEN" \
  --executor "docker" \
  --docker-image alpine:latest \
  --description "docker-runner" \
  --tag-list "docker,aws" \
  --run-untagged="true" \
  --locked="false" \
  --access-level="not_protected"
GitOps、新兴技术能力gitlab-ci/cd(二)Docker安装gitlab Runner插图
GitOps、新兴技术能力gitlab-ci/cd(二)Docker安装gitlab Runner插图1

参考文档:https://help.aliyun.com/document_detail/106968.html