在本文中,我决定描述我在配置gitlab CI和租用VPS 方面的经验。背景
在工作中,紫外线。DevOps'y配置为我的项目在部署kubernetes(我工作作为围棋开发商)。我有自己的宠物项目-我想自动化,但我并不希望提高自己的gitlab(无论如何,VPS都不是橡胶)。初始数据
创建存储库
我们创建要自动化的存储库。我决定进行测试以使用nginx引发docker并转发到html页面。仓库结构:Docker文件FROM nginx:latest
COPY html /var/www/html
COPY nginx.conf /etc/nginx/nginx.conf
nginx.confevents {}
http {
server {
listen 80;
location / {
root /var/www/html;
}
}
}
- html
index.html<html>
<h1>Hello, Runner!</h1>
</html>
.gitlab-ci.yml
image: docker:19.03.8
before_script:
- docker info
build:
stage: build
script:
- docker build -t hellorunner .
deploy:
stage: deploy
script:
- docker ps --filter name=hellorunner --quiet | xargs --no-run-if-empty docker stop | xargs --no-run-if-empty docker rm
- docker run -d --restart=always --name hellorunner -p 8090:80 hellorunner
after_script:
- docker system prune -f
储存库设定
打开设置-> CI
然后,单击“运行器”,展开。
首先,关闭建议的运行器- 禁用共享运行器
然后,我们感兴趣-“手动设置特定运行器”
我们复制令牌,将来将需要它。VPS准备
安装docker。安装gitlab-runner。注册一个新的跑步者。!在executor字段中,指定Docker版本,就像Dockerfile中一样!
在令牌字段中,指定从gitlab记住的令牌
gitlab-runner register
现在,您需要对跑步者的配置进行一些小的更改。nano /etc/gitlab-runner/config.toml
领域volumes = ["/cache"]
改成volumes = ["/var/run/docker.sock:/var/run/docker.sock", "/cache"]
重新启动守护程序gitlab-runner restart
再次返回gitlab /设置/ CI / Runners。应该会出现一个活动
的运行器,通过按
来编辑运行器,允许执行不带标签的任务,
现在执行推式提交并遵循作业
,最后打开浏览器,
链接到PS 存储库:我遇到了一个问题-我有一个内部组装的映像,无法访问外部网络,解决方案是创建文件/etc/docker/daemon.json:{
"dns": ["8.8.4.4", "8.8.8.8"]
}
service docker restart