Skip to content

Commit b1c3464

Browse files
committed
Trying to make mutliarch work.
1 parent 50d2b61 commit b1c3464

File tree

1 file changed

+99
-86
lines changed

1 file changed

+99
-86
lines changed
Lines changed: 99 additions & 86 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,11 @@
11
name: Build and Push Docker Image for Multiple Architectures
22

33
on:
4-
# To enable manual triggering of this workflow
5-
workflow_dispatch:
6-
7-
# Trigger for pushes to master and tags
4+
pull_request:
85
push:
96
branches:
107
- master
11-
- develop # TODO: Remove this
8+
- develop
129
tags:
1310
- 'v*.*.*'
1411

@@ -18,6 +15,7 @@ concurrency:
1815

1916
env:
2017
IMAGE_NAME: index.docker.io/metacall/core
18+
BUILDKIT_VERSION: 0.13.0
2119

2220
jobs:
2321
build:
@@ -29,103 +27,118 @@ jobs:
2927
platform:
3028
- linux/amd64
3129
- linux/arm64
32-
- linux/arm/v6
30+
- linux/riscv64
31+
- linux/ppc64le
32+
- linux/s390x
33+
- linux/386
3334
- linux/arm/v7
35+
- linux/arm/v6
36+
# - linux/mips64le
37+
# - linux/mips64
38+
3439
steps:
3540
- name: Checkout the code
3641
uses: actions/checkout@v4
3742
with:
3843
fetch-depth: 0
3944

40-
- name: Define Platform
41-
run: |
42-
PLATFORM=${{ matrix.platform }}
43-
echo "METACALL_PLATFORM=${PLATFORM}" >> $GITHUB_ENV
44-
echo "METACALL_PLATFORM_PAIR=${PLATFORM//\//-}" >> $GITHUB_ENV
45-
46-
- name: Docker Metadata
45+
- name: Docker meta
4746
id: meta
4847
uses: docker/metadata-action@v5
4948
with:
5049
images: ${{ env.IMAGE_NAME }}
51-
50+
5251
- name: Set up QEMU
5352
uses: docker/setup-qemu-action@v3
54-
55-
- name: Set up Docker Buildx
53+
54+
- name: Docker Setup BuildX
5655
uses: docker/setup-buildx-action@v3
56+
with:
57+
version: v${{ env.BUILDKIT_VERSION }}
58+
59+
- name: Verify Docker BuildX Version
60+
run: docker buildx version
5761

58-
- name: Login to DockerHub
62+
- name: Authenticate to Docker registry
63+
if: github.event_name != 'pull_request'
5964
uses: docker/login-action@v3
6065
with:
61-
username: ${{ secrets.DOCKER_HUB_USERNAME }}
62-
password: ${{ secrets.DOCKER_HUB_ACCESS_TOKEN }}
66+
username: ${{ secrets.DOCKER_USERNAME }}
67+
password: ${{ secrets.DOCKER_PASSWORD }}
6368

6469
- name: Build MetaCall Docker Images
65-
run: bash ./docker-compose.sh platform
66-
67-
# # TODO: Build with alpine and provide multiple tags (debian & alpine) once all tests pass
68-
# - name: Push MetaCall Docker Image to DockerHub
69-
# run: |
70-
# if [[ "${{ github.ref == 'refs/heads/master' }}" = true ]]; then
71-
# bash ./docker-compose.sh push
72-
# elif [[ "${{ contains(github.ref, 'refs/tags/') }}" = true ]]; then
73-
# bash ./docker-compose.sh version
74-
# else
75-
# echo "Failed to push the docker images"
76-
# exit 1
77-
# fi
78-
79-
# - name: Export Digest
80-
# run: |
81-
# mkdir -p /tmp/digests
82-
# digest="${{ steps.build.outputs.digest }}"
83-
# touch "/tmp/digests/${digest#sha256:}"
84-
85-
# - name: Upload Digest
86-
# uses: actions/upload-artifact@v4
87-
# with:
88-
# name: digests-${{ env.METACALL_PLATFORM_PAIR }}
89-
# path: /tmp/digests/*
90-
# if-no-files-found: error
91-
# retention-days: 1
92-
93-
- name: Logout from DockerHub
94-
run: docker logout
95-
96-
# merge:
97-
# runs-on: ubuntu-latest
98-
# needs:
99-
# - build
100-
# steps:
101-
# - name: Download Digests
102-
# uses: actions/download-artifact@v4
103-
# with:
104-
# path: /tmp/digests
105-
# pattern: digests-*
106-
# merge-multiple: true
107-
108-
# - name: Set up Docker Buildx
109-
# uses: docker/setup-buildx-action@v3
110-
111-
# - name: Docker Metadata
112-
# id: meta
113-
# uses: docker/metadata-action@v5
114-
# with:
115-
# images: ${{ env.IMAGE_NAME }}
116-
117-
# - name: Login to DockerHub
118-
# uses: docker/login-action@v3
119-
# with:
120-
# username: ${{ secrets.DOCKER_HUB_USERNAME }}
121-
# password: ${{ secrets.DOCKER_HUB_ACCESS_TOKEN }}
122-
123-
# - name: Create manifest list and push
124-
# working-directory: /tmp/digests
125-
# run: |
126-
# docker buildx imagetools create $(jq -cr '.tags | map("-t " + .) | join(" ")' <<< "$DOCKER_METADATA_OUTPUT_JSON") \
127-
# $(printf '${{ env.IMAGE_NAME }}@sha256:%s ' *)
128-
129-
# - name: Inspect image
130-
# run: |
131-
# docker buildx imagetools inspect ${{ env.IMAGE_NAME }}:${{ steps.meta.outputs.version }}
70+
env:
71+
METACALL_PLATFORM: ${{ matrix.platform }}
72+
run: |
73+
./docker-compose.sh platform
74+
75+
- name: Export digests
76+
if: github.event_name != 'pull_request'
77+
run: |
78+
PLATFORM=${{ matrix.platform }}
79+
echo "PLATFORM=${PLATFORM//\//-}" >> $GITHUB_ENV
80+
for tag in "deps" "dev" "runtime" "cli"; do
81+
mkdir -p "/tmp/digests/${tag}"
82+
digest="$(docker images --no-trunc --quiet metacall/core:$tag)"
83+
touch "/tmp/digests/${tag}/${digest#sha256:}"
84+
done
85+
86+
- name: Upload digests
87+
if: github.event_name != 'pull_request'
88+
uses: actions/upload-artifact@v4
89+
with:
90+
name: digests-${{ env.PLATFORM }}
91+
path: /tmp/digests/*
92+
if-no-files-found: error
93+
retention-days: 1
94+
95+
merge:
96+
name: Merge digests for the manifest
97+
runs-on: ubuntu-latest
98+
if: github.event_name != 'pull_request'
99+
needs:
100+
- build
101+
steps:
102+
- name: Download digests
103+
uses: actions/download-artifact@v4
104+
with:
105+
path: /tmp/digests
106+
pattern: digests-*
107+
merge-multiple: true
108+
109+
- name: Set up Docker Buildx
110+
uses: docker/setup-buildx-action@v3
111+
with:
112+
version: v${{ env.BUILDKIT_VERSION }}
113+
114+
- name: Docker meta
115+
id: meta
116+
uses: docker/metadata-action@v5
117+
with:
118+
images: ${{ env.IMAGE_NAME }}
119+
120+
- name: Authenticate to Docker registry
121+
uses: docker/login-action@v3
122+
with:
123+
username: ${{ secrets.DOCKER_USERNAME }}
124+
password: ${{ secrets.DOCKER_PASSWORD }}
125+
126+
- name: Create manifest list and push
127+
if: github.ref != 'refs/heads/develop'
128+
run: |
129+
for tag in "deps" "dev" "runtime" "cli"; do
130+
cd "/tmp/digests/${tag}"
131+
IMAGE_HASHES=$(printf '${{ env.IMAGE_NAME }}@sha256:%s ' *)
132+
for image in $IMAGE_HASHES; do
133+
docker push $image
134+
done
135+
docker buildx imagetools create -t ${{ env.IMAGE_NAME }}:$tag $IMAGE_HASHES
136+
if [[ "${tag}" = "cli" ]]; then
137+
docker buildx imagetools create -t ${{ env.IMAGE_NAME }}:latest $IMAGE_HASHES
138+
if [[ "${{ contains(github.ref, 'refs/tags/') }}" = true ]]; then
139+
TAG=${GITHUB_REF#refs/*/}
140+
VERSION=${TAG#v}
141+
docker buildx imagetools create -t ${{ env.IMAGE_NAME }}:$VERSION $IMAGE_HASHES
142+
fi
143+
fi
144+
done

0 commit comments

Comments
 (0)