原创文章,欢迎转载。转载请注明:转载自IT人故事会,谢谢! 原文链接地址:『中级篇』docker之CI/CD持续集成—真实Python项目的CI演示(72)
上次主要说了在githubCI的服务器,并且也演示了github的runner执行CICD,这次通过真实的python项目来演示下CICD。项目通过gitlab和gitlabCI进行CICD。 源码地址:https://github.com/limingios/docker-cloud-flask-demo 源码:https://github.com/limingios/docker/tree/master/No.11
随便找一个开源的python的在github项目。添加到gitlab上。
new project
Git repository URL
https://github.com/limingios/docker-cloud-flask-demo
上次注册了ci的runner,其实这个runner就是一个shell,通过命令的形式在ci服务器上运行该运行的程序。有可能ci服务器没有装python2 或者python3,我们可以在ci服务器里面装python2或者python3,但是如果想一下,这个ci服务器有很多人在用的话,python有很多环境,python有很多不同的依赖,如果环境全部都装在这个shell里面是不是很混乱,不光是python项目,如果有java项目啊,js的项目都装一下包肯定会很乱很乱,怎么去解决这个问题,看来只能通过docker了。
python2.7的环境
sudo gitlab-ci-multi-runner register
python3.4的环境
sudo gitlab-ci-multi-runner verify
stages: - style - test pep8: stage: style script: - pip install tox - tox -e pep8 tags: - python2.7 unittest-py27: stage: test script: - pip install tox - tox -e py27 tags: - python2.7 unittest-py34: stage: test script: - pip install tox - tox -e py34 tags: - python3/4
本地docker没有提前拉取镜像,下载python2.7 和 python3.4的比较慢,我直接增加了加速器
curl -sSL https://get.daocloud.io/daotools/set_mirror.sh | sh -s http://b81aace9.m.daocloud.io sudo systemctl restart docker
结果还是报错了,开始分析:
Cloning repository... Cloning into '/builds/root/flask-demo'... fatal: unable to access 'http://gitlab-ci-token:xxxxxxxxxxxxxxxxxxxx@gitlab.example.com/root/flask-demo.git/': Couldn't resolve host 'gitlab.example.com' ERROR: Job failed: exit code 1
Runner启动的docker容器里无法访问到gitlab.example.com这个地址(能访问到才怪)。这一般是由于我们的测试环境没有使用域名导致的,gitlab论坛里也不少人讨论这个问题,如果你是在部署正式的gitlab环境,那你自然会有一个域名来使用。不过我这里只是搭建测试环境,所以我使用了一种投机的方法:
gitlab.example.com
修改Runner的/etc/gitlab-runner/config.toml文件,在其中的[runner.docker]下增加:
/etc/gitlab-runner/config.toml
[runner.docker]
sudo vi /etc/gitlab-runner/config.toml
成功了 重新Retry
PS:这次主要给大家简单的介绍下CI,还没设计到CD。下次吧!