Skip to content

Commit 5a5d1cd

Browse files
authored
Add image platform in container publication (#17)
* Add image platform in container publication * Docker push with buildx
1 parent 62dbf6e commit 5a5d1cd

1 file changed

Lines changed: 34 additions & 21 deletions

File tree

.github/workflows/reusable-container-publication.yml

Lines changed: 34 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,11 @@ on:
4242
description: Image tag
4343
type: string
4444
required: true
45+
image-platform:
46+
description: Image platform
47+
type: string
48+
required: false
49+
default: "linux/amd64,linux/arm64"
4550
job-name:
4651
description: Job name
4752
type: string
@@ -69,7 +74,7 @@ on:
6974
container-registry-password:
7075
description: Container registry password
7176
required: true
72-
extra-vars:
77+
secret-vars:
7378
description: "Additional environment variables"
7479
required: false
7580

@@ -81,17 +86,18 @@ jobs:
8186
run:
8287
working-directory: ${{ inputs.working-directory }}
8388
steps:
84-
- name: Set additional variables
89+
- name: Set secret variables
90+
shell: bash
91+
env:
92+
SECRET_VARS: ${{ secrets.secret-vars }}
8593
run: |
86-
if [[ -z "${{ secrets.extra-vars }}" ]]; then
87-
echo "No extra-vars bundle provided - skipping."
88-
else
89-
echo "${{ secrets.extra-vars }}" | while IFS='=' read -r key val; do
94+
if [[ -n "$SECRET_VARS" ]]; then
95+
echo "$SECRET_VARS" | while IFS='=' read -r key val; do
9096
if [[ -n "$val" ]]; then
9197
echo "::add-mask::$val"
9298
fi
9399
done
94-
echo "${{ secrets.extra-vars }}" >> "$GITHUB_ENV"
100+
echo "$SECRET_VARS" >> "$GITHUB_ENV"
95101
fi
96102
- name: Clone repository
97103
uses: actions/checkout@v6
@@ -102,31 +108,38 @@ jobs:
102108
ref: ${{ inputs.workflow-parts-version }}
103109
path: workflow-parts
104110
- name: Login to container registry
105-
uses: docker/login-action@v3
111+
uses: docker/login-action@v4
106112
with:
107113
registry: ${{ inputs.container-registry }}
108114
username: ${{ secrets.container-registry-username }}
109115
password: ${{ secrets.container-registry-password }}
110-
- name: Build container image
111-
run: docker build . --file ${{ inputs.image-definition }} --tag ${{ env.IMAGE_REF }} ${{ inputs.extra-build-arguments }}
112-
shell: bash
116+
- name: Set up QEMU
117+
uses: docker/setup-qemu-action@v4
118+
- name: Set up Buildx
119+
uses: docker/setup-buildx-action@v4
120+
- name: Build and push container image
121+
id: build-push
122+
uses: docker/build-push-action@v7
123+
with:
124+
context: ${{ inputs.working-directory }}
125+
file: ${{ inputs.image-definition }}
126+
platforms: ${{ inputs.image-platform }}
127+
push: true
128+
tags: ${{ env.IMAGE_REF }}
129+
cache-from: type=gha
130+
cache-to: type=gha,mode=max
131+
build-args: ${{ inputs.extra-build-arguments }}
113132
- name: Generate SBOM with Syft
114133
uses: anchore/sbom-action@v0
115134
continue-on-error: true
116135
with:
117136
image: ${{ env.IMAGE_REF }}
118-
# format: spdx-json # Or cyclonedx-json
119-
# output-file: sbom.json
120-
# upload-artifact: true # Auto-upload to workflow artifacts
121-
- name: Push image to container registry
122-
run: docker push ${{ env.IMAGE_REF }}
123-
shell: bash
124-
- name: Push latest tag to container registry
137+
- name: Push latest tag
125138
if: ${{ inputs.create-latest }}
126139
run: |
127-
docker tag ${{ env.IMAGE_REF }} ${{ env.IMAGE_REF_LATEST }}
128-
docker push ${{ env.IMAGE_REF_LATEST }}
129-
shell: bash
140+
docker buildx imagetools create \
141+
--tag ${{ env.IMAGE_REF_LATEST }} \
142+
${{ env.IMAGE_REF }}
130143
- name: Sign container image with Cosign
131144
uses: ./workflow-parts/actions/cosign/sign
132145
with:

0 commit comments

Comments
 (0)