Skip to content

Commit

Permalink
feat: support for multiarch images
Browse files Browse the repository at this point in the history
This commit alters the Dockerfile for both regular and OpenShift in such
a way multiarch images are getting built when using buildkit. Also, the
GH workflow actually building the images is prepared for that.

Fixes k8snetworkplumbingwg#226

Signed-off-by: Jorik Jonker <jorik.jonker@eu.equinix.com>
  • Loading branch information
jonkerj committed Apr 18, 2023
1 parent e12772b commit 2438126
Show file tree
Hide file tree
Showing 7 changed files with 26 additions and 114 deletions.
31 changes: 7 additions & 24 deletions .github/workflows/image-build.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
name: Image build
on: [pull_request]
jobs:
build-amd64:
name: Image build/amd64
build-multiarch:
name: Image build
runs-on: ubuntu-latest
steps:
- name: Check out code into the Go module directory
Expand All @@ -16,30 +16,13 @@ jobs:
with:
context: .
push: false
tags: ghcr.io/${{ github.repository }}:latest-amd64
tags: ghcr.io/${{ github.repository }}:latest
file: Dockerfile
platforms: [linux/arm64, linux/amd64]

build-openshift:
name: Image build/openshift
runs-on: ubuntu-latest
steps:
- name: Check out code into the Go module directory
uses: actions/checkout@v2

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v1

- name: Build container image
uses: docker/build-push-action@v2
with:
context: .
push: false
tags: k8snetworkplumbingwg/whereabouts-ocp
file: Dockerfile.openshift

build-arm64:
name: Image build/arm64
runs-on: ubuntu-latest
steps:
- name: Check out code into the Go module directory
uses: actions/checkout@v2
Expand All @@ -55,6 +38,6 @@ jobs:
with:
context: .
push: false
tags: ghcr.io/${{ github.repository }}:latest-arm64
file: Dockerfile.arm64
platforms: linux/arm64
tags: k8snetworkplumbingwg/whereabouts-ocp
file: Dockerfile.openshift
platforms: [linux/arm64, linux/amd64]
29 changes: 5 additions & 24 deletions .github/workflows/image-push-master.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ on:
env:
image-push-owner: 'k8snetworkplumbingwg'
jobs:
push-amd64:
name: Image push/amd64
push:
name: Image push
runs-on: ubuntu-latest
steps:
- name: Check out code into the Go module directory
Expand All @@ -30,8 +30,9 @@ jobs:
with:
context: .
push: true
tags: ghcr.io/${{ github.repository }}:latest-amd64
tags: ghcr.io/${{ github.repository }}:latest
file: Dockerfile
platforms: linux/arm64,linux/amd64

push-origin:
name: Image push/origin
Expand Down Expand Up @@ -59,24 +60,4 @@ jobs:
push: true
tags: ghcr.io/${{ github.repository }}:latest-ocp
file: Dockerfile.openshift

push-arm64:
name: Image build/arm64
runs-on: ubuntu-latest
steps:
- name: Check out code into the Go module directory
uses: actions/checkout@v2

- name: Set up QEMU
uses: docker/setup-qemu-action@v2

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v1

- name: Build container image
uses: docker/build-push-action@v2
with:
context: .
push: true
tags: ghcr.io/${{ github.repository }}:latest-arm64
file: Dockerfile.arm64
platforms: linux/arm64,linux/amd64
44 changes: 3 additions & 41 deletions .github/workflows/image-push-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ env:
image-push-owner: 'k8snetworkplumbingwg'
jobs:
push-amd64:
name: Image push/amd64
name: Image push
runs-on: ubuntu-latest
steps:
- name: Check out code into the Go module directory
Expand Down Expand Up @@ -38,44 +38,6 @@ jobs:
context: .
push: true
tags: |
${{ steps.docker_meta.outputs.tags }}-amd64
${{ steps.docker_meta.outputs.tags }}
file: Dockerfile

push-arm64:
name: Image push/arm64
runs-on: ubuntu-latest
steps:
- name: Check out code into the Go module directory
uses: actions/checkout@v2

- name: Set up QEMU
uses: docker/setup-qemu-action@v2

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v1

- name: Login to Container Registry
if: github.repository_owner == 'k8snetworkplumbingwg'
uses: docker/login-action@v1
with:
registry: ghcr.io
username: ${{ github.repository_owner }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Docker meta
id: docker_meta
uses: crazy-max/ghaction-docker-meta@v1
with:
images: ghcr.io/${{ github.repository }}
tag-latest: false

- name: Push container image
if: github.repository_owner == 'k8snetworkplumbingwg'
uses: docker/build-push-action@v2
with:
context: .
push: true
tags: |
${{ steps.docker_meta.outputs.tags }}-arm64
file: Dockerfile
platforms: linux/arm64
platforms: linux/arm64,linux/amd64
9 changes: 5 additions & 4 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
FROM golang:1.19
FROM --platform=$BUILDPLATFORM golang:1.19 as builder
ADD . /usr/src/whereabouts
RUN mkdir -p $GOPATH/src/github.com/k8snetworkplumbingwg/whereabouts
WORKDIR $GOPATH/src/github.com/k8snetworkplumbingwg/whereabouts
COPY . .
RUN ./hack/build-go.sh
ARG TARGETOS TARGETARCH
RUN GOOS=$TARGETOS GOARCH=$TARGETARCH ./hack/build-go.sh

FROM alpine:latest
LABEL org.opencontainers.image.source https://github.com/k8snetworkplumbingwg/whereabouts
COPY --from=0 /go/src/github.com/k8snetworkplumbingwg/whereabouts/bin/whereabouts .
COPY --from=0 /go/src/github.com/k8snetworkplumbingwg/whereabouts/bin/ip-control-loop .
COPY --from=builder /go/src/github.com/k8snetworkplumbingwg/whereabouts/bin/whereabouts .
COPY --from=builder /go/src/github.com/k8snetworkplumbingwg/whereabouts/bin/ip-control-loop .
COPY script/install-cni.sh .
CMD ["/install-cni.sh"]
17 changes: 0 additions & 17 deletions Dockerfile.arm64

This file was deleted.

9 changes: 5 additions & 4 deletions Dockerfile.openshift
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
# This dockerfile is used for building for OpenShift
FROM registry.ci.openshift.org/openshift/release:golang-1.19 as builder
FROM --platform=$BUILDPLATFORM registry.ci.openshift.org/openshift/release:golang-1.19 as builder
ADD . /go/src/github.com/k8snetworkplumbingwg/whereabouts
WORKDIR /go/src/github.com/k8snetworkplumbingwg/whereabouts
ENV CGO_ENABLED=1
ENV CGO_ENABLED=0
ENV GO111MODULE=on
RUN go build -mod vendor -o bin/whereabouts cmd/whereabouts.go
RUN go build -mod vendor -o bin/ip-control-loop cmd/controlloop/controlloop.go
ARG TARGETARCH TARGETOS
RUN GOOS=$TARGETOS GOARCH=$TARGETARCH go build -mod vendor -o bin/whereabouts cmd/whereabouts.go
RUN GOOS=$TARGETOS GOARCH=$TARGETARCH go build -mod vendor -o bin/ip-control-loop cmd/controlloop/controlloop.go
WORKDIR /

FROM openshift/origin-base
Expand Down
1 change: 1 addition & 0 deletions hack/build-go.sh
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ echo "VERSION: ${VERSION}"
echo "GIT_SHA: ${GIT_SHA}"
echo "GIT_TREE_STATE: ${GIT_TREE_STATE}"
echo "RELEASE_STATUS: ${RELEASE_STATUS}"
echo "PLATFORM: ${GOOS}/${GOARCH}"
VERSION_LDFLAGS="-X github.com/k8snetworkplumbingwg/whereabouts/pkg/version.Version=${VERSION} \
-X github.com/k8snetworkplumbingwg/whereabouts/pkg/version.GitSHA=${GIT_SHA} \
-X github.com/k8snetworkplumbingwg/whereabouts/pkg/version.GitTreeState=${GIT_TREE_STATE} \
Expand Down

0 comments on commit 2438126

Please sign in to comment.