Gitlab+GitlabRunner CI/CD
注意 gitlab跟runner版本要一致,不然会出问题
docker安装gitlab
cd /opt/
mkdir gitlab
export GITLAB_HOME=/opt/gitlab
由于官方版本的gitlab/gitlab-ce:latest创建runner老是404,后来装了jh版本的。
docker run --detach \
--hostname gitlab.example.com \
--publish 443:443 --publish 9001:80 --publish 2222:22 \
--name gitlab \
--restart always \
--volume $GITLAB_HOME/config:/etc/gitlab \
--volume $GITLAB_HOME/logs:/var/log/gitlab \
--volume $GITLAB_HOME/data:/var/opt/gitlab \
--shm-size 256m \
registry.gitlab.cn/omnibus/gitlab-jh:latest
访问极狐 GitLab URL,http://192.168.252.131:9001,并使用用户名 root 和来自以下命令的密码登录:
[root@root~]# docker exec -it gitlab grep 'Password:' /etc/gitlab/initial_root_password
Password: xxzIrC8HPFfuxVmGSyxxxx221Ihu+a2edEySMw=
登录,然后创建项目,上传公钥,省略。。。
Docker方式安装注册gitlab-runner
docker run -d --name gitlab-runner --restart always \
-v /opt/gitlab-runner/config:/etc/gitlab-runner \
-v /var/run/docker.sock:/var/run/docker.sock \
gitlab/gitlab-runner:latest
创建runner,以及注册runner
进入runner容器内 docker exec -it gitlab-runner /bin/bash
gitlab-runner register --url http://192.168.252.131:9001 --token glrt-Tz6onF8_bUSeNwaqqg8w
# 然后在交互界面,最后选择输入shell
极狐有个小坑
没有自带vim命令,要在容器内自行安装,其实也可在宿主机映射的目录修改
[root@249b6b18ffa8]# apt update
[root@249b6b18ffa8]# apt install -y vim
# 修改配置,增加clone_url配置,跟url并列
[root@249b6b18ffa8]# vi /opt/gitlab-runner/config/config.toml
[[runners]]
name = "9b499a1ad4dc"
url = "http://192.168.252.131:9001"
id = 10
token = "glrt-Tz6onF8_bUSeNwaqqg8w"
token_obtained_at = 2024-03-07T03:43:37Z
token_expires_at = 0001-01-01T00:00:00Z
executor = "shell"
[runners.cache]
MaxUploadedArchiveSize = 0
# 重启gitlab-runner所在容器
docker restart gitlab-runner
开始创建 .gitlab-ci.yml 官方示例,只是用来跑通项目
stages: # List of stages for jobs, and their order of execution
- build
- test
- deploy
build-job: # This job runs in the build stage, which runs first.
stage: build
script:
- echo "Compiling the code..."
- echo "Compile complete."
unit-test-job: # This job runs in the test stage.
stage: test # It only starts when the job in the build stage completes successfully.
script:
- echo "Running unit tests... This will take about 60 seconds."
- echo "Code coverage is 90%"
lint-test-job: # This job also runs in the test stage.
stage: test # It can run at the same time as unit-test-job (in parallel).
script:
- echo "Linting code... This will take about 10 seconds."
- echo "No lint issues found."
deploy-job: # This job runs in the deploy stage.
stage: deploy # It only runs when *both* jobs in the test stage complete successfully.
environment: production
script:
- echo "Deploying application..."
- echo "Application successfully deployed."
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】凌霞软件回馈社区,博客园 & 1Panel & Halo 联合会员上线
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】博客园社区专享云产品让利特惠,阿里云新客6.5折上折
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· DeepSeek “源神”启动!「GitHub 热点速览」
· 微软正式发布.NET 10 Preview 1:开启下一代开发框架新篇章
· 我与微信审核的“相爱相杀”看个人小程序副业
· C# 集成 DeepSeek 模型实现 AI 私有化(本地部署与 API 调用教程)
· DeepSeek R1 简明指南:架构、训练、本地部署及硬件要求