手记

『中级篇』docker之CI/CD持续集成—真实Python项目的CI演示(72)

copy到gitlab上

  • new project


  • Git repository URL

https://github.com/limingios/docker-cloud-flask-demo

  • 点击create project

思考

上次注册了ci的runner,其实这个runner就是一个shell,通过命令的形式在ci服务器上运行该运行的程序。有可能ci服务器没有装python2 或者python3,我们可以在ci服务器里面装python2或者python3,但是如果想一下,这个ci服务器有很多人在用的话,python有很多环境,python有很多不同的依赖,如果环境全部都装在这个shell里面是不是很混乱,不光是python项目,如果有java项目啊,js的项目都装一下包肯定会很乱很乱,怎么去解决这个问题,看来只能通过docker了。

runner管理新的flask-demo

python2.7的环境

 sudo gitlab-ci-multi-runner register

python3.4的环境

 sudo gitlab-ci-multi-runner register

sudo gitlab-ci-multi-runner verify

新建github-ci 文件

stages:
  - style
  - testpep8:
  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环境,那你自然会有一个域名来使用。不过我这里只是搭建测试环境,所以我使用了一种投机的方法:

修改Runner的/etc/gitlab-runner/config.toml文件,在其中的[runner.docker]下增加:

sudo vi /etc/gitlab-runner/config.toml

成功了 重新Retry

PS:这次主要给大家简单的介绍下CI,还没设计到CD。下次吧!



作者:IT人故事会
链接:https://www.jianshu.com/p/f559b1152096


0人推荐
随时随地看视频
慕课网APP