-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path.gitlab-ci.yml
285 lines (271 loc) · 12.7 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
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
stages:
- Image Build
- Deployment
- Restart Pods
- Image Scan
include:
- local: 'version.yml'
# - project: 'DSO/DASTScanner'
# file: '.gitlab-ci.yml'
- remote: 'https://gitlab.com/prismacloud-public/shift-left/extension/-/raw/master/.pcs.gitlab-ci.yml'
CopyDevImages:
stage: Image Build
tags:
- qed-stg-runner
when: manual
image:
name: gcr.io/kaniko-project/executor:debug
entrypoint: [ "" ]
script:
- mkdir -p /kaniko/.docker
- echo "{\"auths\":{\"$CI_REGISTRY\":{\"username\":\"$CI_REGISTRY_USER\",\"password\":\"$CI_REGISTRY_PASSWORD\"}}}" > /kaniko/.docker/config.json
- mkdir -p /workspace
# HMS .NET5 image
- echo "FROM ghcr.io/quanted/hms:dev" > /workspace/Dockerfile
- /kaniko/executor --context=/workspace --destination=$CI_REGISTRY_IMAGE/hms_dotnet:$CI_COMMIT_REF_NAME
# HMS django image
- echo "FROM ghcr.io/quanted/hms_app:dev-kube" > /workspace/Dockerfile
- /kaniko/executor --context=/workspace --destination=$CI_REGISTRY_IMAGE/hms_django:$CI_COMMIT_REF_NAME
# HMS flask image
- echo "FROM ghcr.io/quanted/hms_flask:dev-kube" > /workspace/Dockerfile
- /kaniko/executor --context=/workspace --destination=$CI_REGISTRY_IMAGE/hms_flask:$CI_COMMIT_REF_NAME
# HMS dask image
# - echo "FROM ghcr.io/quanted/hms_flask:dev-kube" > /workspace/Dockerfile
# - /kaniko/executor --context=/workspace --destination=$CI_REGISTRY_IMAGE/hms_dask:$CI_COMMIT_REF_NAME
# HMS nginx image
- echo "FROM ghcr.io/quanted/hms-nginx:dev-gl" > /workspace/Dockerfile
- /kaniko/executor --context=/workspace --destination=$CI_REGISTRY_IMAGE/hms_nginx:$CI_COMMIT_REF_NAME
# HMS mongo image
- echo "FROM ghcr.io/quanted/hms-mongo:dev-gl" > /workspace/Dockerfile
- /kaniko/executor --context=/workspace --destination=$CI_REGISTRY_IMAGE/hms_mongo:$CI_COMMIT_REF_NAME
environment:
name: stg
url: http://qed.qed-stage.aws.epa.gov
kubernetes:
namespace: qed-45-stg
SetProdImages:
stage: Image Build
tags:
- qed-stg-runner
when: manual
image:
name: gcr.io/kaniko-project/executor:debug
entrypoint: [ "" ]
script:
- mkdir -p /kaniko/.docker
- echo "{\"auths\":{\"$CI_REGISTRY\":{\"username\":\"$CI_REGISTRY_USER\",\"password\":\"$CI_REGISTRY_PASSWORD\"}}}" > /kaniko/.docker/config.json
- mkdir -p /workspace
# HMS .NET5 image
- echo "FROM $CI_REGISTRY_IMAGE/hms_dotnet:dev-gl" > /workspace/Dockerfile
- /kaniko/executor --context=/workspace --destination=$CI_REGISTRY_IMAGE/hms_dotnet:main-$PROD_VERSION
# HMS django image
- echo "FROM $CI_REGISTRY_IMAGE/hms_django:dev-gl" > /workspace/Dockerfile
- /kaniko/executor --context=/workspace --destination=$CI_REGISTRY_IMAGE/hms_django:main-$PROD_VERSION
# HMS flask image
- echo "FROM $CI_REGISTRY_IMAGE/hms_flask:dev-gl" > /workspace/Dockerfile
- /kaniko/executor --context=/workspace --destination=$CI_REGISTRY_IMAGE/hms_flask:main-$PROD_VERSION
# HMS dask image
- echo "FROM $CI_REGISTRY_IMAGE/hms_dask:dev-gl" > /workspace/Dockerfile
- /kaniko/executor --context=/workspace --destination=$CI_REGISTRY_IMAGE/hms_dask:main-$PROD_VERSION
# HMS nginx image
- echo "FROM $CI_REGISTRY_IMAGE/hms_nginx:dev-gl" > /workspace/Dockerfile
- /kaniko/executor --context=/workspace --destination=$CI_REGISTRY_IMAGE/hms_nginx:main-$PROD_VERSION
# HMS mongo image
- echo "FROM $CI_REGISTRY_IMAGE/hms_mongo:dev-gl" > /workspace/Dockerfile
- /kaniko/executor --context=/workspace --destination=$CI_REGISTRY_IMAGE/hms_mongo:main-$PROD_VERSION
environment:
name: stg
url: http://qed.qed-stage.aws.epa.gov
kubernetes:
namespace: qed-45-stg
LoadVolumeData:
stage: Deployment
tags:
- qed-stg-runner
when: manual
image: dtzar/helm-kubectl
script:
- kubectl config set-cluster "$KUBECTL_DEV_CLUSTER" --server="$KUBE_URL"
- kubectl config set-cluster "$KUBECTL_DEV_CLUSTER" --certificate-authority=$KUBE_CA_PEM_FILE --embed-certs=true
- kubectl config set-credentials gitlab --token="$KUBE_TOKEN"
- kubectl config set-context default --cluster="$KUBECTL_DEV_CLUSTER" --user=gitlab --namespace="$KUBE_NAMESPACE"
- kubectl config use-context default
- chmod 775 ./hms-volume-setup.sh
- ./hms-volume-setup.sh
environment:
name: stg
url: http://qed.qed-stage.aws.epa.gov
kubernetes:
namespace: qed-45-stg
ApplyManifests:
stage: Deployment
tags:
- qed-stg-runner
when: manual
image: dtzar/helm-kubectl
script:
- kubectl config set-cluster "$KUBECTL_DEV_CLUSTER" --server="$KUBE_URL"
- kubectl config set-cluster "$KUBECTL_DEV_CLUSTER" --certificate-authority=$KUBE_CA_PEM_FILE --embed-certs=true
- kubectl config set-credentials gitlab --token="$KUBE_TOKEN"
- kubectl config set-context default --cluster="$KUBECTL_DEV_CLUSTER" --user=gitlab --namespace="$KUBE_NAMESPACE"
- kubectl config use-context default
- kubectl apply -f k8s/
environment:
name: stg
url: http://qed.qed-stage.aws.epa.gov
kubernetes:
namespace: qed-45-stg
DeleteManifests:
stage: Deployment
tags:
- qed-stg-runner
when: manual
image: dtzar/helm-kubectl
script:
- kubectl config set-cluster "$KUBECTL_DEV_CLUSTER" --server="$KUBE_URL"
- kubectl config set-cluster "$KUBECTL_DEV_CLUSTER" --certificate-authority=$KUBE_CA_PEM_FILE --embed-certs=true
- kubectl config set-credentials gitlab --token="$KUBE_TOKEN"
- kubectl config set-context default --cluster="$KUBECTL_DEV_CLUSTER" --user=gitlab --namespace="$KUBE_NAMESPACE"
- kubectl config use-context default
- kubectl delete -f k8s/
environment:
name: stg
url: http://qed.qed-stage.aws.epa.gov
kubernetes:
namespace: qed-45-stg
ScaleDjango:
stage: Restart Pods
tags:
- qed-stg-runner
when: manual
image: dtzar/helm-kubectl
script:
- kubectl config set-cluster "$KUBECTL_DEV_CLUSTER" --server="$KUBE_URL"
- kubectl config set-cluster "$KUBECTL_DEV_CLUSTER" --certificate-authority=$KUBE_CA_PEM_FILE --embed-certs=true
- kubectl config set-credentials gitlab --token="$KUBE_TOKEN"
- kubectl config set-context default --cluster="$KUBECTL_DEV_CLUSTER" --user=gitlab --namespace="$KUBE_NAMESPACE"
- kubectl config use-context default
- kubectl scale deployment hms-django --replicas=0
- kubectl scale deployment hms-django --replicas=1
environment:
name: stg
url: http://qed.qed-stage.aws.epa.gov
kubernetes:
namespace: qed-45-stg
ScalePods:
stage: Restart Pods
tags:
- qed-stg-runner
when: manual
image: dtzar/helm-kubectl
script:
- kubectl config set-cluster "$KUBECTL_DEV_CLUSTER" --server="$KUBE_URL"
- kubectl config set-cluster "$KUBECTL_DEV_CLUSTER" --certificate-authority=$KUBE_CA_PEM_FILE --embed-certs=true
- kubectl config set-credentials gitlab --token="$KUBE_TOKEN"
- kubectl config set-context default --cluster="$KUBECTL_DEV_CLUSTER" --user=gitlab --namespace="$KUBE_NAMESPACE"
- kubectl config use-context default
- kubectl scale deployment hms-django --replicas=0
- kubectl scale deployment hms-django --replicas=1
- kubectl scale deployment hms-flask --replicas=0
- kubectl scale deployment hms-flask --replicas=1
- kubectl scale deployment hms-dask-worker --replicas=0
- kubectl scale deployment hms-dask-worker --replicas=3
- kubectl scale deployment hms-dotnet --replicas=0
- kubectl scale deployment hms-dotnet --replicas=1
- kubectl scale deployment hms-nginx --replicas=0
- kubectl scale deployment hms-nginx --replicas=1
environment:
name: stg
url: http://qed.qed-stage.aws.epa.gov
kubernetes:
namespace: qed-45-stg
DotNetImageScan:
stage: Image Scan
tags:
- twistcli
when: manual
variables:
GIT_STRATEGY: none
script:
- 'export PRISMA_CI_TOKEN=$(curl -kH "Content-Type: application/json" -d "{\"username\":\"$prisma_cloud_compute_username\", \"password\":\"$prisma_cloud_compute_password\"}" https://prismacloud.epa.gov/api/v32.01/authenticate | jq -r .token)'
- 'curl --progress-bar -L -k --header "Authorization: Bearer $PRISMA_CI_TOKEN" https://prismacloud.epa.gov/api/v1/util/twistcli > twistcli; chmod a+x twistcli;'
- docker login -u $CI_REGISTRY_USER -p $CI_REGISTRY_PASSWORD $CI_REGISTRY
- docker pull $CI_REGISTRY_IMAGE/hms_dotnet:$CI_COMMIT_REF_NAME
- ./twistcli images scan --address=https://prismacloud.epa.gov --details --token=$PRISMA_CI_TOKEN $CI_REGISTRY_IMAGE/hms_dotnet:$CI_COMMIT_REF_NAME
after_script:
- rm -rf $CI_PROJECT_DIR
DjangoImageScan:
stage: Image Scan
tags:
- twistcli
when: manual
variables:
GIT_STRATEGY: none
script:
- 'export PRISMA_CI_TOKEN=$(curl -kH "Content-Type: application/json" -d "{\"username\":\"$prisma_cloud_compute_username\", \"password\":\"$prisma_cloud_compute_password\"}" https://prismacloud.epa.gov/api/v32.01/authenticate | jq -r .token)'
- 'curl --progress-bar -L -k --header "Authorization: Bearer $PRISMA_CI_TOKEN" https://prismacloud.epa.gov/api/v1/util/twistcli > twistcli; chmod a+x twistcli;'
- docker login -u $CI_REGISTRY_USER -p $CI_REGISTRY_PASSWORD $CI_REGISTRY
- docker pull $CI_REGISTRY_IMAGE/hms_django:$CI_COMMIT_REF_NAME
- ./twistcli images scan --address=https://prismacloud.epa.gov --details --token=$PRISMA_CI_TOKEN $CI_REGISTRY_IMAGE/hms_django:$CI_COMMIT_REF_NAME
after_script:
- rm -rf $CI_PROJECT_DIR
FlaskImageScan:
stage: Image Scan
tags:
- twistcli
when: manual
variables:
GIT_STRATEGY: none
script:
- 'export PRISMA_CI_TOKEN=$(curl -kH "Content-Type: application/json" -d "{\"username\":\"$prisma_cloud_compute_username\", \"password\":\"$prisma_cloud_compute_password\"}" https://prismacloud.epa.gov/api/v32.01/authenticate | jq -r .token)'
- 'curl --progress-bar -L -k --header "Authorization: Bearer $PRISMA_CI_TOKEN" https://prismacloud.epa.gov/api/v1/util/twistcli > twistcli; chmod a+x twistcli;'
- docker login -u $CI_REGISTRY_USER -p $CI_REGISTRY_PASSWORD $CI_REGISTRY
- docker pull $CI_REGISTRY_IMAGE/hms_flask:$CI_COMMIT_REF_NAME
- ./twistcli images scan --address=https://prismacloud.epa.gov --details --token=$PRISMA_CI_TOKEN $CI_REGISTRY_IMAGE/hms_flask:$CI_COMMIT_REF_NAME
after_script:
- rm -rf $CI_PROJECT_DIR
DaskImageScan:
stage: Image Scan
tags:
- twistcli
when: manual
variables:
GIT_STRATEGY: none
script:
- 'export PRISMA_CI_TOKEN=$(curl -kH "Content-Type: application/json" -d "{\"username\":\"$prisma_cloud_compute_username\", \"password\":\"$prisma_cloud_compute_password\"}" https://prismacloud.epa.gov/api/v32.01/authenticate | jq -r .token)'
- 'curl --progress-bar -L -k --header "Authorization: Bearer $PRISMA_CI_TOKEN" https://prismacloud.epa.gov/api/v1/util/twistcli > twistcli; chmod a+x twistcli;'
- docker login -u $CI_REGISTRY_USER -p $CI_REGISTRY_PASSWORD $CI_REGISTRY
- docker pull $CI_REGISTRY_IMAGE/hms_dask:$CI_COMMIT_REF_NAME
- ./twistcli images scan --address=https://prismacloud.epa.gov --details --token=$PRISMA_CI_TOKEN $CI_REGISTRY_IMAGE/hms_dask:$CI_COMMIT_REF_NAME
after_script:
- rm -rf $CI_PROJECT_DIR
NginxImageScan:
stage: Image Scan
tags:
- twistcli
when: manual
variables:
GIT_STRATEGY: none
script:
- 'export PRISMA_CI_TOKEN=$(curl -kH "Content-Type: application/json" -d "{\"username\":\"$prisma_cloud_compute_username\", \"password\":\"$prisma_cloud_compute_password\"}" https://prismacloud.epa.gov/api/v32.01/authenticate | jq -r .token)'
- 'curl --progress-bar -L -k --header "Authorization: Bearer $PRISMA_CI_TOKEN" https://prismacloud.epa.gov/api/v1/util/twistcli > twistcli; chmod a+x twistcli;'
- docker login -u $CI_REGISTRY_USER -p $CI_REGISTRY_PASSWORD $CI_REGISTRY
- docker pull $CI_REGISTRY_IMAGE/hms_nginx:$CI_COMMIT_REF_NAME
- ./twistcli images scan --address=https://prismacloud.epa.gov --details --token=$PRISMA_CI_TOKEN $CI_REGISTRY_IMAGE/hms_nginx:$CI_COMMIT_REF_NAME
after_script:
- rm -rf $CI_PROJECT_DIR
MongoImageScan:
stage: Image Scan
tags:
- twistcli
when: manual
variables:
GIT_STRATEGY: none
script:
- 'export PRISMA_CI_TOKEN=$(curl -kH "Content-Type: application/json" -d "{\"username\":\"$prisma_cloud_compute_username\", \"password\":\"$prisma_cloud_compute_password\"}" https://prismacloud.epa.gov/api/v32.01/authenticate | jq -r .token)'
- 'curl --progress-bar -L -k --header "Authorization: Bearer $PRISMA_CI_TOKEN" https://prismacloud.epa.gov/api/v1/util/twistcli > twistcli; chmod a+x twistcli;'
- docker login -u $CI_REGISTRY_USER -p $CI_REGISTRY_PASSWORD $CI_REGISTRY
- docker pull $CI_REGISTRY_IMAGE/hms_mongo:$CI_COMMIT_REF_NAME
- ./twistcli images scan --address=https://prismacloud.epa.gov --details --token=$PRISMA_CI_TOKEN $CI_REGISTRY_IMAGE/hms_mongo:$CI_COMMIT_REF_NAME
after_script:
- rm -rf $CI_PROJECT_DIR