From fac6b2bab54db8e0b3b874dc9f3c528d22555d04 Mon Sep 17 00:00:00 2001 From: Jorik Jonker Date: Tue, 18 Apr 2023 09:58:03 +0200 Subject: [PATCH 1/5] feat: support for multiarch images 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 #226 Signed-off-by: Jorik Jonker --- .github/workflows/image-build.yml | 31 ++++------------- .github/workflows/image-push-master.yml | 32 +++++------------ .github/workflows/image-push-release.yml | 44 ++---------------------- Dockerfile | 9 ++--- Dockerfile.arm64 | 17 --------- Dockerfile.openshift | 9 ++--- hack/build-go.sh | 1 + hack/e2e-setup-kind-cluster.sh | 2 +- 8 files changed, 30 insertions(+), 115 deletions(-) delete mode 100644 Dockerfile.arm64 diff --git a/.github/workflows/image-build.yml b/.github/workflows/image-build.yml index 8a3b1634c..b863573af 100644 --- a/.github/workflows/image-build.yml +++ b/.github/workflows/image-build.yml @@ -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 @@ -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 @@ -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 diff --git a/.github/workflows/image-push-master.yml b/.github/workflows/image-push-master.yml index 685ca29a6..b82d17d2c 100644 --- a/.github/workflows/image-push-master.yml +++ b/.github/workflows/image-push-master.yml @@ -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 @@ -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 @@ -40,6 +41,9 @@ jobs: - 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 @@ -59,24 +63,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 diff --git a/.github/workflows/image-push-release.yml b/.github/workflows/image-push-release.yml index e3159033f..70584baa6 100644 --- a/.github/workflows/image-push-release.yml +++ b/.github/workflows/image-push-release.yml @@ -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 @@ -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 diff --git a/Dockerfile b/Dockerfile index b44309955..4ababbf23 100644 --- a/Dockerfile +++ b/Dockerfile @@ -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"] diff --git a/Dockerfile.arm64 b/Dockerfile.arm64 deleted file mode 100644 index 0b1c7fd54..000000000 --- a/Dockerfile.arm64 +++ /dev/null @@ -1,17 +0,0 @@ -FROM golang:1.19 -ADD . /usr/src/whereabouts - -ENV GOARCH "arm64" -ENV GOOS "linux" - -RUN mkdir -p $GOPATH/src/github.com/k8snetworkplumbingwg/whereabouts -WORKDIR $GOPATH/src/github.com/k8snetworkplumbingwg/whereabouts -COPY . . -RUN ./hack/build-go.sh - -FROM arm64v8/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 script/install-cni.sh . -CMD ["/install-cni.sh"] diff --git a/Dockerfile.openshift b/Dockerfile.openshift index b6fa401e7..c8d91338d 100644 --- a/Dockerfile.openshift +++ b/Dockerfile.openshift @@ -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 diff --git a/hack/build-go.sh b/hack/build-go.sh index 0d615169e..f3644f774 100755 --- a/hack/build-go.sh +++ b/hack/build-go.sh @@ -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} \ diff --git a/hack/e2e-setup-kind-cluster.sh b/hack/e2e-setup-kind-cluster.sh index c03d40ef1..419788007 100755 --- a/hack/e2e-setup-kind-cluster.sh +++ b/hack/e2e-setup-kind-cluster.sh @@ -89,7 +89,7 @@ retry kubectl create -f "${CNIS_DAEMONSET_PATH}" retry kubectl -n kube-system wait --for=condition=ready -l name="cni-plugins" pod --timeout=$TIMEOUT_K8 echo "## build whereabouts" pushd "$ROOT" -$OCI_BIN build . -t "$IMG_NAME" +$OCI_BIN buildx build --load . -t "$IMG_NAME" popd echo "## load image into KinD" From 51bd6827ac88cd2f1426a17163b1cc52e9f85b89 Mon Sep 17 00:00:00 2001 From: Jorik Jonker Date: Tue, 18 Apr 2023 10:46:18 +0200 Subject: [PATCH 2/5] feat: also build/push in forks This is needed to test/use the workflow in forks. Signed-off-by: Jorik Jonker --- .github/workflows/image-push-master.yml | 8 ++------ .github/workflows/image-push-release.yml | 4 +--- 2 files changed, 3 insertions(+), 9 deletions(-) diff --git a/.github/workflows/image-push-master.yml b/.github/workflows/image-push-master.yml index b82d17d2c..ed29fc5c7 100644 --- a/.github/workflows/image-push-master.yml +++ b/.github/workflows/image-push-master.yml @@ -17,15 +17,13 @@ jobs: 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 }} + username: ${{ github.actor }} password: ${{ secrets.GITHUB_TOKEN }} - name: Push container image - if: github.repository_owner == 'k8snetworkplumbingwg' uses: docker/build-push-action@v2 with: context: . @@ -48,15 +46,13 @@ jobs: 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 }} + username: ${{ github.actor }} password: ${{ secrets.GITHUB_TOKEN }} - name: Push container image - if: github.repository_owner == 'k8snetworkplumbingwg' uses: docker/build-push-action@v2 with: context: . diff --git a/.github/workflows/image-push-release.yml b/.github/workflows/image-push-release.yml index 70584baa6..114f5ecdf 100644 --- a/.github/workflows/image-push-release.yml +++ b/.github/workflows/image-push-release.yml @@ -17,11 +17,10 @@ jobs: 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 }} + username: ${{ github.actor }} password: ${{ secrets.GITHUB_TOKEN }} - name: Docker meta @@ -32,7 +31,6 @@ jobs: tag-latest: false - name: Push container image - if: github.repository_owner == 'k8snetworkplumbingwg' uses: docker/build-push-action@v2 with: context: . From 7f6b5e4c357997d8391d08ef4350a13c5b036904 Mon Sep 17 00:00:00 2001 From: Jorik Jonker Date: Tue, 18 Apr 2023 10:35:19 +0200 Subject: [PATCH 3/5] commit to trigger a build --- .github/workflows/image-build.yml | 2 +- .github/workflows/image-push-master.yml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/image-build.yml b/.github/workflows/image-build.yml index b863573af..1eddebd2f 100644 --- a/.github/workflows/image-build.yml +++ b/.github/workflows/image-build.yml @@ -1,5 +1,5 @@ name: Image build -on: [pull_request] +on: [push] jobs: build-multiarch: name: Image build diff --git a/.github/workflows/image-push-master.yml b/.github/workflows/image-push-master.yml index ed29fc5c7..6820dbc36 100644 --- a/.github/workflows/image-push-master.yml +++ b/.github/workflows/image-push-master.yml @@ -2,7 +2,7 @@ name: Image push for master on: push: branches: - - master + - improved-images env: image-push-owner: 'k8snetworkplumbingwg' jobs: From 9c5c6d506bf26786798d8efd7cf3f8d160c7b3ad Mon Sep 17 00:00:00 2001 From: Jorik Jonker Date: Tue, 18 Apr 2023 10:55:51 +0200 Subject: [PATCH 4/5] feat: updated GH actions Some were giving warnings about deprecated features Signed-off-by: Jorik Jonker --- .github/workflows/binaries-upload-release.yml | 2 +- .github/workflows/build.yml | 4 ++-- .github/workflows/image-build.yml | 12 ++++++------ .github/workflows/image-push-master.yml | 14 +++++++------- .github/workflows/image-push-release.yml | 8 ++++---- .github/workflows/test.yml | 8 ++++---- 6 files changed, 24 insertions(+), 24 deletions(-) diff --git a/.github/workflows/binaries-upload-release.yml b/.github/workflows/binaries-upload-release.yml index a5579a9ce..66cd9947e 100644 --- a/.github/workflows/binaries-upload-release.yml +++ b/.github/workflows/binaries-upload-release.yml @@ -11,7 +11,7 @@ jobs: matrix: arch: [amd64, arm64, arm] steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v3 - name: Build whereabouts binary env: GOARCH: ${{ matrix.arch }} diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 9786115f3..efe5e74cc 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -11,12 +11,12 @@ jobs: runs-on: ${{ matrix.os }} steps: - name: Install Go - uses: actions/setup-go@v2 + uses: actions/setup-go@v4 with: go-version: ${{ matrix.go-version }} - name: Checkout code - uses: actions/checkout@v2 + uses: actions/checkout@v3 - name: Install kubebuilder tools run: ./hack/install-kubebuilder-tools.sh diff --git a/.github/workflows/image-build.yml b/.github/workflows/image-build.yml index 1eddebd2f..bef51585d 100644 --- a/.github/workflows/image-build.yml +++ b/.github/workflows/image-build.yml @@ -6,13 +6,13 @@ jobs: runs-on: ubuntu-latest steps: - name: Check out code into the Go module directory - uses: actions/checkout@v2 + uses: actions/checkout@v3 - name: Set up Docker Buildx - uses: docker/setup-buildx-action@v1 + uses: docker/setup-buildx-action@v2 - name: Build container image - uses: docker/build-push-action@v2 + uses: docker/build-push-action@v4 with: context: . push: false @@ -25,16 +25,16 @@ jobs: runs-on: ubuntu-latest steps: - name: Check out code into the Go module directory - uses: actions/checkout@v2 + uses: actions/checkout@v3 - name: Set up QEMU uses: docker/setup-qemu-action@v2 - name: Set up Docker Buildx - uses: docker/setup-buildx-action@v1 + uses: docker/setup-buildx-action@v2 - name: Build container image - uses: docker/build-push-action@v2 + uses: docker/build-push-action@v4 with: context: . push: false diff --git a/.github/workflows/image-push-master.yml b/.github/workflows/image-push-master.yml index 6820dbc36..20a81ba60 100644 --- a/.github/workflows/image-push-master.yml +++ b/.github/workflows/image-push-master.yml @@ -11,20 +11,20 @@ jobs: runs-on: ubuntu-latest steps: - name: Check out code into the Go module directory - uses: actions/checkout@v2 + uses: actions/checkout@v3 - name: Set up Docker Buildx - uses: docker/setup-buildx-action@v1 + uses: docker/setup-buildx-action@v2 - name: Login to Container Registry - uses: docker/login-action@v1 + uses: docker/login-action@v2 with: registry: ghcr.io username: ${{ github.actor }} password: ${{ secrets.GITHUB_TOKEN }} - name: Push container image - uses: docker/build-push-action@v2 + uses: docker/build-push-action@v4 with: context: . push: true @@ -43,17 +43,17 @@ jobs: uses: docker/setup-qemu-action@v2 - name: Set up Docker Buildx - uses: docker/setup-buildx-action@v1 + uses: docker/setup-buildx-action@v2 - name: Login to Container Registry - uses: docker/login-action@v1 + uses: docker/login-action@v2 with: registry: ghcr.io username: ${{ github.actor }} password: ${{ secrets.GITHUB_TOKEN }} - name: Push container image - uses: docker/build-push-action@v2 + uses: docker/build-push-action@v4 with: context: . push: true diff --git a/.github/workflows/image-push-release.yml b/.github/workflows/image-push-release.yml index 114f5ecdf..042e2a751 100644 --- a/.github/workflows/image-push-release.yml +++ b/.github/workflows/image-push-release.yml @@ -11,13 +11,13 @@ jobs: runs-on: ubuntu-latest steps: - name: Check out code into the Go module directory - uses: actions/checkout@v2 + uses: actions/checkout@v3 - name: Set up Docker Buildx - uses: docker/setup-buildx-action@v1 + uses: docker/setup-buildx-action@v2 - name: Login to Container Registry - uses: docker/login-action@v1 + uses: docker/login-action@v2 with: registry: ghcr.io username: ${{ github.actor }} @@ -31,7 +31,7 @@ jobs: tag-latest: false - name: Push container image - uses: docker/build-push-action@v2 + uses: docker/build-push-action@v4 with: context: . push: true diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index deb9c429a..4d3da839f 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -9,12 +9,12 @@ jobs: runs-on: ${{ matrix.os }} steps: - name: Install Go - uses: actions/setup-go@v2 + uses: actions/setup-go@v4 with: go-version: ${{ matrix.go-version }} - name: Checkout code - uses: actions/checkout@v2 + uses: actions/checkout@v3 - name: Get all changed files excluding docs and README id: changed-files @@ -72,12 +72,12 @@ jobs: NUMBER_OF_COMPUTE_NODES: 5 steps: - name: Set up Go version - uses: actions/setup-go@v1 + uses: actions/setup-go@v4 with: go-version: 1.19.x - name: Checkout code into the Go module directory - uses: actions/checkout@v2 + uses: actions/checkout@v3 - name: Get all changed files excluding docs and README id: changed-files From b77bbe56ea850834d7a2bd064d65b2388e63a759 Mon Sep 17 00:00:00 2001 From: Jorik Jonker Date: Tue, 18 Apr 2023 11:02:25 +0200 Subject: [PATCH 5/5] feat: clarify push jobs Signed-off-by: Jorik Jonker --- .github/workflows/image-push-master.yml | 2 +- .github/workflows/image-push-release.yml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/image-push-master.yml b/.github/workflows/image-push-master.yml index 20a81ba60..58743c032 100644 --- a/.github/workflows/image-push-master.yml +++ b/.github/workflows/image-push-master.yml @@ -7,7 +7,7 @@ env: image-push-owner: 'k8snetworkplumbingwg' jobs: push: - name: Image push + name: Image push/ghcr runs-on: ubuntu-latest steps: - name: Check out code into the Go module directory diff --git a/.github/workflows/image-push-release.yml b/.github/workflows/image-push-release.yml index 042e2a751..d400fee95 100644 --- a/.github/workflows/image-push-release.yml +++ b/.github/workflows/image-push-release.yml @@ -7,7 +7,7 @@ env: image-push-owner: 'k8snetworkplumbingwg' jobs: push-amd64: - name: Image push + name: Image push/ghcr runs-on: ubuntu-latest steps: - name: Check out code into the Go module directory