Skip to content

Commit 379cf62

Browse files
chore(ci): reusable container image generation (open-telemetry#1581)
* ci: reusable container image generation * ci: parametrize container repositories name --------- Co-authored-by: Austin Parker <[email protected]>
1 parent b9c5d37 commit 379cf62

File tree

5 files changed

+183
-166
lines changed

5 files changed

+183
-166
lines changed

.github/workflows/build-images.yml

+3-163
Original file line numberDiff line numberDiff line change
@@ -1,174 +1,14 @@
11
# Copyright The OpenTelemetry Authors
22
# SPDX-License-Identifier: Apache-2.0
3+
name: Test image generation
34

45
on:
56
push:
67
paths:
78
- 'src/**'
89
- 'test/**'
9-
workflow_call:
10-
inputs:
11-
push:
12-
description: Should the images be pushed
13-
default: false
14-
required: false
15-
type: boolean
16-
version:
17-
description: The version used when tagging the image
18-
default: 'dev'
19-
required: false
20-
type: string
2110

2211
jobs:
23-
build_and_push_images:
12+
build_images:
2413
if: github.repository == 'open-telemetry/opentelemetry-demo'
25-
runs-on: ubuntu-latest
26-
permissions:
27-
contents: read
28-
packages: write
29-
30-
env:
31-
RELEASE_VERSION: "${{ github.event.release.tag_name }}"
32-
DOCKERHUB_REPO: "otel/demo"
33-
GHCR_REPO: "ghcr.io/open-telemetry/demo"
34-
35-
strategy:
36-
fail-fast: false
37-
matrix:
38-
file_tag:
39-
- file: ./src/accountingservice/Dockerfile
40-
tag_suffix: accountingservice
41-
context: ./
42-
setup-qemu: true
43-
- file: ./src/adservice/Dockerfile
44-
tag_suffix: adservice
45-
context: ./
46-
setup-qemu: true
47-
- file: ./src/cartservice/src/Dockerfile
48-
tag_suffix: cartservice
49-
context: ./
50-
setup-qemu: false
51-
- file: ./src/checkoutservice/Dockerfile
52-
tag_suffix: checkoutservice
53-
context: ./
54-
setup-qemu: true
55-
- file: ./src/currencyservice/Dockerfile
56-
tag_suffix: currencyservice
57-
context: ./
58-
setup-qemu: true
59-
- file: ./src/emailservice/Dockerfile
60-
tag_suffix: emailservice
61-
context: ./src/emailservice
62-
setup-qemu: true
63-
- file: ./src/frauddetectionservice/Dockerfile
64-
tag_suffix: frauddetectionservice
65-
context: ./
66-
setup-qemu: true
67-
- file: ./src/frontend/Dockerfile
68-
tag_suffix: frontend
69-
context: ./
70-
setup-qemu: true
71-
- file: ./src/frontendproxy/Dockerfile
72-
tag_suffix: frontendproxy
73-
context: ./
74-
setup-qemu: true
75-
- file: ./src/frontend/Dockerfile.cypress
76-
tag_suffix: frontend-tests
77-
context: ./
78-
setup-qemu: true
79-
- file: ./src/imageprovider/Dockerfile
80-
tag_suffix: imageprovider
81-
context: ./
82-
setup-qemu: true
83-
- file: ./src/kafka/Dockerfile
84-
tag_suffix: kafka
85-
context: ./
86-
setup-qemu: true
87-
- file: ./src/loadgenerator/Dockerfile
88-
tag_suffix: loadgenerator
89-
context: ./
90-
setup-qemu: true
91-
- file: ./src/paymentservice/Dockerfile
92-
tag_suffix: paymentservice
93-
context: ./
94-
setup-qemu: true
95-
- file: ./src/productcatalogservice/Dockerfile
96-
tag_suffix: productcatalogservice
97-
context: ./
98-
setup-qemu: true
99-
- file: ./src/quoteservice/Dockerfile
100-
tag_suffix: quoteservice
101-
context: ./
102-
setup-qemu: true
103-
- file: ./src/recommendationservice/Dockerfile
104-
tag_suffix: recommendationservice
105-
context: ./
106-
setup-qemu: true
107-
- file: ./src/shippingservice/Dockerfile
108-
tag_suffix: shippingservice
109-
context: ./
110-
setup-qemu: true
111-
- file: ./test/tracetesting/Dockerfile
112-
tag_suffix: traceBasedTests
113-
context: ./
114-
setup-qemu: true
115-
116-
steps:
117-
- uses: actions/checkout@v4
118-
with:
119-
fetch-depth: 0
120-
- name: Check for changes and set push options
121-
id: check_changes
122-
run: |
123-
DOCKERFILE_DIR=$(dirname ${{ matrix.file_tag.file }})
124-
FILES_CHANGED=$(git diff --name-only ${{ github.event.pull_request.base.sha }} ${{ github.sha }} -- $DOCKERFILE_DIR)
125-
FORCE_PUSH=${{ inputs.push }}
126-
if [ "$FORCE_PUSH" = true ]; then
127-
echo "Force push is enabled, proceeding with build."
128-
echo "skip=false" >> "$GITHUB_OUTPUT"
129-
elif [ -z "$FILES_CHANGED" ]; then
130-
echo "No changes in ${{ matrix.file_tag.context }}, skipping build."
131-
echo "skip=true" >> "$GITHUB_OUTPUT"
132-
else
133-
echo "Changes detected in ${{ matrix.file_tag.context }}, proceeding with build."
134-
echo "skip=false" >> "$GITHUB_OUTPUT"
135-
fi
136-
- name: Log in to the Container registry
137-
uses: docker/login-action@v3
138-
with:
139-
registry: ghcr.io
140-
username: ${{ github.repository_owner }}
141-
password: ${{ secrets.GITHUB_TOKEN }}
142-
if: ${{ inputs.push }}
143-
- name: Log in to Docker Hub
144-
uses: docker/login-action@v3
145-
with:
146-
username: ${{ secrets.DOCKER_USERNAME }}
147-
password: ${{ secrets.DOCKER_PASSWORD }}
148-
if: ${{ inputs.push }}
149-
- name: Set up QEMU
150-
if: ${{ matrix.file_tag.setup-qemu }}
151-
uses: docker/setup-qemu-action@v3
152-
with:
153-
image: tonistiigi/binfmt:master
154-
- name: Set up Docker Buildx
155-
uses: docker/setup-buildx-action@v3
156-
with:
157-
config-inline: |
158-
[worker.oci]
159-
max-parallelism = 2
160-
- name: Matrix Build and push demo images
161-
if: steps.check_changes.outputs.skip == 'false'
162-
uses: docker/[email protected]
163-
with:
164-
context: ${{ matrix.file_tag.context }}
165-
file: ${{ matrix.file_tag.file }}
166-
platforms: linux/amd64,linux/arm64
167-
push: ${{ inputs.push }}
168-
tags: |
169-
${{ env.DOCKERHUB_REPO }}:${{ inputs.version }}-${{matrix.file_tag.tag_suffix }}
170-
${{ env.DOCKERHUB_REPO }}:latest-${{matrix.file_tag.tag_suffix }}
171-
${{ env.GHCR_REPO }}:${{ inputs.version }}-${{ matrix.file_tag.tag_suffix }}
172-
${{ env.GHCR_REPO }}:latest-${{ matrix.file_tag.tag_suffix }}
173-
cache-from: type=gha
174-
cache-to: type=gha
14+
uses: ./.github/workflows/component_build_images.yml

.github/workflows/checks.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ on:
1111

1212
jobs:
1313
build_images:
14-
uses: ./.github/workflows/build-images.yml
14+
uses: ./.github/workflows/component_build-images.yml
1515
with:
1616
push: false
1717
version: 'dev'
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,177 @@
1+
# Copyright The OpenTelemetry Authors
2+
# SPDX-License-Identifier: Apache-2.0
3+
4+
on:
5+
workflow_call:
6+
inputs:
7+
push:
8+
description: Should the images be pushed
9+
default: false
10+
required: false
11+
type: boolean
12+
version:
13+
description: The version used when tagging the image
14+
default: 'dev'
15+
required: false
16+
type: string
17+
dockerhub_repo:
18+
description: Docker Hub repository
19+
default: 'otel/demo'
20+
required: false
21+
type: string
22+
ghcr_repo:
23+
description: GHCR repository
24+
default: 'ghcr.io/open-telemetry/demo'
25+
required: false
26+
type: string
27+
28+
jobs:
29+
build_and_push_images:
30+
runs-on: ubuntu-latest
31+
permissions:
32+
contents: read
33+
packages: write
34+
35+
env:
36+
RELEASE_VERSION: "${{ github.event.release.tag_name }}"
37+
38+
strategy:
39+
fail-fast: false
40+
matrix:
41+
file_tag:
42+
- file: ./src/accountingservice/Dockerfile
43+
tag_suffix: accountingservice
44+
context: ./
45+
setup-qemu: true
46+
- file: ./src/adservice/Dockerfile
47+
tag_suffix: adservice
48+
context: ./
49+
setup-qemu: true
50+
- file: ./src/cartservice/src/Dockerfile
51+
tag_suffix: cartservice
52+
context: ./
53+
setup-qemu: false
54+
- file: ./src/checkoutservice/Dockerfile
55+
tag_suffix: checkoutservice
56+
context: ./
57+
setup-qemu: true
58+
- file: ./src/currencyservice/Dockerfile
59+
tag_suffix: currencyservice
60+
context: ./
61+
setup-qemu: true
62+
- file: ./src/emailservice/Dockerfile
63+
tag_suffix: emailservice
64+
context: ./src/emailservice
65+
setup-qemu: true
66+
- file: ./src/frauddetectionservice/Dockerfile
67+
tag_suffix: frauddetectionservice
68+
context: ./
69+
setup-qemu: true
70+
- file: ./src/frontend/Dockerfile
71+
tag_suffix: frontend
72+
context: ./
73+
setup-qemu: true
74+
- file: ./src/frontendproxy/Dockerfile
75+
tag_suffix: frontendproxy
76+
context: ./
77+
setup-qemu: true
78+
- file: ./src/frontend/Dockerfile.cypress
79+
tag_suffix: frontend-tests
80+
context: ./
81+
setup-qemu: true
82+
- file: ./src/imageprovider/Dockerfile
83+
tag_suffix: imageprovider
84+
context: ./
85+
setup-qemu: true
86+
- file: ./src/kafka/Dockerfile
87+
tag_suffix: kafka
88+
context: ./
89+
setup-qemu: true
90+
- file: ./src/loadgenerator/Dockerfile
91+
tag_suffix: loadgenerator
92+
context: ./
93+
setup-qemu: true
94+
- file: ./src/paymentservice/Dockerfile
95+
tag_suffix: paymentservice
96+
context: ./
97+
setup-qemu: true
98+
- file: ./src/productcatalogservice/Dockerfile
99+
tag_suffix: productcatalogservice
100+
context: ./
101+
setup-qemu: true
102+
- file: ./src/quoteservice/Dockerfile
103+
tag_suffix: quoteservice
104+
context: ./
105+
setup-qemu: true
106+
- file: ./src/recommendationservice/Dockerfile
107+
tag_suffix: recommendationservice
108+
context: ./
109+
setup-qemu: true
110+
- file: ./src/shippingservice/Dockerfile
111+
tag_suffix: shippingservice
112+
context: ./
113+
setup-qemu: true
114+
- file: ./test/tracetesting/Dockerfile
115+
tag_suffix: traceBasedTests
116+
context: ./
117+
setup-qemu: true
118+
119+
steps:
120+
- uses: actions/checkout@v4
121+
with:
122+
fetch-depth: 0
123+
- name: Check for changes and set push options
124+
id: check_changes
125+
run: |
126+
DOCKERFILE_DIR=$(dirname ${{ matrix.file_tag.file }})
127+
FILES_CHANGED=$(git diff --name-only ${{ github.event.pull_request.base.sha }} ${{ github.sha }} -- $DOCKERFILE_DIR)
128+
FORCE_PUSH=${{ inputs.push }}
129+
if [ "$FORCE_PUSH" = true ]; then
130+
echo "Force push is enabled, proceeding with build."
131+
echo "skip=false" >> "$GITHUB_OUTPUT"
132+
elif [ -z "$FILES_CHANGED" ]; then
133+
echo "No changes in ${{ matrix.file_tag.context }}, skipping build."
134+
echo "skip=true" >> "$GITHUB_OUTPUT"
135+
else
136+
echo "Changes detected in ${{ matrix.file_tag.context }}, proceeding with build."
137+
echo "skip=false" >> "$GITHUB_OUTPUT"
138+
fi
139+
- name: Log in to the Container registry
140+
uses: docker/login-action@v3
141+
with:
142+
registry: ghcr.io
143+
username: ${{ github.repository_owner }}
144+
password: ${{ secrets.GITHUB_TOKEN }}
145+
if: ${{ inputs.push }}
146+
- name: Log in to Docker Hub
147+
uses: docker/login-action@v3
148+
with:
149+
username: ${{ secrets.DOCKER_USERNAME }}
150+
password: ${{ secrets.DOCKER_PASSWORD }}
151+
if: ${{ inputs.push }}
152+
- name: Set up QEMU
153+
if: ${{ matrix.file_tag.setup-qemu }}
154+
uses: docker/setup-qemu-action@v3
155+
with:
156+
image: tonistiigi/binfmt:master
157+
- name: Set up Docker Buildx
158+
uses: docker/setup-buildx-action@v3
159+
with:
160+
config-inline: |
161+
[worker.oci]
162+
max-parallelism = 2
163+
- name: Matrix Build and push demo images
164+
if: steps.check_changes.outputs.skip == 'false'
165+
uses: docker/[email protected]
166+
with:
167+
context: ${{ matrix.file_tag.context }}
168+
file: ${{ matrix.file_tag.file }}
169+
platforms: linux/amd64,linux/arm64
170+
push: ${{ inputs.push }}
171+
tags: |
172+
${{ inputs.dockerhub_repo }}:${{ inputs.version }}-${{matrix.file_tag.tag_suffix }}
173+
${{ inputs.dockerhub_repo }}:latest-${{matrix.file_tag.tag_suffix }}
174+
${{ inputs.ghcr_repo }}:${{ inputs.version }}-${{ matrix.file_tag.tag_suffix }}
175+
${{ inputs.ghcr_repo }}:latest-${{ matrix.file_tag.tag_suffix }}
176+
cache-from: type=gha
177+
cache-to: type=gha

.github/workflows/nightly-release.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ on:
99

1010
jobs:
1111
build_and_push_images:
12-
uses: ./.github/workflows/build-images.yml
12+
uses: ./.github/workflows/component_build-images.yml
1313
if: github.repository == 'open-telemetry/opentelemetry-demo'
1414
with:
1515
push: true

.github/workflows/release.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ on:
88

99
jobs:
1010
build_and_push_images:
11-
uses: ./.github/workflows/build-images.yml
11+
uses: ./.github/workflows/component_build-images.yml
1212
if: github.repository == 'open-telemetry/opentelemetry-demo'
1313
with:
1414
push: true

0 commit comments

Comments
 (0)