Pipelines
March 12, 2024
What is a CI/CD pipeline? - source #
A CI/CD pipeline automates your software delivery process. The pipeline builds code, runs tests (CI), and safely deploys a new version of the application (CD).
Automated pipelines remove manual errors, provide standardized feedback loops to developers, and enable fast product iterations.
Hugo CI/CD Pipeline - source #
image: registry.gitlab.com/pages/hugo/hugo_extended:latest
variables:
HUGO_ENV: production
THEME_URL: "github.com/alex-shpak/hugo-book"
default:
before_script:
- apk add --no-cache go curl bash nodejs
- hugo mod get -u $THEME_URL
pages:
script:
- hugo
artifacts:
paths:
- public
rules:
- if: $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH
Python Poetry CI/CD Pipeline #
# This file is a template, and might need editing before it works on your project.
# To contribute improvements to CI/CD templates, please follow the Development guide at:
# https://docs.gitlab.com/ee/development/cicd/templates.html
# This specific template is located at:
# https://gitlab.com/gitlab-org/gitlab/-/blob/master/lib/gitlab/ci/templates/Python.gitlab-ci.yml
# Official language image. Look for the different tagged releases at:
# https://hub.docker.com/r/library/python/tags/
image: python:latest
# Change pip's cache directory to be inside the project directory since we can
# only cache local items.
variables:
PIP_CACHE_DIR: "$CI_PROJECT_DIR/.cache/pip"
stages:
- test
- lint
- types
- deploy
# https://pip.pypa.io/en/stable/topics/caching/
cache:
paths:
- .cache/pip
before_script:
- python --version ; pip --version # For debugging
- pip install poetry
- poetry install
- source `poetry env info --path`/bin/activate
Unit Tests:
stage: test
script:
- echo "This is the test stage."
- cd tests
- poetry --version
Python Code Lint:
stage: lint
script:
- echo "let's do some linting."
- black .
Static Type check:
stage: types
script:
- echo "let's do some type checking."
- mypy .
Deploy:
stage: deploy
script:
- echo "let's deploy some code."
GitLab CI Pipeline - source #
# Work in Progress Pipeline for GitLab CI
default:
image: python:3.9
before_script:
- pip install poetry
- poetry install
- source `poetry env info --path`/bin/activate
stages:
- test
- build
testing:
stage: test
script:
- echo "This is the test stage"
- cd tests
- python3 -m unittest -v
- pytest --junitxml=report.xml
artifacts:
when: always
reports:
junit: /builds/USERNAME/python-devop/tests/report.xml
building:
stage: build
needs: [testing]
script:
- echo "This is the build stage"
- poetry config repositories.gitlab https://gitlab.example.de/path/to/packages/pypi
- echo "Repository gitlab configured ..."
- poetry build
- echo "Build done ..."
- poetry publish --repository gitlab -u YOURUSERNAME -p YOURTOKEN
- echo "Publishing done!"