From 641c319eb8dbb503b27c512f2db96fbbaf0da955 Mon Sep 17 00:00:00 2001 From: David Shay Date: Tue, 7 Jun 2022 01:23:36 -0500 Subject: [PATCH] Added support for multi-arch image build (#496) * Added support for multi-arch image build * Requested changes to multi-arch build * Further optimizations of multi build * multi needs QEMU for some pieces * change main push for all platforms * Update Dockerfile to call Makefile * Remove manual workflow --- .github/workflows/on-main-push.yaml | 26 ++++++++++++++++++++------ .github/workflows/on-tag.yaml | 22 +++++++++++++++++++--- Makefile | 5 ++++- cmd/kured/Dockerfile.multi | 20 ++++++++++++++++++++ 4 files changed, 63 insertions(+), 10 deletions(-) create mode 100644 cmd/kured/Dockerfile.multi diff --git a/.github/workflows/on-main-push.yaml b/.github/workflows/on-main-push.yaml index d41e8a4..ce805fa 100644 --- a/.github/workflows/on-main-push.yaml +++ b/.github/workflows/on-main-push.yaml @@ -36,10 +36,24 @@ jobs: username: weave-ghcr-bot password: ${{ secrets.KURED_WEAVE_GHCR_BOT_TOKEN }} - - name: Build image - run: | - make DH_ORG="${{ github.repository_owner }}" image + - name: Set up QEMU + uses: docker/setup-qemu-action@v1 - - name: Publish image - run: | - make DH_ORG="${{ github.repository_owner }}" publish-image + - name: Set up Docker Buildx + id: buildx + uses: docker/setup-buildx-action@v1 + + - name: Find current tag version + run: echo "::set-output name=sha_short::$(git rev-parse --short HEAD)" + id: tags + + - name: Build image + uses: docker/build-push-action@v2 + with: + context: . + file: cmd/kured/Dockerfile.multi + platforms: linux/arm64, linux/amd64, linux/arm/v7, linux/arm/v6, linux/386 + push: true + tags: | + docker.io/${{ GITHUB.REPOSITORY }}:main-${{ steps.tags.outputs.sha_short }} + ghcr.io/${{ GITHUB.REPOSITORY }}:main-${{ steps.tags.outputs.sha_short }} diff --git a/.github/workflows/on-tag.yaml b/.github/workflows/on-tag.yaml index 52086d6..7276df1 100644 --- a/.github/workflows/on-tag.yaml +++ b/.github/workflows/on-tag.yaml @@ -44,6 +44,22 @@ jobs: username: weave-ghcr-bot password: ${{ secrets.KURED_WEAVE_GHCR_BOT_TOKEN }} - - name: Publish image - run: | - make DH_ORG="${{ github.repository_owner }}" VERSION="${{ steps.tags.outputs.version }}" publish-image + - name: Set up QEMU + uses: docker/setup-qemu-action@v1 + + - name: Set up Docker Buildx + id: buildx + uses: docker/setup-buildx-action@v1 + + - name: Build image + uses: docker/build-push-action@v2 + with: + context: . + file: cmd/kured/Dockerfile.multi + platforms: linux/arm64, linux/amd64, linux/arm/v7, linux/arm/v6, linux/386 + push: true +# cache-from: type=registry,ref=user/app:buildcache +# cache-to: type=inline + tags: | + docker.io/${{ GITHUB.REPOSITORY }}:${{ steps.tags.outputs.version }} + ghcr.io/${{ GITHUB.REPOSITORY }}:${{ steps.tags.outputs.version }} diff --git a/Makefile b/Makefile index af5ef05..111713f 100644 --- a/Makefile +++ b/Makefile @@ -1,5 +1,5 @@ .DEFAULT: all -.PHONY: all clean image publish-image minikube-publish manifest helm-chart test tests +.PHONY: all clean image publish-image minikube-publish manifest helm-chart test tests kured-multi DH_ORG=weaveworks VERSION=$(shell git symbolic-ref --short HEAD)-$(shell git rev-parse --short HEAD) @@ -19,6 +19,9 @@ cmd/kured/kured: $(DEPS) cmd/kured/kured: cmd/kured/*.go CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -ldflags "-X main.version=$(VERSION)" -o $@ cmd/kured/*.go +kured-multi: + CGO_ENABLED=0 go build -ldflags "-X main.version=$(VERSION)" -o cmd/kured/kured cmd/kured/*.go + build/.image.done: cmd/kured/Dockerfile cmd/kured/kured mkdir -p build cp $^ build diff --git a/cmd/kured/Dockerfile.multi b/cmd/kured/Dockerfile.multi new file mode 100644 index 0000000..bad0ddf --- /dev/null +++ b/cmd/kured/Dockerfile.multi @@ -0,0 +1,20 @@ +FROM --platform=$BUILDPLATFORM golang:bullseye AS build + +ARG TARGETOS +ARG TARGETARCH +ARG TARGETVARIANT + +ENV GOOS=$TARGETOS +ENV GOARCH=$TARGETARCH +ENV GOVARIANT=$TARGETVARIANT + +WORKDIR /src +COPY go.mod go.sum . +RUN go mod download +COPY . . +RUN make kured-multi + +FROM --platform=$TARGETPLATFORM alpine:3.15.1 as bin +RUN apk update --no-cache && apk upgrade --no-cache && apk add --no-cache ca-certificates tzdata +COPY --from=build /src/cmd/kured/kured /usr/bin/kured +ENTRYPOINT ["/usr/bin/kured"]