Skip to content

Commit e6197b4

Browse files
authored
Push multi-arch images (opendatahub-io#80)
* Exclude 32bit arm and s390x builds * Use single workflow definition for pull-request and push event * Delete pull-request-validation.yml * Add layer caching * Add TARGETARCH arg to Dockerfile Signed-off-by: ddelange <[email protected]>
1 parent 38c1385 commit e6197b4

File tree

3 files changed

+49
-56
lines changed

3 files changed

+49
-56
lines changed

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

Lines changed: 44 additions & 16 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:
@@ -20,29 +21,56 @@ jobs:
2021
run: sudo ./.github/install-etcd.sh
2122
- name: Build with Maven
2223
run: mvn -B package --file pom.xml
24+
2325
build:
2426
needs: test
2527
runs-on: ubuntu-latest
28+
2629
env:
2730
IMAGE_NAME: kserve/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+
if: github.event_name == 'push'
43+
uses: docker/login-action@v2
44+
with:
45+
username: ${{ secrets.DOCKER_USER }}
46+
password: ${{ secrets.DOCKER_ACCESS_TOKEN }}
47+
48+
- name: Export version variables
49+
run: |
50+
GIT_COMMIT=$(git rev-parse HEAD)
51+
BUILD_ID=$(date '+%Y%m%d')-$(git rev-parse HEAD | cut -c -5)
3452
35-
# Strip git ref prefix from version
36-
VERSION=$(echo "${{ github.ref }}" | sed -e 's,.*/\(.*\),\1,')
53+
# Strip git ref prefix from version
54+
VERSION=$(echo "${{ github.ref }}" | sed -e 's,.*/\(.*\),\1,')
3755
38-
# Use Docker `latest` tag convention
39-
[ "$VERSION" == "main" ] && VERSION=latest
40-
echo $VERSION
56+
# Use Docker `latest` tag convention
57+
[ "$VERSION" == "main" ] && VERSION=latest
4158
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} .
59+
echo "GIT_COMMIT=$GIT_COMMIT" >> $GITHUB_ENV
60+
echo "BUILD_ID=$BUILD_ID" >> $GITHUB_ENV
61+
echo "VERSION=$VERSION" >> $GITHUB_ENV
4662
47-
docker login -u ${{ secrets.DOCKER_USER }} -p ${{ secrets.DOCKER_ACCESS_TOKEN }}
48-
docker push ${{ env.IMAGE_NAME }}:$VERSION
63+
- name: Build and push
64+
uses: docker/build-push-action@v3
65+
with:
66+
# for linux/s390x, maven errors due to missing io.grpc:protoc-gen-grpc-java:exe:linux-s390_64:1.51.1
67+
platforms: linux/amd64,linux/arm64/v8,linux/ppc64le
68+
pull: true
69+
cache-from: type=gha
70+
cache-to: type=gha,mode=max
71+
push: ${{ github.event_name == 'push' }}
72+
tags: ${{ env.IMAGE_NAME }}:${{ env.VERSION }}
73+
build-args: |
74+
imageVersion=${{ env.VERSION }}
75+
buildId=${{ env.BUILD_ID }}
76+
commitSha=${{ env.GIT_COMMIT }}

.github/workflows/pull-request-validation.yml

Lines changed: 0 additions & 38 deletions
This file was deleted.

Dockerfile

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@
1414

1515
FROM registry.access.redhat.com/ubi8/ubi-minimal:8.6 as build_base
1616

17+
# https://blog.thesparktree.com/docker-multi-arch-github-actions#architecture-specific-dockerfile-instructions
18+
ARG TARGETARCH=amd64
19+
1720
ARG ETCD_VERSION=v3.5.4
1821

1922
LABEL image="build_base"
@@ -33,9 +36,9 @@ RUN microdnf install wget tar gzip maven
3336
ENV JAVA_HOME=/usr/lib/jvm/java-17-openjdk
3437

3538
# Install etcd -- used for CI tests
36-
RUN wget -q https://github.com/etcd-io/etcd/releases/download/${ETCD_VERSION}/etcd-${ETCD_VERSION}-linux-amd64.tar.gz && \
39+
RUN wget -q https://github.com/etcd-io/etcd/releases/download/${ETCD_VERSION}/etcd-${ETCD_VERSION}-linux-${TARGETARCH}.tar.gz && \
3740
mkdir -p /usr/lib/etcd && \
38-
tar xzf etcd-*-linux-amd64.tar.gz -C /usr/lib/etcd --strip-components=1 --no-same-owner && \
41+
tar xzf etcd-*-linux-${TARGETARCH}.tar.gz -C /usr/lib/etcd --strip-components=1 --no-same-owner && \
3942
rm -rf etcd*.gz
4043

4144
ENV PATH="/usr/lib/etcd:$PATH"

0 commit comments

Comments
 (0)