Skip to content

Commit b9fda0b

Browse files
authored
feat: publish multi arch docker image to dockerhub (#751)
* chore: Update Docker workflow to use Buildpacks The Docker workflow has been updated to use Buildpacks for building and pushing the Docker image. This change improves the build process and ensures compatibility with the latest versions of the required dependencies. * chore: add workflow dispatch * chore: docker login * chore: add multi arch builds * fix linebreaks * print pack version * update pack action * chore: Update Docker workflow to use Buildpacks * curl * use linux version of pack * fix platform * fix platform * use only arm * no platform * try amd * remove buildpackless * chore: Update Docker workflow to use Buildpacks with multiple platforms * chore: Update Docker workflow to use Buildpacks with multiple platforms * chore: Update Docker workflow to use Buildpacks with multiple platforms * Update docker.yml * Update docker.yml * Update docker.yml * Update docker.yml * Update docker.yml * Update docker.yml * Update docker.yml * Update docker.yml * Update docker.yml * Update docker.yml * Update docker.yml * Update docker.yml * Update docker.yml * Update docker.yml * Update docker.yml * Create buildpack * Rename buildpack to buildpack.yaml * Update buildpack.yaml * Update docker.yml * Delete .github/workflows/buildpack.yaml * Update docker.yml * Update docker.yml * Update docker.yml * Update docker.yml
1 parent 3b7c04b commit b9fda0b

File tree

1 file changed

+96
-49
lines changed

1 file changed

+96
-49
lines changed

.github/workflows/docker.yml

Lines changed: 96 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -1,66 +1,113 @@
1-
name: Docker Release
1+
name: Docker
22

33
on:
44
push:
55
tags:
6-
- '*'
7-
branches:
8-
- master
6+
- "*"
7+
workflow_dispatch:
98

10-
permissions:
11-
contents: read
9+
env:
10+
REGISTRY_IMAGE: mergeability/mergeable
1211

1312
jobs:
14-
init:
15-
permissions:
16-
contents: none
17-
runs-on: ubuntu-latest
18-
outputs:
19-
do_docker: ${{ steps.vars.outputs.IS_DOCKERHUB_PUSH }}
20-
steps:
21-
- name: Initialize workflow variables
22-
shell: bash
23-
run: |
24-
# work-around for inaccessible 'secrets' object for 'if'; see <https://github.community/t5/GitHub-Actions/jobs-lt-job-id-gt-if-does-not-work-with-env-secrets/m-p/38549>)
25-
unset IS_DOCKERHUB_PUSH
26-
if [ -z "$DOCKERHUB_PUSH" ]; then IS_DOCKERHUB_PUSH='false'; else IS_DOCKERHUB_PUSH='true' ; fi
27-
echo set-output name=IS_DOCKERHUB_PUSH::${IS_DOCKERHUB_PUSH}
28-
echo ::set-output name=IS_DOCKERHUB_PUSH::${IS_DOCKERHUB_PUSH}
29-
env:
30-
DOCKERHUB_PUSH: ${{ secrets.DOCKERHUB_PUSH }}
3113
build:
32-
name: Build and push Docker image
3314
runs-on: ubuntu-latest
34-
needs: [init]
35-
if: ${{ needs.init.outputs.do_docker == 'true' }}
15+
strategy:
16+
fail-fast: false
17+
matrix:
18+
platform:
19+
- linux/amd64
20+
# Failing to build
21+
# - linux/arm/v6
22+
- linux/arm/v7
23+
- linux/arm64
3624
steps:
25+
- name: Prepare
26+
run: |
27+
platform=${{ matrix.platform }}
28+
echo "PLATFORM_PAIR=${platform//\//-}" >> $GITHUB_ENV
29+
3730
- name: Checkout
38-
uses: actions/checkout@v2
39-
31+
uses: actions/checkout@v4
32+
33+
- name: Docker meta
34+
id: meta
35+
uses: docker/metadata-action@v5
36+
with:
37+
images: ${{ env.REGISTRY_IMAGE }}
38+
4039
- name: Set up Docker Buildx
41-
uses: docker/setup-buildx-action@v1
42-
43-
- name: Login to DockerHub
44-
uses: docker/login-action@v1
40+
uses: docker/setup-buildx-action@v3
41+
42+
- name: Login to Docker Hub
43+
uses: docker/login-action@v3
4544
with:
4645
username: ${{ secrets.DOCKERHUB_USERNAME }}
47-
password: ${{ secrets.DOCKERHUB_PASSWORD }}
48-
49-
- name: Build and push latest
50-
uses: docker/build-push-action@v2
51-
if: github.ref == 'refs/heads/master'
46+
password: ${{ secrets.DOCKERHUB_TOKEN }}
47+
48+
- name: Build and push by digest
49+
id: build
50+
uses: docker/build-push-action@v5
5251
with:
53-
push: true
54-
tags: ${{ secrets.DOCKERHUB_REPO }}:latest
55-
56-
- name: Set version variable
57-
id: version
58-
if: startsWith(github.ref, 'refs/tags/')
59-
run: echo ::set-output name=TAG::${GITHUB_REF#refs/tags/}
52+
context: .
53+
platforms: ${{ matrix.platform }}
54+
labels: ${{ steps.meta.outputs.labels }}
55+
outputs: type=image,name=${{ env.REGISTRY_IMAGE }},push-by-digest=true,name-canonical=true,push=true
56+
cache-from: type=gha,scope=build-${{ matrix.platform }}
57+
cache-to: type=gha,mode=max,scope=build-${{ matrix.platform }}
58+
59+
- name: Export digest
60+
run: |
61+
mkdir -p /tmp/digests
62+
digest="${{ steps.build.outputs.digest }}"
63+
touch "/tmp/digests/${digest#sha256:}"
64+
65+
- name: Upload digest
66+
uses: actions/upload-artifact@v4
67+
with:
68+
name: digests-${{ env.PLATFORM_PAIR }}
69+
path: /tmp/digests/*
70+
if-no-files-found: error
71+
retention-days: 1
6072

61-
- name: Build and push tag
62-
uses: docker/build-push-action@v2
63-
if: startsWith(github.ref, 'refs/tags/')
73+
merge:
74+
runs-on: ubuntu-latest
75+
needs:
76+
- build
77+
steps:
78+
- name: Download digests
79+
uses: actions/download-artifact@v4
80+
with:
81+
path: /tmp/digests
82+
pattern: digests-*
83+
merge-multiple: true
84+
85+
- name: Set up Docker Buildx
86+
uses: docker/setup-buildx-action@v3
87+
88+
- name: Docker meta
89+
id: meta
90+
uses: docker/metadata-action@v5
6491
with:
65-
push: true
66-
tags: ${{ secrets.DOCKERHUB_REPO }}:${{ steps.version.outputs.TAG }}
92+
images: ${{ env.REGISTRY_IMAGE }}
93+
tags: |
94+
# minimal
95+
type=semver,pattern={{version}}
96+
# set latest tag for default branch
97+
type=raw,value=latest,enable={{is_default_branch}}
98+
99+
- name: Login to Docker Hub
100+
uses: docker/login-action@v3
101+
with:
102+
username: ${{ secrets.DOCKERHUB_USERNAME }}
103+
password: ${{ secrets.DOCKERHUB_TOKEN }}
104+
105+
- name: Create manifest list and push
106+
working-directory: /tmp/digests
107+
run: |
108+
docker buildx imagetools create $(jq -cr '.tags | map("-t " + .) | join(" ")' <<< "$DOCKER_METADATA_OUTPUT_JSON") \
109+
$(printf '${{ env.REGISTRY_IMAGE }}@sha256:%s ' *)
110+
111+
- name: Inspect image
112+
run: |
113+
docker buildx imagetools inspect ${{ env.REGISTRY_IMAGE }}:${{ steps.meta.outputs.version }}

0 commit comments

Comments
 (0)