-
Notifications
You must be signed in to change notification settings - Fork 6.8k
292 lines (276 loc) · 10.4 KB
/
Copy pathcomponent-build-images.yml
File metadata and controls
292 lines (276 loc) · 10.4 KB
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
# Copyright The OpenTelemetry Authors
# SPDX-License-Identifier: Apache-2.0
name: Component build images
on:
workflow_call:
inputs:
push:
description: Should the images be pushed
default: false
required: false
type: boolean
force_build:
description: Build all images regardless of detected changes
default: false
required: false
type: boolean
version:
description: The version used when tagging the image
default: 'dev'
required: false
type: string
dockerhub_repo:
description: Docker Hub repository
default: 'otel/demo'
required: false
type: string
ghcr_repo:
description: GHCR repository
default: 'ghcr.io/open-telemetry/demo'
required: false
type: string
secrets:
DOCKER_USERNAME:
required: false
DOCKER_PASSWORD:
required: false
permissions:
contents: read
jobs:
protobufcheck:
name: Check protobuf generated files
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7.0.0
with:
persist-credentials: false
- name: Generate
run: make clean docker-generate-protobuf
- name: Check clean work tree
run: make check-clean-work-tree
build_and_push_images:
name: Build and push ${{ matrix.file_tag.tag_suffix }} image
runs-on: ubuntu-latest
needs: protobufcheck
permissions:
contents: read # required to read Dockerfiles and source files
packages: write # required to push built images to GHCR
env:
RELEASE_VERSION: "${{ github.event.release.tag_name }}"
strategy:
fail-fast: false
matrix:
file_tag:
- file: ./src/accounting/Dockerfile
tag_suffix: accounting
context: ./
setup-qemu: true
- file: ./src/ad/Dockerfile
tag_suffix: ad
context: ./
setup-qemu: true
- file: ./src/cart/src/Dockerfile
tag_suffix: cart
context: ./
setup-qemu: false
- file: ./src/checkout/Dockerfile
tag_suffix: checkout
context: ./
setup-qemu: true
- file: ./src/currency/Dockerfile
tag_suffix: currency
context: ./
setup-qemu: true
- file: ./src/email/Dockerfile
tag_suffix: email
context: ./
setup-qemu: true
- file: ./src/flagd-ui/Dockerfile
tag_suffix: flagd-ui
context: ./
setup-qemu: true
- file: ./src/fraud-detection/Dockerfile
tag_suffix: fraud-detection
context: ./
setup-qemu: true
- file: ./src/frontend/Dockerfile
tag_suffix: frontend
context: ./
setup-qemu: true
- file: ./src/frontend-proxy/Dockerfile
tag_suffix: frontend-proxy
context: ./
setup-qemu: true
- file: ./src/frontend/Dockerfile.cypress
tag_suffix: frontend-tests
context: ./
setup-qemu: true
- file: ./src/image-provider/Dockerfile
tag_suffix: image-provider
context: ./
setup-qemu: true
- file: ./src/kafka/Dockerfile
tag_suffix: kafka
context: ./
setup-qemu: true
- file: ./src/load-generator/Dockerfile
tag_suffix: load-generator
context: ./
setup-qemu: true
- file: ./src/opensearch/Dockerfile
tag_suffix: opensearch
context: ./
setup-qemu: true
- file: ./src/payment/Dockerfile
tag_suffix: payment
context: ./
setup-qemu: true
- file: ./src/product-catalog/Dockerfile
tag_suffix: product-catalog
context: ./
setup-qemu: true
- file: ./src/quote/Dockerfile
tag_suffix: quote
context: ./
setup-qemu: true
- file: ./src/recommendation/Dockerfile
tag_suffix: recommendation
context: ./
setup-qemu: true
- file: ./src/shipping/Dockerfile
tag_suffix: shipping
context: ./
setup-qemu: true
- file: ./src/telemetry-docs/Dockerfile
tag_suffix: telemetry-docs
context: ./
setup-qemu: true
steps:
- name: Checkout code
uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7.0.0
with:
fetch-depth: 0
persist-credentials: false
- name: Load environment variables from .env file
run: |
if [ -f .env ]; then
# Filter out comments and empty lines, then add each variable to $GITHUB_ENV
grep -vE '^\s*#|^\s*$' .env | while read -r line; do
echo "$line" >> $GITHUB_ENV
done
else
echo ".env file not found!"
exit 1
fi
- name: Check for changes and set push options
id: check_changes
env:
BASE_SHA: ${{ github.event.pull_request.base.sha || github.event.merge_group.base_sha || github.event.before }}
DEFAULT_BRANCH: ${{ github.event.repository.default_branch }}
DOCKER_CONTEXT: ${{ matrix.file_tag.context }}
DOCKERFILE: ${{ matrix.file_tag.file }}
FORCE_BUILD: ${{ inputs.force_build }}
HEAD_SHA: ${{ github.event.merge_group.head_sha || github.sha }}
run: |
DOCKERFILE_DIR=$(dirname "${DOCKERFILE}")
ZERO_SHA=0000000000000000000000000000000000000000
commit_exists() {
[ -n "$1" ] && [ "$1" != "$ZERO_SHA" ] && git cat-file -e "${1}^{commit}" 2>/dev/null
}
use_default_branch_merge_base() {
echo "Using merge base with ${DEFAULT_BRANCH}."
git fetch --no-tags origin "${DEFAULT_BRANCH}" || true
BASE_SHA=$(git merge-base "$HEAD_SHA" "origin/${DEFAULT_BRANCH}" || true)
}
if [ "$FORCE_BUILD" = true ]; then
echo "Force build is enabled, proceeding with build."
echo "skip=false" >> "$GITHUB_OUTPUT"
exit 0
fi
if ! commit_exists "$HEAD_SHA"; then
echo "Head SHA ${HEAD_SHA} is unavailable, using checked out HEAD."
HEAD_SHA=$(git rev-parse HEAD)
fi
case "${GITHUB_EVENT_NAME}" in
pull_request|merge_group)
if ! commit_exists "$BASE_SHA"; then
echo "Base SHA unavailable for ${GITHUB_EVENT_NAME}."
use_default_branch_merge_base
fi
;;
push)
if [ "${GITHUB_REF_NAME}" = "${DEFAULT_BRANCH}" ]; then
if ! commit_exists "$BASE_SHA"; then
echo "No usable base SHA available for default branch push, proceeding with build."
echo "skip=false" >> "$GITHUB_OUTPUT"
exit 0
fi
else
use_default_branch_merge_base
fi
;;
*)
if ! commit_exists "$BASE_SHA"; then
echo "No usable base SHA available for ${GITHUB_EVENT_NAME}, proceeding with build."
echo "skip=false" >> "$GITHUB_OUTPUT"
exit 0
fi
;;
esac
if ! commit_exists "$BASE_SHA"; then
echo "No usable base SHA available, proceeding with build."
echo "skip=false" >> "$GITHUB_OUTPUT"
exit 0
fi
FILES_CHANGED=$(git diff --name-only "$BASE_SHA" "$HEAD_SHA" -- "$DOCKERFILE_DIR")
if [ -z "$FILES_CHANGED" ]; then
echo "No changes in ${DOCKERFILE_DIR}, skipping build for ${DOCKERFILE}."
echo "skip=true" >> "$GITHUB_OUTPUT"
else
echo "Changes detected in ${DOCKERFILE_DIR}, proceeding with build for ${DOCKERFILE}."
echo "skip=false" >> "$GITHUB_OUTPUT"
fi
- name: Log in to container registry
uses: docker/login-action@650006c6eb7dba73a995cc03b0b2d7f5ca915bee # v4.2.0
with:
registry: ghcr.io
username: ${{ github.repository_owner }}
password: ${{ github.token }}
if: ${{ steps.check_changes.outputs.skip == 'false' && inputs.push && !github.event.repository.fork }}
- name: Log in to Docker Hub
uses: docker/login-action@650006c6eb7dba73a995cc03b0b2d7f5ca915bee # v4.2.0
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}
if: ${{ steps.check_changes.outputs.skip == 'false' && inputs.push && !github.event.repository.fork }}
- name: Set up QEMU
if: ${{ steps.check_changes.outputs.skip == 'false' && matrix.file_tag.setup-qemu }}
uses: docker/setup-qemu-action@06116385d9baf250c9f4dcb4858b16962ea869c3 # v4.1.0
with:
image: tonistiigi/binfmt:master
- name: Set up Docker Buildx
if: steps.check_changes.outputs.skip == 'false'
uses: docker/setup-buildx-action@d7f5e7f509e45cec5c76c4d5afdd7de93d0b3df5 # v4.1.0
with:
buildkitd-config-inline: |
[worker.oci]
max-parallelism = 2
- name: Build and push demo images
if: steps.check_changes.outputs.skip == 'false'
uses: docker/build-push-action@f9f3042f7e2789586610d6e8b85c8f03e5195baf # v7.2.0
with:
context: ${{ matrix.file_tag.context }}
file: ${{ matrix.file_tag.file }}
platforms: linux/amd64,linux/arm64
push: ${{ inputs.push && !github.event.repository.fork }}
build-args: |
OTEL_JAVA_AGENT_VERSION=${{ env.OTEL_JAVA_AGENT_VERSION }}
OPENTELEMETRY_CPP_VERSION=${{ env.OPENTELEMETRY_CPP_VERSION }}
tags: |
${{ inputs.dockerhub_repo }}:${{ inputs.version }}-${{matrix.file_tag.tag_suffix }}
${{ inputs.dockerhub_repo }}:latest-${{matrix.file_tag.tag_suffix }}
${{ inputs.ghcr_repo }}:${{ inputs.version }}-${{ matrix.file_tag.tag_suffix }}
${{ inputs.ghcr_repo }}:latest-${{ matrix.file_tag.tag_suffix }}
cache-from: type=gha
cache-to: type=gha