-
Notifications
You must be signed in to change notification settings - Fork 4
/
.drone.yml
208 lines (197 loc) · 6.74 KB
/
.drone.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
207
208
---
kind: pipeline
type: kubernetes
name: default
platform:
os: linux
arch: amd64
steps:
- name: build
image: 340268328991.dkr.ecr.eu-west-2.amazonaws.com/acp/dind
environment:
DOCKER_HOST: tcp://127.0.0.1:2375
DOCKER_IMAGE: lev-web
MOCK_IMAGE: quay.io/ukhomeofficedigital/lev-api:0.18
commands:
- sleep 20
- set -o pipefail
- DOCKER_NAME="$${DOCKER_IMAGE}-$${DRONE_BUILD_NUMBER}"
- docker build -t "$${DOCKER_IMAGE}" .
- docker build -t "$${DOCKER_IMAGE}-testing" -f Dockerfile-testing .
- docker run -d --name "$${DOCKER_NAME}" "$${DOCKER_IMAGE}"
- docker run -d --name "$${DOCKER_NAME}-mock" --net "container:$${DOCKER_NAME}" --env "MOCK=true" "$${MOCK_IMAGE}"
- sleep 5
- printf "* lev-web unit and acceptance test logs *\n\n" > test.log
- docker run --net "container:$${DOCKER_NAME}" "$${DOCKER_IMAGE}-testing" | tee -a 'test.log'
- docker rm -vf "$${DOCKER_NAME}" "$${DOCKER_NAME}-mock"
when:
branch:
- master
event:
- pull_request
- push
- name: perf_test
pull: if-not-exists
image: quay.io/ukhomeofficedigital/lev-ci
commands:
- make 'compose_project_name=lev-web-${DRONE_BUILD_NUMBER}' test
environment:
DOCKER_HOST: tcp://docker:2375
DOCKER_REPO_MOCK: docker.digital.homeoffice.gov.uk
DOCKER_USERNAME_MOCK: lev-kube
when:
event:
- pull_request
- name: push_image
pull: if-not-exists
image: 340268328991.dkr.ecr.eu-west-2.amazonaws.com/acp/dind
environment:
DOCKER_HOST: tcp://127.0.0.1:2375
MOCK_IMAGE: quay.io/ukhomeofficedigital/lev-api:0.18
DOCKER_BASEDIR: /ukhomeofficedigital/
DOCKER_IMAGE: lev-web
DOCKER_QUAY_PASSWORD:
from_secret: DOCKER_QUAY_PASSWORD
DOCKER_REPO: quay.io
DOCKER_USERNAME: ukhomeofficedigital+lev_web
commands:
- sleep 20
- PACKAGE_VERSION=$(grep version package.json | head -1 | awk -F ":" '{ print $2 }' | sed 's/[",]//g' | tr -d '[[:space:]]')
- TAG="v$${PACKAGE_VERSION}-$${DRONE_BUILD_NUMBER}-$${DRONE_COMMIT}"
- IMAGE="$${DOCKER_REPO}$${DOCKER_BASEDIR}$${DOCKER_IMAGE}"
- docker login -u="$${DOCKER_USERNAME}" -p="$${DOCKER_QUAY_PASSWORD}" "$${DOCKER_REPO}"
- docker tag "$${DOCKER_IMAGE}" "$${IMAGE}:$${TAG}"
- docker push "$${IMAGE}:$${TAG}"
- E2E_IMAGE="$${IMAGE}-e2e"
- docker build -t "$${E2E_IMAGE}" -f Dockerfile-e2e .
- docker tag "$${E2E_IMAGE}" "$${E2E_IMAGE}:$${TAG}"
- docker tag "$${E2E_IMAGE}" "$${E2E_IMAGE}:latest"
- docker push "$${E2E_IMAGE}:$${TAG}"
- docker push "$${E2E_IMAGE}:latest"
when:
branch:
- master
event:
- push
- name: deploy_image
pull: if-not-exists
image: quay.io/ukhomeofficedigital/kd:latest
commands:
- PACKAGE_VERSION=$(grep version package.json | head -1 | awk -F ":" '{ print $2 }' | sed 's/[",]//g' | tr -d '[[:space:]]')
- TAG="v$${PACKAGE_VERSION}-$${DRONE_BUILD_NUMBER}-$${DRONE_COMMIT}"
- IMAGE="$${DOCKER_REPO}$${DOCKER_BASEDIR}$${DOCKER_IMAGE}"
- kubectl="kubectl --insecure-skip-tls-verify --server=$${KUBE_SERVER} --namespace=$${KUBE_NAMESPACE} --token=$${KUBE_TOKEN}"
- $${kubectl} scale deployment $${KUBE_DEPLOYMENT} --replicas 2
- $${kubectl} set image deployment/$${KUBE_DEPLOYMENT} "$${KUBE_CONTAINER}=$${IMAGE}:$${TAG}"
- $${kubectl} rollout status deployment/$${KUBE_DEPLOYMENT}
- $${kubectl} scale deployment $${KUBE_DEPLOYMENT} --replicas 1
- sleep 60
environment:
DOCKER_BASEDIR: /ukhomeofficedigital/
DOCKER_IMAGE: lev-web
DOCKER_REPO: quay.io
KUBE_CONTAINER:
from_secret: KUBE_CONTAINER
KUBE_DEPLOYMENT:
from_secret: KUBE_DEPLOYMENT
KUBE_NAMESPACE:
from_secret: KUBE_NAMESPACE
KUBE_SERVER:
from_secret: KUBE_SERVER
KUBE_TOKEN:
from_secret: KUBE_TOKEN
when:
branch:
- master
event:
- push
- name: e2e_test
pull: if-not-exists
image: 340268328991.dkr.ecr.eu-west-2.amazonaws.com/acp/dind
commands:
- sleep 20
- PACKAGE_VERSION=$(grep version package.json | head -1 | awk -F ":" '{ print $2 }' | sed 's/[",]//g' | tr -d '[[:space:]]')
- TAG="v$${PACKAGE_VERSION}-$${DRONE_BUILD_NUMBER}-$${DRONE_COMMIT}"
- IMAGE="$${DOCKER_REPO}$${DOCKER_BASEDIR}$${DOCKER_IMAGE}"
- set -o pipefail
- docker run --rm --name "$${DOCKER_IMAGE}" -e "ENV=dev" -e "KEYCLOAK_URL=$${DEV_KEYCLOAK_URL}" -e "TEST_URL=$${DEV_URL}" -e "TEST_USERNAME=$${DEV_USERNAME}" -e "TEST_PASSWORD=$${DEV_PASSWORD}" "$${IMAGE}:$${TAG}" | tee 'test.log'
environment:
DEV_KEYCLOAK_URL:
from_secret: DEV_KEYCLOAK_URL
DEV_PASSWORD:
from_secret: DEV_PASSWORD
DEV_URL:
from_secret: DEV_URL
DEV_USERNAME:
from_secret: DEV_USERNAME
DOCKER_BASEDIR: /ukhomeofficedigital/
DOCKER_HOST: tcp://127.0.0.1:2375
DOCKER_IMAGE: lev-web-e2e
DOCKER_REPO: quay.io
when:
branch:
- master
event:
- push
- name: save_test_logs
pull: if-not-exists
image: quay.io/ukhomeofficedigital/kd:latest
commands:
- kubectl="kubectl --insecure-skip-tls-verify --server=$${KUBE_SERVER} --namespace=$${KUBE_NAMESPACE} --token=$${KUBE_TOKEN}"
- $${kubectl} annotate --overwrite deployment $${KUBE_DEPLOYMENT} lev-web-test-log="`cat test.log`"
environment:
KUBE_DEPLOYMENT:
from_secret: KUBE_DEPLOYMENT
KUBE_NAMESPACE:
from_secret: KUBE_NAMESPACE
KUBE_SERVER:
from_secret: KUBE_SERVER
KUBE_TOKEN:
from_secret: KUBE_TOKEN
when:
branch:
- master
event:
- push
- name: notify_slack_success
pull: if-not-exists
image: plugins/slack:1.0
settings:
channel: general
template: "*Deployed {{repo.name}} to Dev* - <{{build.link}}|#{{build.number}}>\n"
username: Drone
environment:
SLACK_WEBHOOK:
from_secret: slack_webhook
when:
branch:
- master
event:
- push
status:
- success
- name: notify_slack_failure
pull: if-not-exists
image: plugins/slack
settings:
channel: alerts
template: "*Failed to deploy {{repo.name}} to Dev*\nAuthor: {{build.author}}\nDuration: {{since job.started}} Job: <{{build.link}}|#{{build.number}}>\nCommit: {{build.commit}}\n"
username: Drone
environment:
SLACK_WEBHOOK:
from_secret: slack_webhook
when:
branch:
- master
event:
- push
status:
- failure
services:
- name: docker
image: 340268328991.dkr.ecr.eu-west-2.amazonaws.com/acp/dind
when:
event:
- pull_request
- push
...