Skip to content

Commit 7410982

Browse files
committed
Introduce composite action for docker building
Test a composite action to reduce duplication
1 parent bbd244e commit 7410982

2 files changed

Lines changed: 78 additions & 8 deletions

File tree

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
name: build-server
2+
description: Sets up the build context and builds a docker image
3+
inputs:
4+
server-profile:
5+
required: true
6+
description: The profile of the server to build (discovery, registry, repository)
7+
load:
8+
required: false
9+
description: Set to "true" to use image in further steps (only works for single architecture builds)
10+
default: "false"
11+
platform:
12+
required: false
13+
description: The target platforms to build the image for
14+
default: "linux/amd64"
15+
publish:
16+
required: false
17+
description: Set to "true" to publish image to Docker Hub (requires login)
18+
default: "false"
19+
20+
outputs:
21+
image-digest:
22+
description: The image name + digest of the built image
23+
value: ${{ steps.build.outputs.imageid }}@${{ steps.build.outputs.digest }}
24+
25+
runs:
26+
using: composite
27+
steps:
28+
- name: Checkout Repository
29+
uses: actions/checkout@fbc6f3992d24b796d5a048ff273f7fcc4a7b6c09 #v5.1.0
30+
31+
- name: Setup QEMU
32+
uses: docker/setup-qemu-action@v4
33+
34+
- name: Set up Docker Buildx
35+
uses: docker/setup-buildx-action@v4
36+
37+
- name: Generate Image Title
38+
id: capitalize
39+
shell: bash
40+
run: |
41+
profile="${{ inputs.server-profile }}"
42+
echo "profile-title=${profile^}" >> "$GITHUB_OUTPUT"
43+
44+
- name: Extract Docker image metadata
45+
id: meta
46+
uses: docker/metadata-action@v5
47+
with:
48+
images: eclipsebasyx/basyx-python-${{ inputs.server-profile }}
49+
# This fetches the latest git tag and adds an additional "latest" to it, so e.g. `2.1.0,latest`
50+
tags: |
51+
type=semver,pattern={{version}}
52+
type=raw,value=latest,enable=${{ inputs.publish == 'true' && true || false }}
53+
type=sha,prefix=pr-,enable=${{ inputs.load == 'true' && true || false }}
54+
labels: |
55+
org.opencontainers.image.title=BaSyx Python ${{ steps.capitalize.outputs.profile-title }} Service
56+
org.opencontainers.image.description=Eclipse BaSyx Python SDK - ${{ steps.capitalize.outputs.profile-title }} HTTP Server
57+
org.opencontainers.image.source=https://github.com/eclipse-basyx/basyx-python-sdk/tree/main/server
58+
org.opencontainers.image.licenses=MIT
59+
60+
- name: Build Docker Image
61+
id: build
62+
uses: docker/build-push-action@v6
63+
with:
64+
context: .
65+
file: ./server/docker/${{ inputs.server-profile }}/Dockerfile
66+
tags: ${{ steps.meta.outputs.tags }}
67+
labels: ${{ steps.meta.outputs.labels }}
68+
platforms: ${{ inputs.platform }}
69+
#push: ${{ inputs.publish == 'true' && true || false }}
70+
load: ${{ inputs.load == 'true' && true || false }}

.github/workflows/pr.yml

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -344,17 +344,17 @@ jobs:
344344
matrix:
345345
service: ["repository", "discovery", "registry"]
346346
fail-fast: false
347-
defaults:
348-
run:
349-
working-directory: ./server/docker/${{ matrix.service }}
350347
steps:
351-
- uses: actions/checkout@fbc6f3992d24b796d5a048ff273f7fcc4a7b6c09 #v5.1.0
352-
- name: Build the Docker image
353-
run: |
354-
docker build -t basyx-python-${{ matrix.service }} -f Dockerfile ../../..
348+
- uses: ./.github/actions/build-server
349+
id: build
350+
with:
351+
server-profile: ${{ matrix.service }}
352+
load: true
353+
publish: false
354+
platform: linux/amd64
355355
- name: Run container
356356
run: |
357-
docker run -d --name basyx-python-${{ matrix.service }} -p 9080:80 basyx-python-${{ matrix.service }}
357+
docker run -d --name basyx-python-${{ matrix.service }} -p 9080:80 ${{ steps.build.outputs.image-digest }}
358358
- name: Wait for container and server initialization
359359
run: |
360360
timeout 30s bash -c '

0 commit comments

Comments
 (0)