1818 outputs :
1919 path :
2020 description : " Path to built container"
21- value : ghcr.io/${{ jobs.build.outputs.repo }}/${{ inputs.name }}:${{ jobs.build.outputs.tag }}
21+ value : ghcr.io/${{ jobs.build-amd64 .outputs.repo }}/${{ inputs.name }}:${{ jobs.build-amd64 .outputs.tag }}
2222
2323jobs :
24- build :
25- name : Build container
24+ build-amd64 :
25+ name : Build container (amd64)
2626 runs-on : ubuntu-24.04
2727 outputs :
2828 tag : ${{ steps.prepare.outputs.tag }}
2929 repo : ${{ steps.prepare.outputs.repo }}
30+ digest : ${{ steps.build.outputs.digest }}
3031 steps :
3132 - name : Checkout code
3233 uses : actions/checkout@v4
3839 run : |
3940 BRANCH_NAME=$(echo "${GITHUB_REF##*/}" | tr '[:upper:]' '[:lower:]')
4041 REPO_NAME=$(echo "${{ github.repository }}" | tr '[:upper:]' '[:lower:]')
41- echo "tag=${BRANCH_NAME}" >> $GITHUB_OUTPUT
42- echo "repo=${REPO_NAME}" >> $GITHUB_OUTPUT
42+ echo "tag=${BRANCH_NAME}" >> " $GITHUB_OUTPUT"
43+ echo "repo=${REPO_NAME}" >> " $GITHUB_OUTPUT"
4344
4445 - name : Set up Docker Buildx
4546 uses : docker/setup-buildx-action@v3
@@ -52,17 +53,99 @@ jobs:
5253 password : ${{ secrets.GITHUB_TOKEN }}
5354
5455 - name : Build and push Docker image
56+ id : build
5557 uses : docker/build-push-action@v6
5658 with :
5759 context : ${{ inputs.context }}
5860 file : ${{ inputs.file }}
5961 push : true
62+ platforms : linux/amd64
6063 tags : |
61- ghcr.io/${{ steps.prepare.outputs.repo }}/${{ inputs.name }}:${{ hashFiles(inputs.file) }}
62- ghcr.io/${{ steps.prepare.outputs.repo }}/${{ inputs.name }}:${{ steps.prepare.outputs.tag }}
63- ghcr.io/${{ steps.prepare.outputs.repo }}/${{ inputs.name }}:latest
64+ ghcr.io/${{ steps.prepare.outputs.repo }}/${{ inputs.name }}:${{ hashFiles(inputs.file) }}-amd64
6465 cache-from : |
65- type=registry,ref=ghcr.io/${{ steps.prepare.outputs.repo }}/${{ inputs.name }}:${{ hashFiles(inputs.file) }}
66+ type=registry,ref=ghcr.io/${{ steps.prepare.outputs.repo }}/${{ inputs.name }}:${{ hashFiles(inputs.file) }}-amd64
6667 type=registry,ref=ghcr.io/${{ steps.prepare.outputs.repo }}/${{ inputs.name }}:${{ steps.prepare.outputs.tag }}
67- type=registry,ref=ghcr.io/${{ steps.prepare.outputs.repo }}/${{ inputs.name }}:latest
6868 cache-to : type=inline
69+
70+ build-arm64 :
71+ name : Build container (arm64)
72+ runs-on : ubuntu-24.04-arm
73+ outputs :
74+ digest : ${{ steps.build.outputs.digest }}
75+ steps :
76+ - name : Checkout code
77+ uses : actions/checkout@v4
78+ with :
79+ ref : ${{ github.event.pull_request.head.sha }}
80+
81+ - name : Prepare variables
82+ id : prepare
83+ run : |
84+ BRANCH_NAME=$(echo "${GITHUB_REF##*/}" | tr '[:upper:]' '[:lower:]')
85+ REPO_NAME=$(echo "${{ github.repository }}" | tr '[:upper:]' '[:lower:]')
86+ echo "tag=${BRANCH_NAME}" >> "$GITHUB_OUTPUT"
87+ echo "repo=${REPO_NAME}" >> "$GITHUB_OUTPUT"
88+
89+ - name : Set up Docker Buildx
90+ uses : docker/setup-buildx-action@v3
91+
92+ - name : Login to GitHub Container Registry
93+ uses : docker/login-action@v3
94+ with :
95+ registry : ghcr.io
96+ username : ${{ github.actor }}
97+ password : ${{ secrets.GITHUB_TOKEN }}
98+
99+ - name : Build and push Docker image
100+ id : build
101+ uses : docker/build-push-action@v6
102+ with :
103+ context : ${{ inputs.context }}
104+ file : ${{ inputs.file }}
105+ push : true
106+ platforms : linux/arm64
107+ tags : |
108+ ghcr.io/${{ steps.prepare.outputs.repo }}/${{ inputs.name }}:${{ hashFiles(inputs.file) }}-arm64
109+ cache-from : |
110+ type=registry,ref=ghcr.io/${{ steps.prepare.outputs.repo }}/${{ inputs.name }}:${{ hashFiles(inputs.file) }}-arm64
111+ type=registry,ref=ghcr.io/${{ steps.prepare.outputs.repo }}/${{ inputs.name }}:${{ steps.prepare.outputs.tag }}
112+ cache-to : type=inline
113+
114+ create-manifest :
115+ name : Create multi-arch manifest
116+ runs-on : ubuntu-24.04-arm
117+ needs : [build-amd64, build-arm64]
118+ steps :
119+ - name : Checkout code
120+ uses : actions/checkout@v4
121+ with :
122+ ref : ${{ github.event.pull_request.head.sha }}
123+
124+ - name : Set up Docker Buildx
125+ uses : docker/setup-buildx-action@v3
126+
127+ - name : Login to GitHub Container Registry
128+ uses : docker/login-action@v3
129+ with :
130+ registry : ghcr.io
131+ username : ${{ github.actor }}
132+ password : ${{ secrets.GITHUB_TOKEN }}
133+
134+ - name : Create and push multi-arch manifest
135+ run : |
136+ REPO="ghcr.io/${{ needs.build-amd64.outputs.repo }}/${{ inputs.name }}"
137+ TAG="${{ needs.build-amd64.outputs.tag }}"
138+ HASH_TAG="${{ hashFiles(inputs.file) }}"
139+
140+ # Create manifest from arch-specific images
141+ docker buildx imagetools create -t "${REPO}:${HASH_TAG}" \
142+ "${REPO}:${HASH_TAG}-amd64" \
143+ "${REPO}:${HASH_TAG}-arm64"
144+
145+ docker buildx imagetools create -t "${REPO}:${TAG}" \
146+ "${REPO}:${HASH_TAG}-amd64" \
147+ "${REPO}:${HASH_TAG}-arm64"
148+
149+ docker buildx imagetools create -t "${REPO}:latest" \
150+ "${REPO}:${HASH_TAG}-amd64" \
151+ "${REPO}:${HASH_TAG}-arm64"
0 commit comments