-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path.gitlab-ci.yml
180 lines (169 loc) · 4 KB
/
.gitlab-ci.yml
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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
image: python:3.11.6
stages:
- prepare
- linting
- testing
- building
variables:
PIP_CACHE_DIR: "$CI_PROJECT_DIR/.cache/pip"
VENV_PATH: "$CI_PROJECT_DIR/.venv"
cache:
key: "${CI_COMMIT_REF_SLUG}-${CI_COMMIT_SHA}"
paths:
- $PIP_CACHE_DIR
- $VENV_PATH
before_script:
- apt-get update
- apt install -y libldap2-dev libsasl2-dev ldap-utils
cache dependencies:
stage: prepare
interruptible: true
rules:
- if: $CI_PIPELINE_SOURCE != "schedule"
changes:
- ".gitlab-ci.yml"
- "*.py"
- "app/**/*"
- "migrations/**/*"
- "tests/**/*"
- "requirements.txt"
script:
- python -m venv $VENV_PATH
- source $VENV_PATH/bin/activate
- pip install --upgrade pip && pip install -r requirements.txt
cache:
key: "${CI_COMMIT_REF_SLUG}-${CI_COMMIT_SHA}"
paths:
- $PIP_CACHE_DIR
- $VENV_PATH
policy: push
imports ordering:
stage: linting
interruptible: true
rules:
- if: $CI_PIPELINE_SOURCE != "schedule"
changes:
- ".gitlab-ci.yml"
- "*.py"
- "app/**/*"
- "migrations/**/*"
- "tests/**/*"
- "requirements.txt"
script:
- source $VENV_PATH/bin/activate
- isort *.py {app,tests}/**/*.py --check-only
cache:
key: "${CI_COMMIT_REF_SLUG}-${CI_COMMIT_SHA}"
paths:
- $PIP_CACHE_DIR
- $VENV_PATH
policy: pull
style checks:
stage: linting
interruptible: true
rules:
- if: $CI_PIPELINE_SOURCE != "schedule"
changes:
- ".gitlab-ci.yml"
- "*.py"
- "app/**/*"
- "migrations/**/*"
- "tests/**/*"
- "requirements.txt"
script:
- source $VENV_PATH/bin/activate
- flake8 {app,tests}/**/*.py
cache:
key: "${CI_COMMIT_REF_SLUG}-${CI_COMMIT_SHA}"
paths:
- $PIP_CACHE_DIR
- $VENV_PATH
policy: pull
type checks:
stage: linting
interruptible: true
rules:
- if: $CI_PIPELINE_SOURCE != "schedule"
changes:
- ".gitlab-ci.yml"
- "*.py"
- "app/**/*"
- "migrations/**/*"
- "tests/**/*"
- "requirements.txt"
script:
- source $VENV_PATH/bin/activate
- mypy {app,tests}/**/*.py
cache:
key: "${CI_COMMIT_REF_SLUG}-${CI_COMMIT_SHA}"
paths:
- $PIP_CACHE_DIR
- $VENV_PATH
policy: pull
unit_test:
stage: testing
interruptible: true
rules:
- if: $CI_PIPELINE_SOURCE != "schedule"
changes:
- ".gitlab-ci.yml"
- "*.py"
- "app/**/*"
- "migrations/**/*"
- "requirements.txt"
- "tests/**/*"
services:
- name: postgres
alias: db-service
variables:
PIP_CACHE_DIR: "$CI_PROJECT_DIR/.cache/pip"
POSTGRES_USER: "user"
POSTGRES_PASSWORD: "pass"
TEST_DB_SERVER_URL: "postgresql://user:pass@db-service"
cache:
key: "${CI_COMMIT_REF_SLUG}-${CI_COMMIT_SHA}"
paths:
- $PIP_CACHE_DIR
- $VENV_PATH
policy: pull
script:
- source $VENV_PATH/bin/activate
- pytest --junitxml=report.xml --cov=app/ tests/
- coverage xml
coverage: '/(?i)total.*? (100(?:\.0+)?\%|[1-9]?\d(?:\.\d+)?\%)$/'
artifacts:
when: always
reports:
junit: report.xml
coverage_report:
coverage_format: cobertura
path: coverage.xml
build docker image:
image: docker:latest
stage: building
interruptible: true
rules:
- if: $CI_COMMIT_BRANCH == "master" && $CI_PIPELINE_SOURCE != "schedule"
changes:
- ".gitlab-ci.yml"
- "*.py"
- "app/**/*"
- "migrations/**/*"
- "*requirements.txt"
- "tests/**/*"
variables:
DOCKER_TLS_CERTDIR: "/certs"
tags:
- docker
services:
- docker:dind
before_script: []
script:
- >
docker build
-t $CI_REGISTRY_IMAGE:latest
--cache-from $CI_REGISTRY_IMAGE:latest
.
- docker tag $CI_REGISTRY_IMAGE:latest $CI_REGISTRY_IMAGE:$CI_COMMIT_REF_NAME
- docker login -u $CI_DEPLOY_USER -p $CI_DEPLOY_PASSWORD $CI_REGISTRY
- docker push $CI_REGISTRY_IMAGE:$CI_COMMIT_REF_NAME