Create a Continuous Integration (CI) Pipeline in Gitlab(2)

简介: Create a Continuous Integration (CI) Pipeline in Gitlab(2)

2.5. 部署gitlab-runner

我们原来缺少一个 action runners,也就是gitlab-runner

官方安装gitlab-runner

我们可以用一个小的镜像gitlab/gitlab-runner:alpine-v14.4.2

 docker run -d --name gitlab-runner --restart always --net=host \
     -v /srv/gitlab-runner/config:/etc/gitlab-runner \
     -v /var/run/docker.sock:/var/run/docker.sock \
     gitlab/gitlab-runner:alpine-v14.4.2

注册runner

$ docker run --rm -it -v /srv/gitlab-runner/config:/etc/gitlab-runner gitlab/gitlab-runner:alpine-v14.4.2 register
Runtime platform                                    arch=amd64 os=linux pid=7 revision=50fc80a6 version=14.4.2
Running in system-mode.                            
Enter the GitLab instance URL (for example, https://gitlab.com/):
http://192.168.211.70:8081
Enter the registration token:
6D5mo8iWCLBaVdqcaqjN
Enter a description for the runner:
[329b671ffa00]: gitlab-example
Enter tags for the runner (comma-separated):
Registering runner... succeeded                     runner=6D5mo8iW
Enter an executor: ssh, virtualbox, docker+machine, shell, docker-ssh+machine, kubernetes, custom, docker, docker-ssh, parallels:
docker
Enter the default Docker image (for example, ruby:2.6):
ubuntu:20.04
Runner registered successfully. Feel free to start it, but if it's running already the config should be automatically reloaded! 

注册完成后,gitlab界面检查gitlab-runner是否注册成功

1832b220aa754cd18c504acc7686a560.png

1832b220aa754cd18c504acc7686a560.png

绿色代表成功,回到项目界面,已经开始在跑了。

2.6 测试跑起来

1832b220aa754cd18c504acc7686a560.png

1832b220aa754cd18c504acc7686a560.png

1832b220aa754cd18c504acc7686a560.png

1832b220aa754cd18c504acc7686a560.png

1832b220aa754cd18c504acc7686a560.png

2.7 CI变得更安全

1832b220aa754cd18c504acc7686a560.png

创建普通用户

apt-get update && apt-get upgrade
useradd -m -s /bin/bash youtube
passwd youtube
usermod -aG sudo youtube

禁用关于root用户ssh的根访问

$ su - youtube
$ vim /etc/ssh/sshd_config
PermitRootLogin no
$ systemctl restart ssh
$ ssh root@192.168.211.70(拒绝)

安装Docker

ssh-copy-id youtube@server-IP
apt-get install -y docker.io
#当前用户授权
usermod -aG docker $USER
docker ps
docker run hello-world

在youtube用户下重新运行部署新的gitlab-runner并注册,继续测试。


视频:https://mp.weixin.qq.com/s/NKgpZ1CCybkrNakZIlN-Ng


原创:https://www.youtube.com/watch?v=6QtJDaycUwA


github:https://github.com/Ghostwritten/gitlab-example-demo.git


更多阅读:


部署gitlab

gitlab-runner部署

Gitlab 基础配置

Create a Continuous Integration (CI) Pipeline in Gitlab

git与gitlab快速学习手册


相关文章
|
4月前
|
缓存 监控 数据可视化
利用GitLab CI/CD自动化您的软件开发流程
【10月更文挑战第10天】GitLab CI/CD 是 GitLab 内置的持续集成和持续部署工具,通过编写 .gitlab-ci.yml 文件,可以自动化构建、测试和部署应用程序的过程。本文介绍 GitLab CI/CD 的核心优势、实施步骤及在现代开发中的应用,帮助您提高开发效率和软件质量。
|
4月前
|
jenkins Shell 持续交付
Jenkins持续集成GitLab项目 GitLab提交分支后触发Jenkis任务 持续集成 CI/CD 超级详细 超多图(二)
Jenkins持续集成GitLab项目 GitLab提交分支后触发Jenkis任务 持续集成 CI/CD 超级详细 超多图(二)
130 0
|
4月前
|
JavaScript 测试技术 持续交付
使用 GitLab CI/CD 管道自动化部署 Web 应用
【10月更文挑战第2天】使用 GitLab CI/CD 管道自动化部署 Web 应用
201 0
|
4月前
|
jenkins Shell 持续交付
Jenkins持续集成GitLab项目 GitLab提交分支后触发Jenkis任务 持续集成 CI/CD 超级详细 超多图(一)
Jenkins持续集成GitLab项目 GitLab提交分支后触发Jenkis任务 持续集成 CI/CD 超级详细 超多图(一)
333 0
|
6月前
|
数据可视化 jenkins 测试技术
GitLab CI/CD 和 Jenkins对比
8月更文挑战第25天
652 5
|
5月前
|
测试技术 API
8-20|https://gitlab.xx.com/api/v4/projects/4/trigger/pipeline Request failed 状态码400
8-20|https://gitlab.xx.com/api/v4/projects/4/trigger/pipeline Request failed 状态码400
|
6月前
|
安全 Shell 数据安全/隐私保护
CI/CD笔记.Gitlab系列:控制台强制修改root用户密码
CI/CD笔记.Gitlab系列:控制台强制修改root用户密码
230 2
|
6月前
CI/CD笔记.Gitlab系列:设置GitLab导入源
CI/CD笔记.Gitlab系列:设置GitLab导入源
341 2
|
6月前
|
数据安全/隐私保护
CI/CD笔记.Gitlab系列.新用户管理
CI/CD笔记.Gitlab系列.新用户管理
75 1
|
6月前
|
存储 Ubuntu jenkins
CI/CD 工具比较:Jenkins、GitLab CI、Buildbot、Drone 和 Concourse
CI/CD 工具比较:Jenkins、GitLab CI、Buildbot、Drone 和 Concourse
318 0

相关实验场景

更多