1
1
name : Build and Push Docker Image for Multiple Architectures
2
2
3
3
on :
4
- # To enable manual triggering of this workflow
5
- workflow_dispatch :
6
-
7
- # Trigger for pushes to master and tags
4
+ pull_request :
8
5
push :
9
6
branches :
10
7
- master
11
- - develop # TODO: Remove this
8
+ - develop
12
9
tags :
13
10
- ' v*.*.*'
14
11
@@ -18,6 +15,7 @@ concurrency:
18
15
19
16
env :
20
17
IMAGE_NAME : index.docker.io/metacall/core
18
+ BUILDKIT_VERSION : 0.13.0
21
19
22
20
jobs :
23
21
build :
@@ -29,103 +27,118 @@ jobs:
29
27
platform :
30
28
- linux/amd64
31
29
- linux/arm64
32
- - linux/arm/v6
30
+ - linux/riscv64
31
+ - linux/ppc64le
32
+ - linux/s390x
33
+ - linux/386
33
34
- linux/arm/v7
35
+ - linux/arm/v6
36
+ # - linux/mips64le
37
+ # - linux/mips64
38
+
34
39
steps :
35
40
- name : Checkout the code
36
41
uses : actions/checkout@v4
37
42
with :
38
43
fetch-depth : 0
39
44
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
47
46
id : meta
48
47
uses : docker/metadata-action@v5
49
48
with :
50
49
images : ${{ env.IMAGE_NAME }}
51
-
50
+
52
51
- name : Set up QEMU
53
52
uses : docker/setup-qemu-action@v3
54
-
55
- - name : Set up Docker Buildx
53
+
54
+ - name : Docker Setup BuildX
56
55
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
57
61
58
- - name : Login to DockerHub
62
+ - name : Authenticate to Docker registry
63
+ if : github.event_name != 'pull_request'
59
64
uses : docker/login-action@v3
60
65
with :
61
- username : ${{ secrets.DOCKER_HUB_USERNAME }}
62
- password : ${{ secrets.DOCKER_HUB_ACCESS_TOKEN }}
66
+ username : ${{ secrets.DOCKER_USERNAME }}
67
+ password : ${{ secrets.DOCKER_PASSWORD }}
63
68
64
69
- 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