Original article, welcome to reprint. Reprint please specify: reprint from IT people story, thank you! Docker CI/CD Continuous Integration — A CI Demo of a Real Python Project (72)

Last time we focused on the githubCI server, and also demonstrated the Github Runner running CICD. This time we will demonstrate CICD through a real Python project. CICD is carried out through GITLab and gitlabCI. Source code address: github.com/limingios/d… Source: github.com/limingios/d…

Find an open source Python project on Github. Add to GitLab.

Copy to the gitlab

  • new project





  • Git repository URL

Github.com/limingios/d…




  • Click on the create project






thinking

The runner who registered CI last time is actually a shell that runs the program on the CI server through commands. It’s possible that the CI server doesn’t have Python 2 or Python 3 installed, we could have Python 2 or Python 3 installed on the CI server, but if you think about it, this CI server has a lot of people using it, Python has a lot of different environments, Python has a lot of different dependencies, If all the environment is installed in this shell, will it be very confusing? Not only python projects, but also Java projects and JS projects will be very messy if they are packaged. How to solve this problem, it seems that docker is the only solution.

Runner manages the new Flask-demo




The environment of python2.7

 sudo gitlab-ci-multi-runner register
Copy the code



Python3.4 environment

 sudo gitlab-ci-multi-runner register
Copy the code



sudo gitlab-ci-multi-runner verify
Copy the code



Create a github-CI file







stages:
  - style
  - test

pep8:
  stage: style
  script:
    - pip install tox
    - tox -ePep8 tags: -python2.7 unittest-py27: stage:test
   script:
     - pip install tox
     - tox -ePy27 tags: -python2.7 unitTest -py34: stage:test
   script:
     - pip install tox
     - tox -e py34
   tags:
     - python3/4

Copy the code



The local docker didn’t pull the image in advance, the download of python2.7 and python3.4 was slow, so I added the accelerator directly

curl -sSL https://get.daocloud.io/daotools/set_mirror.sh | sh -s http://b81aace9.m.daocloud.io
sudo systemctl restart docker 
Copy the code



The result is still wrong, start analysis:

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
Copy the code



Gitlab.example.com cannot be accessed from docker container started by Runner. This is usually caused by the fact that our test environment does not use a domain name, and there is a lot of discussion about this in the GitLab forums. If you are deploying a formal GitLab environment, you will naturally have a domain name to use. But I’m just building a test environment here, so I use a speculative approach:

Docker: /etc/gitlab-runner/config.toml

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

Copy the code






Successful Retry
















PS: THIS time, I will give you a brief introduction of CI, which has not been designed to CD. The next time!