Skip to content

Commit d9892e3

Browse files
authored
Push multi-arch docker image (opendatahub-io#76)
Signed-off-by: ddelange <[email protected]>
1 parent f948753 commit d9892e3

File tree

1 file changed

+49
-17
lines changed

1 file changed

+49
-17
lines changed

.github/workflows/build-and-push.yml

Lines changed: 49 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ on:
55
branches: [ main ]
66
tags:
77
- v*
8+
pull_request:
89

910
jobs:
1011
test:
@@ -23,26 +24,57 @@ jobs:
2324
build:
2425
needs: test
2526
runs-on: ubuntu-latest
27+
if: github.event_name == 'push'
28+
2629
env:
27-
IMAGE_NAME: kserve/modelmesh
30+
IMAGE_NAME: modelmesh
31+
2832
steps:
29-
- uses: actions/checkout@v2
30-
- name: Build and push runtime image
31-
run: |
32-
GIT_COMMIT=$(git rev-parse HEAD)
33-
BUILD_ID=$(date '+%Y%m%d')-$(git rev-parse HEAD | cut -c -5)
33+
- uses: actions/checkout@v2
34+
35+
- name: Setup QEMU
36+
uses: docker/setup-qemu-action@v2
37+
38+
- name: Setup Docker Buildx
39+
uses: docker/setup-buildx-action@v2
40+
41+
- name: Login to DockerHub
42+
uses: docker/login-action@v2
43+
with:
44+
username: ${{ secrets.DOCKER_USER }}
45+
password: ${{ secrets.DOCKER_ACCESS_TOKEN }}
46+
47+
- name: export version variable
48+
run: |
49+
GIT_COMMIT=$(git rev-parse HEAD)
50+
BUILD_ID=$(date '+%Y%m%d')-$(git rev-parse HEAD | cut -c -5)
51+
52+
IMAGE_ID=kserve/$IMAGE_NAME
53+
54+
# Change all uppercase to lowercase
55+
IMAGE_ID=$(echo $IMAGE_ID | tr '[A-Z]' '[a-z]')
56+
57+
# Strip git ref prefix from version
58+
VERSION=$(echo "${{ github.ref }}" | sed -e 's,.*/\(.*\),\1,')
3459
35-
# Strip git ref prefix from version
36-
VERSION=$(echo "${{ github.ref }}" | sed -e 's,.*/\(.*\),\1,')
60+
# Strip "v" prefix from tag name
61+
# [[ "${{ github.ref }}" == "refs/tags/"* ]] && VERSION=$(echo $VERSION | sed -e 's/^v//')
3762
38-
# Use Docker `latest` tag convention
39-
[ "$VERSION" == "main" ] && VERSION=latest
40-
echo $VERSION
63+
# Use Docker `latest` tag convention
64+
[ "$VERSION" == "main" ] && VERSION=latest
4165
42-
docker build -t ${{ env.IMAGE_NAME }}:$VERSION \
43-
--build-arg imageVersion=$VERSION \
44-
--build-arg buildId=${BUILD_ID} \
45-
--build-arg commitSha=${GIT_COMMIT} .
66+
echo "GIT_COMMIT=$GIT_COMMIT" >> $GITHUB_ENV
67+
echo "BUILD_ID=$BUILD_ID" >> $GITHUB_ENV
68+
echo "VERSION=$VERSION" >> $GITHUB_ENV
69+
echo "IMAGE_ID=$IMAGE_ID" >> $GITHUB_ENV
4670
47-
docker login -u ${{ secrets.DOCKER_USER }} -p ${{ secrets.DOCKER_ACCESS_TOKEN }}
48-
docker push ${{ env.IMAGE_NAME }}:$VERSION
71+
- name: Build and push
72+
uses: docker/build-push-action@v3
73+
with:
74+
platforms: linux/amd64,linux/arm/v7,linux/arm64/v8,linux/ppc64le,linux/s390x
75+
push: true
76+
tags: ${{ env.IMAGE_ID }}:${{ env.VERSION }}
77+
build-args: |
78+
imageVersion=${{ env.VERSION }}
79+
buildId=${{ env.BUILD_ID }}
80+
commitSha=${{ env.GIT_COMMIT }}

0 commit comments

Comments
 (0)