-
Notifications
You must be signed in to change notification settings - Fork 512
232 lines (200 loc) · 9.05 KB
/
docker-ecs-worker-image.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
name: Build & publish ECS/Fargate worker image to ECR
on:
workflow_dispatch:
inputs:
SHOULD_BUILD_ARM64:
description: 'Whether to build the ARM64 image.'
type: boolean
default: false
workflow_call:
inputs:
COMMIT_SHA:
description: 'Branch ref to checkout. Needed for pull_request_target to be able to pull correct ref.'
type: string
required: true
USE_COMMIT_SHA_IN_VERSION:
description: 'Whether to use the commit sha in building the pkg version of the image.'
type: boolean
SHOULD_BUILD_ARM64:
description: 'Whether to build the ARM64 image.'
type: boolean
default: false
secrets:
ECR_WORKER_IMAGE_PUSH_ROLE_ARN:
description: 'ARN of the IAM role to assume to push the image to ECR.'
required: true
permissions:
id-token: write
contents: read
jobs:
build_docker_image_amd64:
runs-on: ubuntu-latest
env:
# Set by the caller workflow, defaults to github.sha when not passed (e.g. workflow_dispatch against a branch)
WORKER_VERSION: ${{ inputs.COMMIT_SHA || github.sha }}
strategy:
matrix:
registry: [ public, private ]
steps:
- uses: actions/checkout@v3
with:
ref: ${{ env.WORKER_VERSION }}
fetch-depth: 0
- name: Set up QEMU
uses: docker/setup-qemu-action@v2
- name: Replace package version
if: ${{ inputs.USE_COMMIT_SHA_IN_VERSION || false }}
run: node .github/workflows/scripts/replace-package-versions.js
env:
COMMIT_SHA: ${{ env.WORKER_VERSION }}
REPLACE_MAIN_VERSION_ONLY: true # we don't need to replace dependencies, as docker image builds using workspaces
- name: Get Artillery version
# we only want to tag with an actual version from pkg.json outside of PRs and manual dispatches
# NOTE: can't check for refs/head/main because of pull_request_target used in some workflows
if: github.event.pull_request == null && github.event_name != 'workflow_dispatch'
run: |
echo "WORKER_VERSION=$(node -e 'console.log(require("./packages/artillery/package.json").version)')" >> $GITHUB_ENV
- name: Show git ref
run: |
echo GITHUB REF ${{ github.ref }}
echo GITHUB PR HEAD SHA ${{ github.event.pull_request.head.sha }}
echo GITHUB SHA ${{ github.sha }}
echo WORKER_VERSION ENV ${{ env.WORKER_VERSION }}
- name: Configure AWS Credentials (Public ECR)
if: matrix.registry == 'public'
uses: aws-actions/configure-aws-credentials@v1
with:
aws-region: us-east-1
audience: sts.amazonaws.com
role-to-assume: ${{ secrets.ECR_WORKER_IMAGE_PUSH_ROLE_ARN }}
role-session-name: OIDCSession
mask-aws-account-id: true
- name: Login to Amazon (Public ECR)
if: matrix.registry == 'public'
id: login-ecr-public
uses: aws-actions/amazon-ecr-login@v1
with:
registry-type: public
- name: Build the Docker image (Public ECR)
if: matrix.registry == 'public'
env:
DOCKER_TAG: ${{ env.WORKER_VERSION }}-x86_64
run: |
docker build . --platform linux/amd64 --build-arg="WORKER_VERSION=${{ env.WORKER_VERSION }}" --tag public.ecr.aws/d8a4z9o5/artillery-worker:${{ env.DOCKER_TAG }} -f ./packages/artillery/lib/platform/aws-ecs/worker/Dockerfile
- name: Push Docker image (Public ECR)
if: matrix.registry == 'public'
env:
DOCKER_TAG: ${{ env.WORKER_VERSION }}-x86_64
run: |
docker push public.ecr.aws/d8a4z9o5/artillery-worker:${{ env.DOCKER_TAG }}
- name: Configure AWS Credentials (Private ECR)
if: matrix.registry == 'private'
uses: aws-actions/configure-aws-credentials@v1
with:
aws-region: eu-west-1
audience: sts.amazonaws.com
role-to-assume: ${{ secrets.ECR_WORKER_IMAGE_PUSH_ROLE_ARN }}
role-session-name: OIDCSession
mask-aws-account-id: true
- name: Login to Amazon (Private ECR)
if: matrix.registry == 'private'
id: login-ecr-private
uses: aws-actions/amazon-ecr-login@v1
- name: Build the Docker image (Private ECR)
if: matrix.registry == 'private'
env:
DOCKER_TAG: ${{ env.WORKER_VERSION }}-x86_64
run: |
docker build . --platform linux/amd64 --build-arg="WORKER_VERSION=${{ env.WORKER_VERSION }}" --tag 248481025674.dkr.ecr.eu-west-1.amazonaws.com/artillery-worker:${{ env.DOCKER_TAG }} -f ./packages/artillery/lib/platform/aws-ecs/worker/Dockerfile
- name: Push Docker image (Private ECR)
if: matrix.registry == 'private'
env:
DOCKER_TAG: ${{ env.WORKER_VERSION }}-x86_64
run: |
docker push 248481025674.dkr.ecr.eu-west-1.amazonaws.com/artillery-worker:${{ env.DOCKER_TAG }}
build_docker_image_arm64:
runs-on: ubuntu-latest
if: ${{ inputs.SHOULD_BUILD_ARM64 }}
env:
# Set by the caller workflow, defaults to github.sha when not passed (e.g. workflow_dispatch against a branch)
WORKER_VERSION: ${{ inputs.COMMIT_SHA || github.sha }}
strategy:
matrix:
registry: [ public, private ]
steps:
- uses: actions/checkout@v3
with:
ref: ${{ env.WORKER_VERSION }}
fetch-depth: 0
- name: Set up QEMU
uses: docker/setup-qemu-action@v2
- name: Replace package version
if: ${{ inputs.USE_COMMIT_SHA_IN_VERSION || false }}
run: node .github/workflows/scripts/replace-package-versions.js
env:
COMMIT_SHA: ${{ env.WORKER_VERSION }}
REPLACE_MAIN_VERSION_ONLY: true # we don't need to replace dependencies, as docker image builds using workspaces
- name: Get Artillery version
# we only want to tag with an actual version from pkg.json outside of PRs and manual dispatches
# NOTE: can't check for refs/head/main because of pull_request_target used in some workflows
if: github.event.pull_request == null && github.event_name != 'workflow_dispatch'
run: |
echo "WORKER_VERSION=$(node -e 'console.log(require("./packages/artillery/package.json").version)')" >> $GITHUB_ENV
- name: Show git ref
run: |
echo GITHUB REF ${{ github.ref }}
echo GITHUB PR HEAD SHA ${{ github.event.pull_request.head.sha }}
echo GITHUB SHA ${{ github.sha }}
echo WORKER_VERSION ENV ${{ env.WORKER_VERSION }}
- name: Configure AWS Credentials (Public ECR)
if: matrix.registry == 'public'
uses: aws-actions/configure-aws-credentials@v1
with:
aws-region: us-east-1
audience: sts.amazonaws.com
role-to-assume: ${{ secrets.ECR_WORKER_IMAGE_PUSH_ROLE_ARN }}
role-session-name: OIDCSession
mask-aws-account-id: true
- name: Login to Amazon (Public ECR)
if: matrix.registry == 'public'
id: login-ecr-public
uses: aws-actions/amazon-ecr-login@v1
with:
registry-type: public
- name: Build the Docker image (Public ECR)
if: matrix.registry == 'public'
env:
DOCKER_TAG: ${{ env.WORKER_VERSION }}-arm64
run: |
docker build . --platform linux/arm64 --build-arg="WORKER_VERSION=${{ env.WORKER_VERSION }}" --tag public.ecr.aws/d8a4z9o5/artillery-worker:${{ env.DOCKER_TAG }} -f ./packages/artillery/lib/platform/aws-ecs/worker/Dockerfile
- name: Push Docker image (Public ECR)
if: matrix.registry == 'public'
env:
DOCKER_TAG: ${{ env.WORKER_VERSION }}-arm64
run: |
docker push public.ecr.aws/d8a4z9o5/artillery-worker:${{ env.DOCKER_TAG }}
- name: Configure AWS Credentials (Private ECR)
if: matrix.registry == 'private'
uses: aws-actions/configure-aws-credentials@v1
with:
aws-region: eu-west-1
audience: sts.amazonaws.com
role-to-assume: ${{ secrets.ECR_WORKER_IMAGE_PUSH_ROLE_ARN }}
role-session-name: OIDCSession
mask-aws-account-id: true
- name: Login to Amazon (Private ECR)
if: matrix.registry == 'private'
id: login-ecr-private
uses: aws-actions/amazon-ecr-login@v1
- name: Build the Docker image (Private ECR)
if: matrix.registry == 'private'
env:
DOCKER_TAG: ${{ env.WORKER_VERSION }}-arm64
run: |
docker build . --platform linux/arm64 --build-arg="WORKER_VERSION=${{ env.WORKER_VERSION }}" --tag 248481025674.dkr.ecr.eu-west-1.amazonaws.com/artillery-worker:${{ env.DOCKER_TAG }} -f ./packages/artillery/lib/platform/aws-ecs/worker/Dockerfile
- name: Push Docker image (Private ECR)
if: matrix.registry == 'private'
env:
DOCKER_TAG: ${{ env.WORKER_VERSION }}-arm64
run: |
docker push 248481025674.dkr.ecr.eu-west-1.amazonaws.com/artillery-worker:${{ env.DOCKER_TAG }}