forked from rudderlabs/rudder-transformer
-
Notifications
You must be signed in to change notification settings - Fork 0
229 lines (207 loc) · 7.2 KB
/
build-push-docker-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
name: Build Transformer Docker Image
on:
workflow_call:
inputs:
build_tag:
required: true
type: string
push_tags:
required: true
type: string
img_tag:
required: true
type: string
dockerfile:
required: true
type: string
load_target:
required: true
type: string
push_target:
required: true
type: string
build_type:
type: string
use_merge_sha:
type: boolean
default: false
skip_tests:
type: boolean
default: false
description: if this option is true, we would skip tests while building docker image
workflow_url:
type: string
secrets:
DOCKERHUB_PROD_TOKEN:
required: true
DOCKERHUB_USERNAME:
required: true
DOCKERHUB_TOKEN:
required: true
env:
DOCKERHUB_PROD_TOKEN: ${{ secrets.DOCKERHUB_PROD_TOKEN }}
DOCKERHUB_USERNAME: ${{ secrets.DOCKERHUB_USERNAME }}
jobs:
get_sha:
runs-on: ubuntu-latest
name: Get SHA information
outputs:
sha: ${{steps.getSHA.outputs.SHA}}
steps:
- name: Checkout SHA
id: getSHA
run: |
if ${{inputs.use_merge_sha}} == true; then
sha=$(echo ${{github.sha}})
else
sha=$(echo ${{ github.event.pull_request.head.sha }})
fi
echo "SHA: $sha"
echo "SHA=$sha" >> $GITHUB_OUTPUT
get_changed_files:
runs-on: ubuntu-latest
name: Get Changed files
outputs:
should_execute_tests: ${{ steps.processing.outputs.should_execute_tests }}
steps:
- name: Checkout
uses: actions/checkout@v4.2.1
with:
fetch-depth: 1
- id: files
uses: Ana06/get-changed-files@v1.2
with:
token: ${{ secrets.GITHUB_TOKEN }}
format: 'json'
- id: processing
run: |
readarray -t modified_files <<<"$(jq -r '.[]' <<<'${{ steps.files.outputs.modified }}')"
echo "Modified files: $modified_files"
found=false
for modified_file in "${modified_files[@]}"; do
if [[ "$modified_file" == "Dockerfile" || "$modified_file" == "docker-compose.yml" || "$modified_file" == "Dockerfile" || "$modified_file" == "Dockerfile-ut-func" ]]; then
found=true
break
fi
done
echo "Match Found: $found"
echo "::set-output name=should_execute_tests::$found"
build-transformer-image-arm64:
name: Build Transformer Docker Image ARM64
runs-on: [self-hosted, Linux, ARM64]
needs: [get_sha, get_changed_files]
steps:
- name: Checkout
uses: actions/checkout@v4.2.1
with:
ref: ${{ needs.get_sha.outputs.sha }}
fetch-depth: 1
- name: Login to DockerHub
uses: docker/login-action@v3.3.0
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: Setup Docker Buildx
uses: docker/setup-buildx-action@v3.7.1
- name: Build Docker Image
uses: docker/build-push-action@v6.9.0
with:
context: .
file: ${{ inputs.dockerfile }}
target: ${{ inputs.load_target }}
load: true
tags: ${{ inputs.build_tag }}
# cache-from: type=gha
# cache-to: type=gha,mode=max
- name: Run Tests
if: ${{ inputs.skip_tests != true || needs.get_changed_files.outputs.should_execute_tests == true }}
run: |
docker run ${{ inputs.build_tag }} npm run test:js:ci
docker run ${{ inputs.build_tag }} npm run test:ts:ci
- name: Build and Push Multi-platform Images
uses: docker/build-push-action@v6.9.0
with:
context: .
file: ${{ inputs.dockerfile }}
target: ${{ inputs.push_target }}
push: true
tags: ${{ inputs.push_tags }}-arm64
platforms: |
linux/arm64
build-args: |
version=${{ inputs.img_tag }}-arm64
GIT_COMMIT_SHA=${{ github.sha }}
# cache-from: type=gha
# cache-to: type=gha,mode=max
build-transformer-image-amd64:
name: Build Transformer Docker Image AMD64
runs-on: [self-hosted, Linux, X64]
needs: [get_sha, get_changed_files]
steps:
- name: Checkout
uses: actions/checkout@v4.2.1
with:
ref: ${{ needs.get_sha.outputs.sha }}
fetch-depth: 1
- name: Login to DockerHub
uses: docker/login-action@v3.3.0
with:
username: ${{ env.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_PROD_TOKEN }}
- name: Setup Docker Buildx
uses: docker/setup-buildx-action@v3.7.1
- name: Build Docker Image
uses: docker/build-push-action@v6.9.0
with:
context: .
file: ${{ inputs.dockerfile }}
target: ${{ inputs.load_target }}
load: true
tags: ${{ inputs.build_tag }}
# cache-from: type=gha
# cache-to: type=gha,mode=max
- name: Run Tests
if: ${{ inputs.skip_tests != true || needs.get_changed_files.outputs.should_execute_tests == true }}
run: |
docker run ${{ inputs.build_tag }} npm run test:js:ci
docker run ${{ inputs.build_tag }} npm run test:ts:ci
- name: Build and Push Multi-platform Images
uses: docker/build-push-action@v6.9.0
with:
context: .
file: ${{ inputs.dockerfile }}
target: ${{ inputs.push_target }}
push: true
tags: ${{ inputs.push_tags }}-amd64
platforms: |
linux/amd64
build-args: |
version=${{ inputs.img_tag }}-amd64
GIT_COMMIT_SHA=${{ github.sha }}
# cache-from: type=gha
# cache-to: type=gha,mode=max
create-manifest:
name: Create multi-arch manifest
runs-on: ubuntu-latest
needs: [build-transformer-image-amd64, build-transformer-image-arm64]
steps:
- name: Login to DockerHub
uses: docker/login-action@v3.3.0
with:
username: ${{ env.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_PROD_TOKEN }}
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3.7.1
- name: Create multi-arch manifest
run: |
docker buildx imagetools create -t ${{ inputs.push_tags }} ${{ inputs.push_tags }}-amd64 ${{ inputs.push_tags }}-arm64
- name: Create latest multi-arch manifest
# To be triggered only for release/hotfix PR merges coming from `prepare-for-prod-dt-deploy.yaml`
if: ${{ inputs.build_type == 'dt' }}
run: |
docker buildx imagetools create -t rudderstack/rudder-transformer:latest ${{ inputs.push_tags }}-amd64 ${{ inputs.push_tags }}-arm64
- name: Create latest ut multi-arch manifest
# To be triggered only for release/hotfix PR merges coming from `prepare-for-prod-ut-deploy.yaml`
if: ${{ inputs.build_type == 'ut' }}
run: |
docker buildx imagetools create -t rudderstack/rudder-transformer:ut-latest ${{ inputs.push_tags }}-amd64 ${{ inputs.push_tags }}-arm64