Skip to content

Commit

Permalink
Add multiarch image build support using github actions.
Browse files Browse the repository at this point in the history
These changes enable the building of the Multus Dynamic CNI image
for multiple platforms (amd64, arm64, s390x) from a single Dockerfile

Signed-off-by: Ashok Pariya <[email protected]>
  • Loading branch information
ashokpariya0 authored and maiqueb committed Dec 2, 2024
1 parent a2f19b7 commit d765a56
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 6 deletions.
9 changes: 6 additions & 3 deletions .github/workflows/image-push.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,10 @@ on:
- 'v*.*.*'
env:
image-push-owner: 'k8snetworkplumbingwg'
BUILD_PLATFORMS: linux/amd64,linux/arm64,linux/s390x
jobs:
push-amd64:
name: Image push/amd64
push-image:
name: Image push
runs-on: ubuntu-latest
steps:
- name: Check out code into the Go module directory
Expand All @@ -36,8 +37,9 @@ jobs:
with:
context: .
push: true
tags: ghcr.io/${{ github.repository }}:latest-amd64
tags: ghcr.io/${{ github.repository }}:latest
file: images/Dockerfile
platforms: ${{ env.BUILD_PLATFORMS }}
build-args: |
git_sha=${{ env.git_commit_hash }}
Expand All @@ -49,6 +51,7 @@ jobs:
push: true
tags: ghcr.io/${{ github.repository }}:${{ github.ref_name }}
file: images/Dockerfile
platforms: ${{ env.BUILD_PLATFORMS }}
build-args: |
git_sha=${{ env.git_commit_hash }}
Expand Down
11 changes: 8 additions & 3 deletions images/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,11 +1,16 @@
FROM quay.io/projectquay/golang:1.22 as builder
FROM --platform=$BUILDPLATFORM quay.io/projectquay/golang:1.22 AS builder
ENV GOPATH=/go
ARG TARGETOS
ARG TARGETARCH
ENV TARGETOS=${TARGETOS:-linux}
ENV TARGETARCH=${TARGETARCH:-amd64}

RUN mkdir -p $GOPATH/src/github.com/maiqueb/multus-dynamic-networks-controller
WORKDIR $GOPATH/src/github.com/maiqueb/multus-dynamic-networks-controller
COPY . .
RUN GOOS=linux CGO_ENABLED=0 go build -o /dynamic-networks-controller ./cmd/dynamic-networks-controller
RUN GOOS=${TARGETOS} GOARCH=${TARGETARCH} CGO_ENABLED=0 go build -o /dynamic-networks-controller ./cmd/dynamic-networks-controller

FROM registry.access.redhat.com/ubi8/ubi-minimal
FROM --platform=linux/${TARGETARCH} registry.access.redhat.com/ubi8/ubi-minimal
COPY --from=builder /dynamic-networks-controller /dynamic-networks-controller

ARG git_url=https://github.com/k8snetworkplumbingwg/multus-dynamic-networks-controller.git
Expand Down

0 comments on commit d765a56

Please sign in to comment.