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

栏目: 服务器 · 发布时间: 6年前

上次主要说了在githubCI的服务器,并且也演示了github的runner执行CICD,这次通过真实的 python 项目来演示下CICD。项目通过gitlab和gitlabCI进行CICD。

源码地址:https://github.com/limingios/docker-cloud-flask-demo

随便找一个开源的python的在github项目。添加到gitlab上。

copy到gitlab上

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

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

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

  • 点击create project

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

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

思考

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

runner管理新的flask-demo

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

python2.7的环境

sudo gitlab-ci-multi-runner register

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

python3.4的环境

sudo gitlab-ci-multi-runner register

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

sudo gitlab-ci-multi-runner verify

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

新建github-ci 文件

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

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

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之CI/CD持续集成—真实Python项目的CI演示(72)

本地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

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

结果还是报错了,开始分析:

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

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

Runner启动的docker容器里无法访问到 gitlab.example.com 这个地址(能访问到才怪)。这一般是由于我们的测试环境没有使用域名导致的, gitlab论坛 里也不少人讨论这个问题,如果你是在部署正式的gitlab环境,那你自然会有一个域名来使用。不过我这里只是搭建测试环境,所以我使用了一种投机的方法:

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

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

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

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

成功了 重新Retry

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

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

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

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

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

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

百度未收录

>>原创文章,欢迎转载。转载请注明:转载自IT人故事会,谢谢!

>>原文链接地址:


以上所述就是小编给大家介绍的《『中级篇』docker之CI/CD持续集成—真实Python项目的CI演示(72)》,希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对 码农网 的支持!

查看所有标签

猜你喜欢:

本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们

Learning Python, 5th Edition

Learning Python, 5th Edition

Mark Lutz / O'Reilly Media / 2013-7-6 / USD 64.99

If you want to write efficient, high-quality code that's easily integrated with other languages and tools, this hands-on book will help you be productive with Python quickly. Learning Python, Fifth Ed......一起来看看 《Learning Python, 5th Edition》 这本书的介绍吧!

RGB转16进制工具
RGB转16进制工具

RGB HEX 互转工具

Base64 编码/解码
Base64 编码/解码

Base64 编码/解码

HEX CMYK 转换工具
HEX CMYK 转换工具

HEX CMYK 互转工具