Files
IKT206-kubernetes-cluster/.gitlab-ci.yml
2026-07-26 10:07:10 +02:00

55 lines
1.3 KiB
YAML

# CI/CD Pipeline for project
# what the pipeline should do: build, test, deploy
stages:
- test
- build
#global variables that is used in the pipeline
variables:
IMAGE_VERSION: "$CI_COMMIT_SHORT_SHA"
# 1. test the image (prøver å bruke dind istedenfor python image)
test:
stage: test
image: python:3.10
before_script:
- cd webapp
- pip install -r requirements.txt
- pip install pytest pytest-cov
script:
# run pytest with junit + coverage reports from within the webapp directory
- python -m pytest tests/ --junitxml=report.xml --cov=. --cov-report=term-missing --cov-report=xml:coverage.xml
coverage: '/TOTAL.*\s+(\d+%)$/'
artifacts:
when: always
reports:
junit: webapp/report.xml
coverage_report:
coverage_format: cobertura
path: webapp/coverage.xml
paths:
- webapp/report.xml
- webapp/coverage.xml
rules:
- exists:
- webapp/requirements.txt
# 2. build docker image and push it
build:
stage: build
# use kaniko to build and push the image to the registry
image:
name: gcr.io/kaniko-project/executor:debug
entrypoint: [""]
script:
- /kaniko/executor --context "$CI_PROJECT_DIR/webapp"
--dockerfile "$CI_PROJECT_DIR/webapp/Dockerfile"
--destination "$CI_REGISTRY_IMAGE:$IMAGE_VERSION"
--destination "$CI_REGISTRY_IMAGE:latest"