Skip to content

Commit 55dd0ff

Browse files
authored
Enhance Docker publish workflow for multi-platform support
Updated Docker publish workflow to support multiple platforms and removed unused job.
1 parent 934e525 commit 55dd0ff

File tree

1 file changed

+15
-59
lines changed

1 file changed

+15
-59
lines changed

.github/workflows/docker-publish.yml

Lines changed: 15 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -12,22 +12,19 @@ on:
1212
# Publish `v1.2.3` tags as releases.
1313
tags:
1414
- v*
15-
- '*-v*'
1615

1716
# Defines two custom environment variables for the workflow.
1817
# These are used for the Container registry domain, and a
1918
# name for the Docker image that this workflow builds.
2019
env:
2120
REGISTRY: ghcr.io
2221
IMAGE_NAME: ${{ github.repository }}
22+
DOCKER_PLATFORMS: linux/amd64,linux/arm64
2323

24-
# Two jobs for creating and pushing Docker image
25-
# - build-and-push-image -> triggered by commits on main and tagging with semantic version (e.g.: v1.2.3)
26-
# - build-and-push-image-of-branch -> triggered by tags matching '*-v*' (e.g.: Version_1-v1.2.3)
24+
# Only one job for creating and pushing Docker image
2725
jobs:
2826
build-and-push-image:
2927
runs-on: ubuntu-latest
30-
if: ${{ contains(github.ref_name, '-') == failure() }}
3128
# Sets the permissions granted to the `GITHUB_TOKEN`
3229
# for the actions in this job.
3330
permissions:
@@ -36,83 +33,42 @@ jobs:
3633
#
3734
steps:
3835
- name: Checkout repository
39-
uses: actions/checkout@v6
36+
uses: actions/checkout@v4
4037
# Uses the `docker/login-action` action to log in to the Container
4138
# registry using the account and password that will publish the packages.
4239
# Once published, the packages are scoped to the account defined here.
4340
- name: Log in to the Container registry
44-
uses: docker/login-action@v3
41+
uses: docker/login-action@327cd5a69de6c009b9ce71bce8395f28e651bf99
4542
with:
4643
registry: ${{ env.REGISTRY }}
4744
username: ${{ github.actor }}
4845
password: ${{ secrets.GITHUB_TOKEN }}
46+
47+
# Add support for more platforms with QEMU
48+
- name: Set up QEMU
49+
uses: docker/setup-qemu-action@v3
50+
51+
- name: Set up Docker Buildx
52+
uses: docker/setup-buildx-action@v3
53+
4954
# This step uses [docker/metadata-action](https://github.com/docker/metadata-action#about)
5055
# to extract tags and labels that will be applied to the specified image.
5156
# The `id` "meta" allows the output of this step to be referenced in a
5257
# subsequent step. The `images` value provides the base name for the tags
5358
# and labels.
5459
- name: Extract metadata (tags, labels) for Docker
5560
id: meta
56-
uses: docker/metadata-action@v5
61+
uses: docker/metadata-action@8e1d5461f02b7886d3c1a774bfbd873650445aa2
5762
with:
5863
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
5964
# This step uses the `docker/build-push-action` action to build the image, based on your repository's `Dockerfile`. If the build succeeds, it pushes the image to GitHub Packages.
6065
# It uses the `context` parameter to define the build's context as the set of files located in the specified path. For more information, see "[Usage](https://github.com/docker/build-push-action#usage)" in the README of the `docker/build-push-action` repository.
6166
# It uses the `tags` and `labels` parameters to tag and label the image with the output from the "meta" step.
6267
- name: Build and push Docker image
63-
uses: docker/build-push-action@v6
68+
uses: docker/build-push-action@ca877d9245402d1537745e0e356eab47c3520991
6469
with:
6570
context: .
6671
push: true
6772
tags: ${{ steps.meta.outputs.tags }}
6873
labels: ${{ steps.meta.outputs.labels }}
69-
build-and-push-image-of-branch:
70-
runs-on: ubuntu-latest
71-
if: contains(github.ref_name, '-')
72-
# Sets the permissions granted to the `GITHUB_TOKEN`
73-
# for the actions in this job.
74-
permissions:
75-
contents: read
76-
packages: write
77-
#
78-
steps:
79-
- name: Split first part
80-
env:
81-
TAG: ${{ github.ref_name }}
82-
id: split
83-
run: echo "branch=${TAG%-v*}" >> $GITHUB_OUTPUT
84-
- name: Test variable
85-
run: |
86-
echo ${{ steps.split.outputs.branch }}
87-
- name: Checkout repository
88-
uses: actions/checkout@v6
89-
# Uses the `docker/login-action` action to log in to the Container
90-
# registry using the account and password that will publish the packages.
91-
# Once published, the packages are scoped to the account defined here.
92-
- name: Log in to the Container registry
93-
uses: docker/login-action@v3
94-
with:
95-
registry: ${{ env.REGISTRY }}
96-
username: ${{ github.actor }}
97-
password: ${{ secrets.GITHUB_TOKEN }}
98-
# This step uses [docker/metadata-action](https://github.com/docker/metadata-action#about)
99-
# to extract tags and labels that will be applied to the specified image.
100-
# The `id` "meta" allows the output of this step to be referenced in a
101-
# subsequent step. The `images` value provides the base name for the tags
102-
# and labels.
103-
- name: Extract metadata (tags, labels) for Docker
104-
id: meta-branch
105-
uses: docker/metadata-action@v5
106-
with:
107-
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}-${{steps.split.outputs.branch}}
108-
# This step uses the `docker/build-push-action` action to build the image, based on your repository's `Dockerfile`. If the build succeeds, it pushes the image to GitHub Packages.
109-
# It uses the `context` parameter to define the build's context as the set of files located in the specified path. For more information, see "[Usage](https://github.com/docker/build-push-action#usage)" in the README of the `docker/build-push-action` repository.
110-
# It uses the `tags` and `labels` parameters to tag and label the image with the output from the "meta" step.
111-
- name: Build and push Docker image
112-
uses: docker/build-push-action@v6
113-
with:
114-
context: .
115-
push: true
116-
tags: ${{ steps.meta-branch.outputs.tags }}
117-
labels: ${{ steps.meta-branch.outputs.labels }}
118-
74+
platforms: ${{ env.DOCKER_PLATFORMS }}

0 commit comments

Comments
 (0)