... | ... | @@ -80,15 +80,69 @@ The goal of this pipeline is to create the package wheel for this library and pu |
|
|
Doing this enable the user to retrieve this python library with a simple
|
|
|
`pip install lib`
|
|
|
|
|
|
-[]TODO complete this part based on DDMS libraries
|
|
|
Example of CI pipeline
|
|
|
```yaml
|
|
|
default:
|
|
|
image: python:3.7-slim-buster
|
|
|
|
|
|
stages:
|
|
|
- pytest
|
|
|
- publish
|
|
|
|
|
|
build:
|
|
|
stage: pytest
|
|
|
script:
|
|
|
- pip3 install -r requirements.txt
|
|
|
- pip3 install -r requirements_tests.txt
|
|
|
- pytest test --junitxml=report.xml
|
|
|
artifacts:
|
|
|
when: always
|
|
|
reports:
|
|
|
junit: report.xml
|
|
|
|
|
|
# This job only runs on master, and it creates the lib and push it to the feed
|
|
|
deploylib:
|
|
|
stage: publish
|
|
|
script:
|
|
|
- pip3 install -r requirements.txt
|
|
|
- pip3 install twine
|
|
|
- python3 setup.py sdist bdist_wheel
|
|
|
- TWINE_PASSWORD=${CI_JOB_TOKEN} TWINE_USERNAME=${CI_REGISTRY_USER} python -m twine upload --repository-url ${CI_API_V4_URL}/projects/${CI_PROJECT_ID}/packages/pypi dist/*
|
|
|
rules:
|
|
|
- if: $CI_COMMIT_BRANCH == 'master'
|
|
|
```
|
|
|
The first part defines the image to use, the stages then the pytest part as in the previous example.
|
|
|
The second stage is about generating the python package, for more pythonic details on this please refer to the [documentation](https://packaging.python.org/tutorials/packaging-projects/).
|
|
|
|
|
|
This stage install only the dependencies needed for running the application then the package is generated by the `python3 setup.py sdist bdist_wheel` command
|
|
|
|
|
|
The command `TWINE_PASSWORD=${CI_JOB_TOKEN} TWINE_USERNAME=${CI_REGISTRY_USER} python -m twine upload --repository-url ${CI_API_V4_URL}/projects/${CI_PROJECT_ID}/packages/pypi dist/*` is using some GitLab environment variables, automatically set during the CI pipeline:
|
|
|
- CI_JOB_TOKEN : password token used to grant access to the package repository
|
|
|
- CI_REGISTRY_USER : user used to grant access to the package repository
|
|
|
- CI_API_V4_URL : base URL of the repository
|
|
|
- CI_PROJECT_ID : id of the current project (in order to store the packages in this project's package repository)
|
|
|
|
|
|
|
|
|
```yaml
|
|
|
deploylib:
|
|
|
stage: publish
|
|
|
script:
|
|
|
- pip3 install -r requirements.txt
|
|
|
- pip3 install twine
|
|
|
- python3 setup.py sdist bdist_wheel
|
|
|
- TWINE_PASSWORD=${CI_JOB_TOKEN} TWINE_USERNAME=${CI_REGISTRY_USER} python -m twine upload --repository-url ${CI_API_V4_URL}/projects/${CI_PROJECT_ID}/packages/pypi dist/*
|
|
|
```
|
|
|
The last part only executes this stage when commiting on master. We do not want to generate the package for each commit for every branch, only when the merge is done on master
|
|
|
```yaml
|
|
|
rules:
|
|
|
- if: $CI_COMMIT_BRANCH == 'master'
|
|
|
```
|
|
|
|
|
|
## Continuous integration pipeline for python service projects.
|
|
|
The goal of this pipeline is to create the docker image associated to the service and push it to a docker registry (Container Registry)
|
|
|
In this case some automatic tests can be run directly on the newly generated docker image, [GitLab is providing several tools](https://docs.gitlab.com/ee/user/application_security/).
|
|
|
|
|
|
-[]TODO complete this part based on DDMS Service
|
|
|
|
|
|
## Full example
|
|
|
Example of CI pipeline
|
|
|
```yaml
|
|
|
stages:
|
|
|
- pytest
|
... | ... | @@ -153,4 +207,7 @@ include: |
|
|
- template: Container-Scanning.gitlab-ci.yml
|
|
|
- template: Dependency-Scanning.gitlab-ci.yml
|
|
|
- template: Security/SAST.gitlab-ci.yml
|
|
|
``` |
|
|
\ No newline at end of file |
|
|
```
|
|
|
|
|
|
The first part is about defining the stages, then running the test.
|
|
|
The second part will create the docker image and push it to a docker repository |
|
|
\ No newline at end of file |