-
Notifications
You must be signed in to change notification settings - Fork 0
/
.gitlab-ci.yml
206 lines (162 loc) · 5.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
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
---
.docker_build_common: &docker_build_common
image: michaelboulton/rocker-deploy:gke-latest
tags:
- dind
services:
- docker:dind
.gcr_login_common: &gcr_login_common
before_script:
- gcloud config set project $GCLOUD_PROJECT_NAME
# update
- gcloud --quiet components update
# get credentials
- echo $GCLOUD_CONTAINER_AUTH | base64 -d > /tmp/auth.json
# login
- gcloud auth activate-service-account --key-file /tmp/auth.json
- docker login -u _json_key --password-stdin https://eu.gcr.io < /tmp/auth.json
variables:
GIT_SUBMODULE_STRATEGY: none
# base docker image name
BASENAME: djangodemoapp
# base name for tag in repository
REMOTE_IMAGE_NAME: ${GCR_REGISTRY_PREFIX}/${GCLOUD_PROJECT_NAME}/${BASENAME}:${CI_COMMIT_TAG}
GCR_REGISTRY_PREFIX: eu.gcr.io
GCLOUD_PROJECT_NAME: zconnect-201710
GCLOUD_CLUSTER_NAME: cluster-1
GCLOUD_COMPUTE_ZONE: europe-west2-a
GCLOUD_VER: 199.0.0
# Extra things that need to be set:
# GCLOUD_CONTAINER_AUTH: Look at helm-deployment-start README on how to get this
# KUBE_NAMESPACE: set via gitlab kubernetes integration
# KUBECONFIG: set via gitlab kubernetes integration
stages:
- precheck
- tests
- push_image
- deploy
#############################################################################
# Run pyflakes
pep8 django app:
image: michaelboulton/python-package-build:3.5-slim-jessie
stage: precheck
before_script:
- pip install pylama
script:
- pylama -o pytest.ini -l pep8 django_demo apps/zconnect-django
allow_failure: true
Pyflakes tests:
image: michaelboulton/python-package-build:3.5-slim-jessie
stage: precheck
before_script:
- pip install pylama
script:
- pylama -o pytest.ini -l pyflakes django_demo/tests apps/zconnect-django/tests
allow_failure: true
Check sort order of django app:
image: michaelboulton/python-package-build:3.5-slim-jessie
stage: precheck
before_script:
- pip install tox
script:
- tox -e isort
allow_failure: true
Pyflakes django app:
image: michaelboulton/python-package-build:3.5-slim-jessie
stage: precheck
before_script:
- pip install pylama
script:
- pylama -o pytest.ini -l pyflakes django_demo apps/zconnect-django/zconnect
#############################################################################
# Integration tests
Run integration tests with docker-compose:
<<: *docker_build_common
only:
- master
variables:
GIT_SUBMODULE_STRATEGY: recursive
GIT_SSL_CAPATH: /etc/ssl/certs/
stage: tests
before_script:
# Use rocker to build the base image and the others
- apk update && apk add --no-cache --virtual .fetch-deps git python3-dev curl openssh libffi-dev build-base openssl-dev linux-headers pcre-dev && rm -rf /var/cache/apk/*
- pip3 install --upgrade pip setuptools docker-compose
- docker-compose -f docker-compose-tavern.yaml build
script:
- docker-compose -f docker-compose-tavern.yaml run tavern
after_script:
- docker-compose -f docker-compose-tavern.yaml stop
#############################################################################
# Tests + pylint
Lint django app:
image: michaelboulton/python-package-build:3.5-slim-jessie
stage: tests
tags:
- kwak
before_script:
- pip install -r requirements.txt
script:
- pylint django_demo apps/zconnect-django/zconnect --rcfile .pylintrc
Test zconnect-django:
image: michaelboulton/python-package-build:3.5-slim-jessie
stage: tests
tags:
- kwak
before_script:
- cd apps/zconnect-django
- pip3 install tox
script:
- tox -e py35-django20
Test django app:
image: michaelboulton/python-package-build:3.5-slim-jessie
stage: tests
tags:
- kwak
before_script:
- pip3 install tox
script:
- tox -e py35-django20
#############################################################################
# build + push image
Build and push docker image:
<<: *docker_build_common
<<: *gcr_login_common
stage: push_image
only:
- tags
script:
- >
docker build .
-t ${REMOTE_IMAGE_NAME}
-f deploy/Dockerfile
- docker push ${REMOTE_IMAGE_NAME}
#############################################################################
# Deploy
Deploy tagged version to integration:
<<: *docker_build_common
image: michaelboulton/helmdeploy:v2.8.2
stage: deploy
environment:
name: integration
variables:
GIT_SUBMODULE_STRATEGY: none
TILLER_NAMESPACE: $KUBE_NAMESPACE
before_script:
- helm init --client-only
- helm repo add incubator https://kubernetes-charts-incubator.storage.googleapis.com
- helm dependency update ./deploy/chart/djangodemoapp
- helm dependency build ./deploy/chart/djangodemoapp
- helm init --upgrade --service-account=tiller-sa
- sleep 10
- helm list
script:
- >
helm upgrade
--namespace $KUBE_NAMESPACE
--values ./deploy/chart/integration.yaml
$(helm list | grep djangodemoapp | awk '{print $1}')
./deploy/chart/djangodemoapp
only:
- tags
when: manual