From 42c0ffb7ea8048aa353a71aaa2edae994041f150 Mon Sep 17 00:00:00 2001 From: Noel Georgi Date: Mon, 5 Sep 2022 22:39:24 +0530 Subject: [PATCH] fix: multi arch build Builds and pushes for arm64 Signed-off-by: Noel Georgi --- .drone.yml | 3 ++- .kres.yaml | 8 ++++++++ Dockerfile | 36 ++++++++++++++++++++++++++++++------ Makefile | 20 +++++++++++++++++--- hack/test/Dockerfile | 2 -- 5 files changed, 57 insertions(+), 12 deletions(-) delete mode 100644 hack/test/Dockerfile diff --git a/.drone.yml b/.drone.yml index d46c34c..2cf7e76 100644 --- a/.drone.yml +++ b/.drone.yml @@ -1,7 +1,7 @@ --- # THIS FILE WAS AUTOMATICALLY GENERATED, PLEASE DO NOT EDIT. # -# Generated on 2022-08-31T21:37:24Z by kres ec2cd64. +# Generated on 2022-09-05T17:11:08Z by kres 871f67c. kind: pipeline type: kubernetes @@ -169,6 +169,7 @@ steps: from_secret: ghcr_token GHCR_USERNAME: from_secret: ghcr_username + PLATFORM: linux/amd64,linux/arm64 PUSH: true volumes: - name: outer-docker-socket diff --git a/.kres.yaml b/.kres.yaml index abb7138..908cae3 100644 --- a/.kres.yaml +++ b/.kres.yaml @@ -3,6 +3,8 @@ kind: common.Image name: image-bldr spec: pushLatest: false + droneExtraEnvironment: + PLATFORM: linux/amd64,linux/arm64 entrypointArgs: - frontend --- @@ -15,6 +17,12 @@ spec: linux-arm64: GOOS: linux GOARCH: arm64 + darwin-amd64: + GOOS: darwin + GOARCH: amd64 + darwin-arm64: + GOOS: darwin + GOARCH: arm64 --- kind: auto.CustomSteps spec: diff --git a/Dockerfile b/Dockerfile index af9a86a..0ee3f40 100644 --- a/Dockerfile +++ b/Dockerfile @@ -2,21 +2,21 @@ # THIS FILE WAS AUTOMATICALLY GENERATED, PLEASE DO NOT EDIT. # -# Generated on 2022-08-31T21:36:31Z by kres ec2cd64. +# Generated on 2022-09-05T17:08:38Z by kres 871f67c. ARG TOOLCHAIN # cleaned up specs and compiled versions FROM scratch AS generate -FROM ghcr.io/siderolabs/ca-certificates:v1.1.0 AS image-ca-certificates +FROM ghcr.io/siderolabs/ca-certificates:v1.2.0 AS image-ca-certificates -FROM ghcr.io/siderolabs/fhs:v1.1.0 AS image-fhs +FROM ghcr.io/siderolabs/fhs:v1.2.0 AS image-fhs # runs markdownlint -FROM docker.io/node:18.7.0-alpine3.16 AS lint-markdown +FROM docker.io/node:18.8.0-alpine3.16 AS lint-markdown WORKDIR /src -RUN npm i -g markdownlint-cli@0.31.1 +RUN npm i -g markdownlint-cli@0.32.2 RUN npm i sentences-per-line@0.2.1 COPY .markdownlint.json . COPY ./README.md ./README.md @@ -27,7 +27,7 @@ FROM ${TOOLCHAIN} AS toolchain RUN apk --update --no-cache add bash curl build-base protoc protobuf-dev # build tools -FROM toolchain AS tools +FROM --platform=${BUILDPLATFORM} toolchain AS tools ENV GO111MODULE on ENV CGO_ENABLED 0 ENV GOPATH /go @@ -55,6 +55,24 @@ COPY ./cmd ./cmd COPY ./internal ./internal RUN --mount=type=cache,target=/go/pkg go list -mod=readonly all >/dev/null +# builds bldr-darwin-amd64 +FROM base AS bldr-darwin-amd64-build +COPY --from=generate / / +WORKDIR /src/cmd/bldr +ARG VERSION_PKG="github.com/siderolabs/bldr/internal/version" +ARG SHA +ARG TAG +RUN --mount=type=cache,target=/root/.cache/go-build --mount=type=cache,target=/go/pkg GOARCH=amd64 GOOS=darwin go build -ldflags "-s -w -X ${VERSION_PKG}.Name=bldr -X ${VERSION_PKG}.SHA=${SHA} -X ${VERSION_PKG}.Tag=${TAG}" -o /bldr-darwin-amd64 + +# builds bldr-darwin-arm64 +FROM base AS bldr-darwin-arm64-build +COPY --from=generate / / +WORKDIR /src/cmd/bldr +ARG VERSION_PKG="github.com/siderolabs/bldr/internal/version" +ARG SHA +ARG TAG +RUN --mount=type=cache,target=/root/.cache/go-build --mount=type=cache,target=/go/pkg GOARCH=arm64 GOOS=darwin go build -ldflags "-s -w -X ${VERSION_PKG}.Name=bldr -X ${VERSION_PKG}.SHA=${SHA} -X ${VERSION_PKG}.Tag=${TAG}" -o /bldr-darwin-arm64 + # builds bldr-linux-amd64 FROM base AS bldr-linux-amd64-build COPY --from=generate / / @@ -105,6 +123,12 @@ FROM base AS unit-tests-run ARG TESTPKGS RUN --mount=type=cache,target=/root/.cache/go-build --mount=type=cache,target=/go/pkg --mount=type=cache,target=/tmp go test -v -covermode=atomic -coverprofile=coverage.txt -coverpkg=${TESTPKGS} -count 1 ${TESTPKGS} +FROM scratch AS bldr-darwin-amd64 +COPY --from=bldr-darwin-amd64-build /bldr-darwin-amd64 /bldr-darwin-amd64 + +FROM scratch AS bldr-darwin-arm64 +COPY --from=bldr-darwin-arm64-build /bldr-darwin-arm64 /bldr-darwin-arm64 + FROM scratch AS bldr-linux-amd64 COPY --from=bldr-linux-amd64-build /bldr-linux-amd64 /bldr-linux-amd64 diff --git a/Makefile b/Makefile index 06a299a..4296336 100644 --- a/Makefile +++ b/Makefile @@ -1,6 +1,6 @@ # THIS FILE WAS AUTOMATICALLY GENERATED, PLEASE DO NOT EDIT. # -# Generated on 2022-08-31T21:36:40Z by kres ec2cd64. +# Generated on 2022-09-05T17:08:38Z by kres 871f67c. # common variables @@ -17,7 +17,7 @@ GO_VERSION ?= 1.19 GOIMPORTS_VERSION ?= v0.1.12 PROTOBUF_GO_VERSION ?= 1.28.1 GRPC_GO_VERSION ?= 1.2.0 -GRPC_GATEWAY_VERSION ?= 2.11.1 +GRPC_GATEWAY_VERSION ?= 2.11.3 VTPROTOBUF_VERSION ?= 0.3.0 DEEPCOPY_VERSION ?= v0.5.5 TESTPKGS ?= ./... @@ -133,6 +133,20 @@ unit-tests-race: ## Performs unit tests with race detection enabled. coverage: ## Upload coverage data to codecov.io. bash -c "bash <(curl -s https://codecov.io/bash) -f $(ARTIFACTS)/coverage.txt -X fix" +.PHONY: $(ARTIFACTS)/bldr-darwin-amd64 +$(ARTIFACTS)/bldr-darwin-amd64: + @$(MAKE) local-bldr-darwin-amd64 DEST=$(ARTIFACTS) + +.PHONY: bldr-darwin-amd64 +bldr-darwin-amd64: $(ARTIFACTS)/bldr-darwin-amd64 ## Builds executable for bldr-darwin-amd64. + +.PHONY: $(ARTIFACTS)/bldr-darwin-arm64 +$(ARTIFACTS)/bldr-darwin-arm64: + @$(MAKE) local-bldr-darwin-arm64 DEST=$(ARTIFACTS) + +.PHONY: bldr-darwin-arm64 +bldr-darwin-arm64: $(ARTIFACTS)/bldr-darwin-arm64 ## Builds executable for bldr-darwin-arm64. + .PHONY: $(ARTIFACTS)/bldr-linux-amd64 $(ARTIFACTS)/bldr-linux-amd64: @$(MAKE) local-bldr-linux-amd64 DEST=$(ARTIFACTS) @@ -148,7 +162,7 @@ $(ARTIFACTS)/bldr-linux-arm64: bldr-linux-arm64: $(ARTIFACTS)/bldr-linux-arm64 ## Builds executable for bldr-linux-arm64. .PHONY: bldr -bldr: bldr-linux-amd64 bldr-linux-arm64 ## Builds executables for bldr. +bldr: bldr-darwin-amd64 bldr-darwin-arm64 bldr-linux-amd64 bldr-linux-arm64 ## Builds executables for bldr. .PHONY: lint-markdown lint-markdown: ## Runs markdownlint. diff --git a/hack/test/Dockerfile b/hack/test/Dockerfile deleted file mode 100644 index 6da8544..0000000 --- a/hack/test/Dockerfile +++ /dev/null @@ -1,2 +0,0 @@ -FROM --platform=$TARGETPLATFORM alpine:3.9 as test -COPY --from=docker.io/autonomy/golang:059383d-dirty /toolchain /toolchain \ No newline at end of file