-
Notifications
You must be signed in to change notification settings - Fork 5
/
.drone.yml
218 lines (202 loc) · 6.99 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
209
210
211
212
213
214
215
216
217
218
kind: pipeline
name: default
type: kubernetes
platform:
os: linux
arch: amd64
steps:
- name: web_tests_then_build_dist
image: quay.io/ukhomeofficedigital/nodejs-base:v6.9.1
commands:
## Band aid workaround to build container after centos7 EOL 20240701 - https://serverfault.com/questions/1161816/mirrorlist-centos-org-no-longer-resolve
- sed -i s/mirror.centos.org/vault.centos.org/g /etc/yum.repos.d/*.repo
- sed -i s/^#.*baseurl=http/baseurl=http/g /etc/yum.repos.d/*.repo
- sed -i s/^mirrorlist=http/#mirrorlist=http/g /etc/yum.repos.d/*.repo
- yum install -y git bzip2 bzip2-libs fontconfig
- git config --global url."https://".insteadOf git://
- npm install -g [email protected]
- cd platform-hub-web
- rm -rf node_modules
- yarn
- yarn run test
- yarn run build
when:
event: [push, tag]
# Expects the optimized dist code to have been built
- name: web_build_image
image: 340268328991.dkr.ecr.eu-west-2.amazonaws.com/acp/dind
commands:
- cd platform-hub-web
# wait for docker service to be up before running docker build.
- n=0; while [ "$n" -lt 60 ] && [ ! -e /var/run/docker.sock ]; do n=$(( n + 1 )); sleep 1; done
- docker build -t platform-hub-web:$${DRONE_COMMIT_SHA} .
volumes:
- name: dockersock
path: /var/run
when:
event: [push, tag]
- name: web_test_image
image: 340268328991.dkr.ecr.eu-west-2.amazonaws.com/acp/dind
commands:
- docker run -t --rm --name platform-hub-web-test platform-hub-web:${DRONE_COMMIT_SHA} sh -c "cd /app; ls -lah; test -e index.html"
volumes:
- name: dockersock
path: /var/run
when:
event: [push, tag]
- name: scan-image-web
pull: Always
image: 340268328991.dkr.ecr.eu-west-2.amazonaws.com/acp/trivy/client:latest
resources:
limits:
cpu: 1000
memory: 1024Mi
environment:
IMAGE_NAME: platform-hub-web:${DRONE_COMMIT_SHA}
IGNORE_UNFIXED: "true"
FAIL_ON_DETECTION: false
FAIL_ON_EOL_OS_DETECTION: false
when:
event:
- pull_request
- push
- name: web_latest_image_to_quay
image: 340268328991.dkr.ecr.eu-west-2.amazonaws.com/acp/dind
commands:
- docker login -u="ukhomeofficedigital+platform_hub" -p=$${DOCKER_PASSWORD} quay.io
- docker tag platform-hub-web:$${DRONE_COMMIT_SHA} quay.io/ukhomeofficedigital/platform-hub-web:$${DRONE_COMMIT_SHA}
- docker tag platform-hub-web:$${DRONE_COMMIT_SHA} quay.io/ukhomeofficedigital/platform-hub-web:latest
- docker push quay.io/ukhomeofficedigital/platform-hub-web:$${DRONE_COMMIT_SHA}
- docker push quay.io/ukhomeofficedigital/platform-hub-web:latest
environment:
DOCKER_PASSWORD:
from_secret: docker_password
volumes:
- name: dockersock
path: /var/run
when:
event: push
branch: master
- name: web_tag_image_to_quay
image: 340268328991.dkr.ecr.eu-west-2.amazonaws.com/acp/dind
commands:
- docker login -u="ukhomeofficedigital+platform_hub" -p=$${DOCKER_PASSWORD} quay.io
- docker tag platform-hub-web:$${DRONE_COMMIT_SHA} quay.io/ukhomeofficedigital/platform-hub-web:$${DRONE_TAG}
- docker push quay.io/ukhomeofficedigital/platform-hub-web:$${DRONE_TAG}
environment:
DOCKER_PASSWORD:
from_secret: docker_password
volumes:
- name: dockersock
path: /var/run
when:
event: tag
- name: api_tests
image: ruby:2.3.8-alpine
environment:
PHUB_DB_HOST: postgres
commands:
- apk -U add ca-certificates libressl postgresql-client postgresql-dev build-base make
- update-ca-certificates
- "echo 'gem: --no-document' > /etc/gemrc && gem install bundler -v 2.1.4"
- cd platform-hub-api
- bundle install --jobs 20 --retry 5 --deployment
- ./test.sh
when:
event: [push, tag]
- name: api_build_image
image: 340268328991.dkr.ecr.eu-west-2.amazonaws.com/acp/dind
commands:
- cd platform-hub-api
# wait for docker service to be up before running docker build.
- n=0; while [ "$n" -lt 60 ] && [ ! -e /var/run/docker.sock ]; do n=$(( n + 1 )); sleep 1; done
- docker build -t platform-hub-api:$${DRONE_COMMIT_SHA} .
volumes:
- name: dockersock
path: /var/run
when:
event: [push, tag]
- name: api_test_image
image: 340268328991.dkr.ecr.eu-west-2.amazonaws.com/acp/dind
environment:
POSTGRES_USER: phub
POSTGRES_PASSWORD: phub_password
commands:
- docker run -d --name phub-api-postgres-${DRONE_BUILD_NUMBER} -e POSTGRES_USER -e POSTGRES_PASSWORD postgres:12.5
- sleep 5
- docker run --name phub-api-${DRONE_BUILD_NUMBER} -t --rm --env-file=platform-hub-api/.env.test -e PHUB_DB_HOST=phub-api-postgres-${DRONE_BUILD_NUMBER} --link phub-api-postgres-${DRONE_BUILD_NUMBER} platform-hub-api:${DRONE_COMMIT_SHA} /bin/bash -c "cd /app; bin/setup; bin/rails server -d; sleep 5; curl -s -f http://127.0.0.1:3000/healthz"
when:
event: [push, tag]
volumes:
- name: dockersock
path: /var/run
- name: cleanup_postgres
image: 340268328991.dkr.ecr.eu-west-2.amazonaws.com/acp/dind
commands:
- docker rm -f phub-api-postgres-${DRONE_BUILD_NUMBER}
volumes:
- name: dockersock
path: /var/run
when:
event: [push, tag]
status: [success, failure]
- name: scan-image-api
pull: Always
image: 340268328991.dkr.ecr.eu-west-2.amazonaws.com/acp/trivy/client:latest
resources:
limits:
cpu: 1000
memory: 1024Mi
environment:
IMAGE_NAME: platform-hub-api:${DRONE_COMMIT_SHA}
IGNORE_UNFIXED: "true"
FAIL_ON_DETECTION: false
FAIL_ON_EOL_OS_DETECTION: false
when:
event:
- pull_request
- push
- name: api_latest_image_to_quay
image: 340268328991.dkr.ecr.eu-west-2.amazonaws.com/acp/dind
commands:
- docker login -u="ukhomeofficedigital+platform_hub" -p=$${DOCKER_PASSWORD} quay.io
- docker tag platform-hub-api:$${DRONE_COMMIT_SHA} quay.io/ukhomeofficedigital/platform-hub-api:$${DRONE_COMMIT_SHA}
- docker tag platform-hub-api:$${DRONE_COMMIT_SHA} quay.io/ukhomeofficedigital/platform-hub-api:latest
- docker push quay.io/ukhomeofficedigital/platform-hub-api:$${DRONE_COMMIT_SHA}
- docker push quay.io/ukhomeofficedigital/platform-hub-api:latest
environment:
DOCKER_PASSWORD:
from_secret: docker_password
volumes:
- name: dockersock
path: /var/run
when:
event: push
branch: master
- name: api_tag_image_to_quay
image: 340268328991.dkr.ecr.eu-west-2.amazonaws.com/acp/dind
commands:
- docker login -u="ukhomeofficedigital+platform_hub" -p=$${DOCKER_PASSWORD} quay.io
- docker tag platform-hub-api:$${DRONE_COMMIT_SHA} quay.io/ukhomeofficedigital/platform-hub-api:$${DRONE_TAG}
- docker push quay.io/ukhomeofficedigital/platform-hub-api:$${DRONE_TAG}
environment:
DOCKER_PASSWORD:
from_secret: docker_password
volumes:
- name: dockersock
path: /var/run
when:
event: tag
services:
- name: docker
image: 340268328991.dkr.ecr.eu-west-2.amazonaws.com/acp/dind
- name: postgres
image: postgres:12.5
ports:
- 5432
environment:
POSTGRES_USER: phub
POSTGRES_PASSWORD: phub_password
volumes:
- name: dockersock
temp: {}