CD/CI - Continuous Delivery / Continuous Integration is a DevOps methodology that speeds up software delivery
We need to combine:
The latest tool in the zoo is ruff.
It supports +900 linting rules
$ ruff check --output-format=concise helloworld.py
helloworld.py:3:1: SyntaxError: Unexpected indentation
helloworld.py:5:1: SyntaxError: Expected a statement
Found 2 errors.
mypy is the go-to tool - leveraging type hints
mult.py
$ mypy mult.py
mult.py:6: error: Argument 2 to "mult_int" has incompatible type "str"; expected "int" [arg-type]
Found 1 error in 1 file (checked 1 source file)
$ python3 mult.py
Mult 3*6 is:
666
helloworld.py) that prints somethingruff and mypy in your environmentcpython latest linting check: cpython latest tests python versionsConfigured with a file YAML file named .gitlab-ci.yaml
gitlab.dkrz.de’s CI.gitlab-ci.yml.gitlab-ci.yml
stages:
- static-analysis
default:
image: python # container image with basic python tools
tags:
- docker-any-image # note this is specific to DKRZ's gitlab
linter:
stage: static-analylsis
script:
- pip install ruff
- ruff check .
type-check:
stage: static-analysis
script:
- pip install mypy
- mypy ..gitlab-ci.yml.gitlab-ci.yml
In order to run the CI, code needs to run1 somewhere.
tags.python: an operating system with Python pre-installedThe image keyword specifies an image for the executor to use
docker-any-image tag on DKRZ gitlab.Create a simple Gitlab CI pipeline job on your repository:
python and print "Hello world!"Important
⚠️ You need to enable CI/CD in Settings->General->“Visibility, project features, permissions” and enable enable instance runners under “Settings->CI/CD->Runners”.
Tip
Since you are using DKRZ’s Gitlab refer to the documentation:
ruff
mypy as wellartifacts1 allows us to specify which files to keep
.gitlab-ci.yml
$ cat output/result.txt
cat: output/result.txt: No such file or directory
The pipeline fails, job2 starts from the same initial point as job1 and there is no persistency!
parallel:matrix1 one can run a job in parallel.
parallel:matrix1 one can run a job in parallel.
In Gitlab different executors1 offer different isolation settings.
With SSH and Shell executors, a job that runs rm -rf / could destroy the state of the runner (persistency).
The same using Docker would only destroy the newly created isolated environment (not even the image)
Automate the locally checking the code with git hooks 1.
.git/hooks/pre-commit.sample. What does it do?helloworld.py)Using the pre-commit tool:
.pre-commit-config.yaml