58

『中级篇』docker之CI/CD持续集成-CD演示(74)

 5 years ago
source link: http://idig8.com/2018/09/02/zhongjipiandockerzhici-cdchixujicheng-cdyanshi74/?amp%3Butm_medium=referral
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

这次主要看下CICD中的CD功能。源码:https://github.com/limingios/docker/tree/master/No.11

从gitlab中flask-demo下载代码到本地。

通过git clone 克隆到本地

eYbQbaU.png!web

MBvUVjM.png!web

### 修改.gitlab-ci.yml 增加部署代码

* 修改

stages:
  - style
  - test
  - deploy

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-deploy:
   stage: deploy
   script:
     - docker build -t flask-demo .
     - docker run -d -p 5000:5000 flask-demo
   tags:
     - demo
  • 提交到自建的gitlab上 commit push

ERbya2a.png!web

VVNV7ff.png!web

  • 增加了pipline

u2Uz22e.png!web

URnA3im.png!web

QzQvAz7.png!web

NVFV3ub.png!web

想想一下场景

gitlab-ci.yml是否有问题,假如有人修改代码,提交代码,重新CICD的时候

#执行这句没问题
docker build -t flask-demo .

#执行这句就有问题了,之前已经有一个了之前的端口号就是5000,部署肯定报错的,解决方案,可以先将之前的remove掉,在起一个新的。可以写一些简单的脚本。
docker run -d -p 5000:5000 flask-demo
  • 先将刚才创建的remove掉
sudo docker ps
sudo docker rm -f 容器名称

3imyEfE.png!web

  • 修改yml

    >.gitlab-ci.yml 然后commit push到服务器上

stages:
  - style
  - test
  - deploy

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-deploy:
   stage: deploy
   script:
     - docker build -t flask-demo .
     - if [ $( docker ps -aq --filter name=web) ]; then docker rm -f web;fi
     - docker run -d -p 5000:5000 --name web flask-demo
   tags:
     - test1

QJzYrmz.png!web

6FJbEvU.png!web

PS:基本的流程就是开发人员提交代码,自动构建,然后可以在ci服务器上访问,整个流程基本就是这样。

百度未收录

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

>>原文链接地址:


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK