Skip to content

Commit d97241c

Browse files
Updated workflow
1 parent 59b14dc commit d97241c

1 file changed

Lines changed: 123 additions & 10 deletions

File tree

.github/workflows/docker-push.yml

Lines changed: 123 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
name: Build and Push Multi-Architecture Docker image
1+
name: Multi-Architecture Docker Build
22

33
on:
44
push:
@@ -10,9 +10,9 @@ permissions:
1010
packages: write
1111

1212
jobs:
13-
build-multiarch:
13+
build-push-amd64:
1414
runs-on: ubuntu-latest
15-
name: Build Multi-Architecture Image
15+
name: Build AMD64 Image
1616

1717
steps:
1818
- name: Check out the repository
@@ -30,11 +30,16 @@ jobs:
3030
echo "REPO_OWNER=$REPO_OWNER" >> $GITHUB_ENV
3131
echo "BRANCH_NAME=$BRANCH_NAME" >> $GITHUB_ENV
3232
33-
- name: Set up QEMU
34-
uses: docker/setup-qemu-action@v2
35-
33+
- name: Set up Docker Context for Buildx
34+
id: buildx-context
35+
run: |
36+
docker context create builders
37+
3638
- name: Set up Docker Buildx
3739
uses: docker/setup-buildx-action@v2
40+
with:
41+
version: latest
42+
endpoint: builders
3843

3944
- name: Log in to GitHub Container Registry
4045
uses: docker/login-action@v2
@@ -43,13 +48,121 @@ jobs:
4348
username: ${{ github.actor }}
4449
password: ${{ secrets.GITHUB_TOKEN }}
4550

46-
- name: Build and push multi-architecture Docker image
51+
- name: Build and push AMD64 Docker image
4752
uses: docker/build-push-action@v3
4853
with:
4954
context: .
5055
file: ./docker/Dockerfile
51-
platforms: linux/amd64,linux/arm64
56+
platforms: linux/amd64
5257
push: true
58+
provenance: false
5359
tags: |
54-
ghcr.io/${{ env.REPO_OWNER }}/${{ env.REPO_NAME }}:${{ env.BRANCH_NAME }}
55-
${{ github.ref == 'refs/heads/main' && format('ghcr.io/{0}/{1}:latest', env.REPO_OWNER, env.REPO_NAME) || '' }}
60+
ghcr.io/${{ env.REPO_OWNER }}/${{ env.REPO_NAME }}:latest-amd64
61+
ghcr.io/${{ env.REPO_OWNER }}/${{ env.REPO_NAME }}:${{ github.sha }}-amd64
62+
ghcr.io/${{ env.REPO_OWNER }}/${{ env.REPO_NAME }}:${{ env.BRANCH_NAME }}-amd64
63+
64+
build-push-arm64:
65+
runs-on: ubuntu-24.04-arm
66+
name: Build ARM64 Image
67+
68+
steps:
69+
- name: Check out the repository
70+
uses: actions/checkout@v3
71+
with:
72+
submodules: recursive
73+
74+
- name: Extract repository name and branch
75+
id: repo-info
76+
run: |
77+
REPO_NAME=$(echo "${{ github.repository }}" | awk -F '/' '{print $2}' | tr '[:upper:]' '[:lower:]')
78+
REPO_OWNER=$(echo "${{ github.repository_owner }}" | tr '[:upper:]' '[:lower:]')
79+
BRANCH_NAME=$(echo "${{ github.ref_name }}" | tr '/' '-' | tr '[:upper:]' '[:lower:]')
80+
echo "REPO_NAME=$REPO_NAME" >> $GITHUB_ENV
81+
echo "REPO_OWNER=$REPO_OWNER" >> $GITHUB_ENV
82+
echo "BRANCH_NAME=$BRANCH_NAME" >> $GITHUB_ENV
83+
84+
- name: Set up Docker Context for Buildx
85+
id: buildx-context
86+
run: |
87+
docker context create builders
88+
89+
- name: Set up Docker Buildx
90+
uses: docker/setup-buildx-action@v2
91+
with:
92+
version: latest
93+
endpoint: builders
94+
95+
- name: Log in to GitHub Container Registry
96+
uses: docker/login-action@v2
97+
with:
98+
registry: ghcr.io
99+
username: ${{ github.actor }}
100+
password: ${{ secrets.GITHUB_TOKEN }}
101+
102+
- name: Build and push ARM64 Docker image
103+
uses: docker/build-push-action@v3
104+
with:
105+
context: .
106+
file: ./docker/Dockerfile
107+
platforms: linux/arm64
108+
push: true
109+
provenance: false
110+
tags: |
111+
ghcr.io/${{ env.REPO_OWNER }}/${{ env.REPO_NAME }}:latest-arm64
112+
ghcr.io/${{ env.REPO_OWNER }}/${{ env.REPO_NAME }}:${{ github.sha }}-arm64
113+
ghcr.io/${{ env.REPO_OWNER }}/${{ env.REPO_NAME }}:${{ env.BRANCH_NAME }}-arm64
114+
115+
create-manifests:
116+
runs-on: ubuntu-latest
117+
needs: [build-push-amd64, build-push-arm64]
118+
name: Create Multi-Arch Manifest
119+
120+
steps:
121+
- name: Check out the repository
122+
uses: actions/checkout@v3
123+
124+
- name: Extract repository name and branch
125+
run: |
126+
REPO_NAME=$(echo "${{ github.repository }}" | awk -F '/' '{print $2}' | tr '[:upper:]' '[:lower:]')
127+
REPO_OWNER=$(echo "${{ github.repository_owner }}" | tr '[:upper:]' '[:lower:]')
128+
BRANCH_NAME=$(echo "${{ github.ref_name }}" | tr '/' '-' | tr '[:upper:]' '[:lower:]')
129+
echo "REPO_NAME=$REPO_NAME" >> $GITHUB_ENV
130+
echo "REPO_OWNER=$REPO_OWNER" >> $GITHUB_ENV
131+
echo "BRANCH_NAME=$BRANCH_NAME" >> $GITHUB_ENV
132+
133+
- name: Enable Docker experimental features
134+
run: |
135+
mkdir -p $HOME/.docker
136+
echo '{"experimental": "enabled"}' > $HOME/.docker/config.json
137+
138+
- name: Log in to GitHub Container Registry
139+
uses: docker/login-action@v2
140+
with:
141+
registry: ghcr.io
142+
username: ${{ github.actor }}
143+
password: ${{ secrets.GITHUB_TOKEN }}
144+
145+
- name: Create SHA manifest and push
146+
run: |
147+
# Using buildx imagetools instead of docker manifest
148+
docker buildx imagetools create \
149+
-t ghcr.io/${{ env.REPO_OWNER }}/${{ env.REPO_NAME }}:${{ github.sha }} \
150+
ghcr.io/${{ env.REPO_OWNER }}/${{ env.REPO_NAME }}:${{ github.sha }}-amd64 \
151+
ghcr.io/${{ env.REPO_OWNER }}/${{ env.REPO_NAME }}:${{ github.sha }}-arm64
152+
153+
- name: Create branch manifest and push
154+
run: |
155+
# Using buildx imagetools instead of docker manifest
156+
docker buildx imagetools create \
157+
-t ghcr.io/${{ env.REPO_OWNER }}/${{ env.REPO_NAME }}:${{ env.BRANCH_NAME }} \
158+
ghcr.io/${{ env.REPO_OWNER }}/${{ env.REPO_NAME }}:${{ env.BRANCH_NAME }}-amd64 \
159+
ghcr.io/${{ env.REPO_OWNER }}/${{ env.REPO_NAME }}:${{ env.BRANCH_NAME }}-arm64
160+
161+
- name: Create latest manifest and push
162+
if: github.ref == 'refs/heads/main'
163+
run: |
164+
# Using buildx imagetools instead of docker manifest
165+
docker buildx imagetools create \
166+
-t ghcr.io/${{ env.REPO_OWNER }}/${{ env.REPO_NAME }}:latest \
167+
ghcr.io/${{ env.REPO_OWNER }}/${{ env.REPO_NAME }}:latest-amd64 \
168+
ghcr.io/${{ env.REPO_OWNER }}/${{ env.REPO_NAME }}:latest-arm64

0 commit comments

Comments
 (0)