首页 > 编程语言 >『中级篇』docker之CI/CD持续集成—真实Python项目的CI演示(72)

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

时间:2023-01-06 11:35:24浏览次数:64  
标签:CI Python gitlab ci CD runner docker tox com


上次主要说了在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上。

copy到gitlab上

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

  • Git repository URL

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

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

  • 点击create project

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

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

思考

上次注册了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)_git_05

python2.7的环境

sudo gitlab-ci-multi-runner register

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

python3.4的环境

sudo gitlab-ci-multi-runner register

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

sudo gitlab-ci-multi-runner verify

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

新建github-ci 文件

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

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

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)_git_11

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

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

Cloning repository...
Cloning into '/builds/root/flask-demo'...
fatal: unable to access 'http://gitlab-ci-token:[email protected]/root/flask-demo.git/': Couldn't resolve host 'gitlab.example.com'
ERROR: Job failed: exit code 1

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

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)_python_14

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

成功了 重新Retry

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

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

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

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

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

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

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


标签:CI,Python,gitlab,ci,CD,runner,docker,tox,com
From: https://blog.51cto.com/u_12040702/5992886

相关文章

  • 『中级篇』docker之CI/CD持续集成-整个流程串联(75)
    ython,CIjava,CDpython,这次主要说下从gitlab,gitlab-ci,gitlabCICD的整个从开发流程到发布流程的,一个工作的流程。源码:​​https://github.com/limingios/docker/tree/master/......
  • 『中级篇』docker之CI/CD持续集成-CD演示(74)
    能。源码:​​https://github.com/limingios/docker/tree/master/No.11​​从gitlab中flask-demo下载代码到本地。通过gitclone克隆到本地修改.gitlab-ci.yml增加部署代码......
  • 『中级篇』docker之CI/CD持续集成—真实JAVA-Maven项目的CI演示(73)
    ICD。项目通过gitlab和gitlabCI进行CICD。源码地址:​​​https://github.com/limingios/gitlabci-maven​​​源码:​​https://github.com/limingios/docker/tree/master/......
  • 『中级篇』CI/CD持续集成/持续部署(69)
    )​​从这次课就开始学习CI/CD,结合docker或者是使用k8s来完成。CICD的理解CICD是一个整套流程的解决方案,光依靠docker和k8s是完全不行的,中间涉及到很多CICD的工具,CI的服务器......
  • python网络爬虫(二)
    今天看了网络爬虫爬取图片的内容,主要是讲利用正则匹配爬图片。Day3-3.正则解析案例01_哔哩哔哩_bilibili所以就想着用学到的内容去试一下,我直接用这个方法去爬B站的图......
  • 【Python】traceback使用
    traceback使用importtracebackimportosfrompathlibimportPathfromioimportStringIOfp=StringIO()#使用内存try:print('---------')int('abc......
  • 使用python编写端口扫描工具
    端口扫描工具编写目录端口扫描工具编写0x01:实现端口扫描的方式一、TCP扫描:二、SYN扫描:三、UDP扫描:0x02:使用python实现端口扫描一、使用socket库的connect()方法扫描1、核......
  • 【Python】pandas 读取,保存数据
    pandas读取/保存数据importpandasaspdfile=r''df=pd.read_excel(file)df_columns=df.columns.to_list()#字段名listredundant_column=['name','age......
  • python-面向对象
    1.什么是面向对象编程面向过程编程:是一种以过程为中心的编程思想。这些都是以什么正在发生为主要目标进行编程。面向对象编程:是一种计算机编程架构,以对象为中心的编......
  • python-异常处理
    1.python-异常处理什么是异常?顾名思义,异常就是程序因为某种原因无法正常工作了,比如缩进错误、缺少软件包、环境错误、连接超时等都会引发异常。一个健壮的程序应该把......