-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy path.gitlab-ci.yml
More file actions
81 lines (76 loc) · 2.82 KB
/
Copy path.gitlab-ci.yml
File metadata and controls
81 lines (76 loc) · 2.82 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
stages:
- lint
- test
- build
variables:
PIP_CACHE_DIR: "$CI_PROJECT_DIR/.cache/pip"
default:
image: python:3.12-slim
tags:
- SN-runner
cache:
key: "$CI_COMMIT_REF_SLUG" # Cache per branch
paths:
- "$PIP_CACHE_DIR"
before_script:
- apt-get update && apt-get install -y --no-install-recommends git
- pip install -r requirements.txt
lint:
stage: lint
script:
- isort src tests --check
- black src tests --check
- flake8 src tests
- mypy src
rules:
- if: '$CI_PIPELINE_SOURCE == "merge_request_event"'
tests:
stage: test
script:
# Generate terminal output, XML for GitLab integration, and HTML for Browse
- pytest --cov=src --cov-report=term --cov-report=xml:coverage.xml --cov-report=html:coverage_html
artifacts:
reports:
coverage_report:
coverage_format: cobertura
path: coverage.xml
paths:
- coverage.xml
- .coverage # Raw coverage data
- coverage_html # HTML report
expire_in: 7 days
build-docker-image:
stage: build
image:
name: gcr.io/kaniko-project/executor:v1.14.0-debug # Kaniko image for building Docker images
entrypoint: [""] # Override entrypoint for Kaniko
tags:
- SN-runner # Ensure this job runs on a runner that can execute Docker/Kaniko
cache: {} # Disable default cache inherited from 'default' key, as it's not relevant for this job
before_script: [] # Disable default before_script as Kaniko image doesn't have apt-get/pip
script:
- |
# Determine Docker image destination tag based on the pipeline context
if [ -n "$CI_COMMIT_TAG" ]; then # If it's a git tag
DESTINATION="${CI_REGISTRY_IMAGE}:${CI_COMMIT_TAG}"
elif [ "$CI_COMMIT_BRANCH" == "$CI_DEFAULT_BRANCH" ]; then # If it's the default branch (e.g., main)
DESTINATION="${CI_REGISTRY_IMAGE}:latest"
elif [ "$CI_PIPELINE_SOURCE" == "merge_request_event" ]; then # If it's a merge request
# Tag for MRs, e.g., for review apps or temporary images
DESTINATION="${CI_REGISTRY_IMAGE}:mr-${CI_MERGE_REQUEST_IID}"
else # Fallback for other branches/contexts
DESTINATION="${CI_REGISTRY_IMAGE}:${CI_COMMIT_REF_SLUG}-${CI_COMMIT_SHORT_SHA}"
fi
echo "Building and pushing Docker image to: ${DESTINATION}"
- /kaniko/executor
--context "${CI_PROJECT_DIR}"
--dockerfile "${CI_PROJECT_DIR}/Dockerfile"
--destination "${DESTINATION}"
# Example: pass build arguments to Dockerfile
# --build-arg "MY_BUILD_ARG=${SOME_CI_VARIABLE}"
rules:
# Run this job for:
- if: "$CI_COMMIT_TAG" # Git tags
- if: "$CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH" # Commits to the default branch
- if: '$CI_PIPELINE_SOURCE == "merge_request_event"' # Merge requests
needs: [] # This job does not depend on artifacts from previous jobs in this example