-
Notifications
You must be signed in to change notification settings - Fork 38
/
publish-docker-images-dry-run.yml
343 lines (336 loc) · 12.3 KB
/
publish-docker-images-dry-run.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
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
# This configuration has been automatically generated by the CircleCI Config SDK.
# For more information, see https://github.com/CircleCI-Public/circleci-config-sdk-ts
# SDK Version: 0.0.0-development
version: 2.1
setup: false
parameters:
gio_action:
type: string
default: pull_requests
description: ""
dry_run:
type: boolean
default: true
description: Run in dry run mode?
docker_tag_as_latest:
type: boolean
default: false
description: Is this version the latest version available?
graviteeio_version:
type: string
default: ""
description: Version of APIM to be used in docker images
apim_version_path:
type: string
default: /home/circleci/project/pom.xml
description: Path to pom.xml with APIM version
commands:
cmd-restore-maven-job-cache:
parameters:
jobName:
type: string
default: ""
description: The job name
steps:
- restore_cache:
keys:
- gravitee-api-management-v9-<< parameters.jobName >>-{{ .Branch }}-{{ checksum "pom.xml" }}
- gravitee-api-management-v9-<< parameters.jobName >>-{{ .Branch }}
- gravitee-api-management-v9-<< parameters.jobName >>
description: Restore Maven cache for a dedicated job
cmd-save-maven-job-cache:
parameters:
jobName:
type: string
default: ""
description: The job name
steps:
- run:
name: Exclude all APIM artefacts from cache.
command: rm -rf ~/.m2/repository/io/gravitee/apim
- save_cache:
key: gravitee-api-management-v9-<< parameters.jobName >>-{{ .Branch }}-{{ checksum "pom.xml" }}
paths:
- ~/.m2
when: always
description: Save Maven cache for a dedicated job
cmd-notify-on-failure:
steps:
- keeper/env-export:
secret-url: keeper://ZOz4db245GNaETVwmPBk8w/field/password
var-name: SLACK_ACCESS_TOKEN
- slack/notify:
channel: C02JENTV2AX
branch_pattern: master,[0-9]+\.[0-9]+\.x
event: fail
template: basic_fail_1
cmd-create-docker-context:
steps:
- run:
name: Create docker context for buildx
command: |-
docker context create tls-env
docker buildx create tls-env --use
cmd-docker-azure-login:
steps:
- keeper/env-export:
secret-url: keeper://Q721P2LSOPJ9qiXLuf5AHQ/field/login
var-name: AZURE_DOCKER_REGISTRY_USERNAME
- keeper/env-export:
secret-url: keeper://Q721P2LSOPJ9qiXLuf5AHQ/field/password
var-name: AZURE_DOCKER_REGISTRY_PASSWORD
- run:
name: Login to Azure Container Registry
command: echo $AZURE_DOCKER_REGISTRY_PASSWORD | docker login --username $AZURE_DOCKER_REGISTRY_USERNAME --password-stdin graviteeio.azurecr.io
description: Login to Azure Container Registry
cmd-docker-azure-logout:
steps:
- run:
name: Logout from Azure Container Registry
command: docker logout graviteeio.azurecr.io
description: Logout from Azure Container Registry
cmd-webui-install:
parameters:
apim-ui-project:
type: string
default: ""
description: the name of the UI project to build
steps:
- restore_cache:
name: Restore NPM cache
keys:
- << parameters.apim-ui-project >>-cache-v1-{{ .Branch }}-{{ checksum "<< parameters.apim-ui-project >>/package-lock.json" }}
- << parameters.apim-ui-project >>-cache-v1-{{ .Branch }}
- run:
name: Install dependencies
command: npm install
working_directory: << parameters.apim-ui-project >>
- save_cache:
name: Save NPM cache
key: << parameters.apim-ui-project >>-cache-v1-{{ .Branch }}-{{ checksum "<< parameters.apim-ui-project >>/package-lock.json" }}
paths:
- ./<< parameters.apim-ui-project >>/node_modules
cmd-build-ui-image:
parameters:
docker-image-name:
type: string
default: ""
description: the name of the image
apim-ui-project:
type: string
default: ""
description: the name of the UI project to build
steps:
- cmd-create-docker-context
- cmd-docker-azure-login
- run:
name: Build UI docker image
command: |-
docker buildx build --push --platform=linux/arm64,linux/amd64 -f docker/Dockerfile \
-t graviteeio.azurecr.io/<< parameters.docker-image-name >>:apim-1234-branch-name-latest \
.
working_directory: << parameters.apim-ui-project >>
- cmd-docker-azure-logout
jobs:
job-setup:
docker:
- image: cimg/base:stable
resource_class: small
steps:
- checkout
- keeper/env-export:
secret-url: keeper://7CgijuGiFDSLynRJt1Dm9w/custom_field/xml
var-name: MAVEN_SETTINGS
- run:
command: "echo $MAVEN_SETTINGS > .gravitee.settings.xml "
- persist_to_workspace:
root: .
paths:
- .gravitee.settings.xml
job-build:
docker:
- image: cimg/openjdk:17.0.8
resource_class: large
steps:
- checkout
- attach_workspace:
at: .
- cmd-restore-maven-job-cache:
jobName: job-build
- run:
name: Build project
command: |-
mvn -s .gravitee.settings.xml clean install --no-transfer-progress --update-snapshots -DskipTests -Dskip.validation=true -T 2C -Dbundle=dev
mkdir -p ./rest-api-docker-context/distribution && cp -r ./gravitee-apim-rest-api/gravitee-apim-rest-api-standalone/gravitee-apim-rest-api-standalone-distribution/target/distribution ./rest-api-docker-context/.
mkdir -p ./gateway-docker-context/distribution && cp -r ./gravitee-apim-gateway/gravitee-apim-gateway-standalone/gravitee-apim-gateway-standalone-distribution/target/distribution ./gateway-docker-context/.
environment:
BUILD_ID: "1234"
BUILD_NUMBER: "1234"
GIT_COMMIT: 784ff35ca
- cmd-notify-on-failure
- save_cache:
paths:
- ~/.m2/repository/io/gravitee/apim
key: gravitee-api-management-v9-build-apim-{{ .Environment.CIRCLE_WORKFLOW_WORKSPACE_ID }}
when: on_success
- cmd-save-maven-job-cache:
jobName: job-build
- persist_to_workspace:
root: ./
paths:
- ./gravitee-apim-rest-api/gravitee-apim-rest-api-management/gravitee-apim-rest-api-management-rest/target/classes/console-openapi.*
- ./rest-api-docker-context
- ./gateway-docker-context
job-build-images:
docker:
- image: cimg/openjdk:17.0.8
resource_class: medium
steps:
- checkout
- attach_workspace:
at: .
- setup_remote_docker:
version: default
- cmd-create-docker-context
- cmd-docker-azure-login
- run:
name: Build rest api and gateway docker images
command: |-
docker buildx build --push --platform=linux/arm64,linux/amd64 -f gravitee-apim-rest-api/docker/Dockerfile \
-t graviteeio.azurecr.io/apim-management-api:apim-1234-branch-name-latest \
rest-api-docker-context
docker buildx build --push --platform=linux/arm64,linux/amd64 -f gravitee-apim-gateway/docker/Dockerfile \
-t graviteeio.azurecr.io/apim-gateway:apim-1234-branch-name-latest \
gateway-docker-context
- cmd-docker-azure-logout
job-webui-build:
parameters:
apim-ui-project:
type: string
default: ""
description: the name of the UI project to build
docker-image-name:
type: string
default: ""
description: the name of the image
node_version:
type: string
default: "20.11"
description: Node version to use for executor
docker:
- image: cimg/node:<< parameters.node_version >>
resource_class: large
steps:
- checkout
- attach_workspace:
at: .
- setup_remote_docker:
version: default
- cmd-webui-install:
apim-ui-project: << parameters.apim-ui-project >>
- run:
name: Update Build version
command: "sed -i 's/\"version\": \".*\"/\"version\": \"4.2.0\"/' << parameters.apim-ui-project >>/build.json"
- run:
name: Build
command: npm run build:prod
environment:
NODE_OPTIONS: --max_old_space_size=4086
working_directory: << parameters.apim-ui-project >>
- cmd-build-ui-image:
docker-image-name: << parameters.docker-image-name >>
apim-ui-project: << parameters.apim-ui-project >>
- cmd-notify-on-failure
- persist_to_workspace:
root: .
paths:
- << parameters.apim-ui-project >>/dist
job-publish-pr-env-urls:
docker:
- image: cimg/node:16.13
resource_class: small
steps:
- checkout
- attach_workspace:
at: .
- keeper/env-export:
secret-url: keeper://TIlcGPFq4rN5GvgnZb9hng/field/password
var-name: GITHUB_TOKEN
- gh/setup
- run:
name: Edit Pull Request Description
command: |-
# First check there is an associated pull request, otherwise just stop the job here
if ! gh pr view --json title;
then
echo "No PR found for this branch, stopping the job here."
exit 0
fi
# If PR state is different from OPEN
if [ "$(gh pr view --json state --jq .state)" != "OPEN" ];
then
echo "PR is not opened, stopping the job here."
exit 0
fi
export PR_NUMBER=$(gh pr view --json number --jq .number)
export PR_BODY_ENV_SECTION="
<!-- Environment placeholder -->
🏗️ Your changes can be tested here and will be available soon:
Console: [https://pr.team-apim.gravitee.dev/$PR_NUMBER/console](https://pr.team-apim.gravitee.dev/$PR_NUMBER/console)
Portal: [https://pr.team-apim.gravitee.dev/$PR_NUMBER/portal](https://pr.team-apim.gravitee.dev/$PR_NUMBER/portal)
Management-api: [https://pr.team-apim.gravitee.dev/$PR_NUMBER/api/management](https://pr.team-apim.gravitee.dev/$PR_NUMBER/api/management)
Gateway v4: [https://pr.team-apim.gravitee.dev/$PR_NUMBER](https://pr.team-apim.gravitee.dev/$PR_NUMBER)
Gateway v3: [https://pr.gateway-v3.team-apim.gravitee.dev/$PR_NUMBER](https://pr.gateway-v3.team-apim.gravitee.dev/$PR_NUMBER)
<!-- Environment placeholder end -->
"
export CLEAN_BODY=$(gh pr view --json body --jq .body | sed '/Environment placeholder -->/,/Environment placeholder end -->/d')
gh pr edit --body "$CLEAN_BODY$PR_BODY_ENV_SECTION"
- cmd-notify-on-failure
workflows:
publish_docker_images:
jobs:
- job-setup:
context:
- cicd-orchestrator
name: Setup
- job-build:
context:
- cicd-orchestrator
requires:
- Setup
name: Build backend
- job-build-images:
context:
- cicd-orchestrator
requires:
- Build backend
name: Build and push rest api and gateway images
- job-webui-build:
context:
- cicd-orchestrator
requires:
- Setup
name: Build APIM Console and publish image
apim-ui-project: gravitee-apim-console-webui
docker-image-name: apim-management-ui
- job-webui-build:
context:
- cicd-orchestrator
requires:
- Setup
name: Build APIM Portal and publish image
apim-ui-project: gravitee-apim-portal-webui
docker-image-name: apim-portal-ui
node_version: "20.9"
- job-publish-pr-env-urls:
name: Publish environment URLs in Github PR
context:
- cicd-orchestrator
requires:
- Build and push rest api and gateway images
- Build APIM Console and publish image
- Build APIM Portal and publish image
orbs:
keeper: gravitee-io/keeper@0.6.3
slack: circleci/slack@4.12.5
gh: circleci/github-cli@1.0.5