From 6af92b54d6b8fe300136b325753597e92158c151 Mon Sep 17 00:00:00 2001 From: Dennis Marttinen Date: Sun, 21 Jan 2024 12:30:28 +0200 Subject: [PATCH] feat: add support for arm64 builds Resolves https://github.com/siderolabs/discovery-service/issues/52. `make rekres` also updated some of the image tags. Signed-off-by: Dennis Marttinen Signed-off-by: Noel Georgi --- .conform.yaml | 2 +- .github/workflows/ci.yaml | 4 +++- .kres.yaml | 16 ++++++++++++++++ Dockerfile | 20 ++++++++++++++++---- Makefile | 28 ++++++++++++++++++++++++++-- 5 files changed, 62 insertions(+), 8 deletions(-) diff --git a/.conform.yaml b/.conform.yaml index 5256819..0516593 100644 --- a/.conform.yaml +++ b/.conform.yaml @@ -1,6 +1,6 @@ # THIS FILE WAS AUTOMATICALLY GENERATED, PLEASE DO NOT EDIT. # -# Generated on 2022-08-25T16:11:00Z by kres d2252ce. +# Generated on 2024-01-22T17:51:41Z by kres latest. --- policies: diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 4881132..cc15094 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -1,6 +1,6 @@ # THIS FILE WAS AUTOMATICALLY GENERATED, PLEASE DO NOT EDIT. # -# Generated on 2024-01-12T12:34:10Z by kres latest. +# Generated on 2024-01-22T17:52:47Z by kres latest. name: default concurrency: @@ -80,12 +80,14 @@ jobs: - name: push-discovery-service if: github.event_name != 'pull_request' env: + PLATFORM: linux/amd64,linux/arm64 PUSH: "true" run: | make image-discovery-service - name: push-discovery-service-latest if: github.event_name != 'pull_request' env: + PLATFORM: linux/amd64,linux/arm64 PUSH: "true" run: | make image-discovery-service TAG=latest diff --git a/.kres.yaml b/.kres.yaml index 33d3380..430b3cf 100644 --- a/.kres.yaml +++ b/.kres.yaml @@ -1,4 +1,20 @@ --- +kind: common.Image +name: image-discovery-service +spec: + extraEnvironment: + PLATFORM: linux/amd64,linux/arm64 +--- +kind: golang.Build +spec: + outputs: + linux-amd64: + GOOS: linux + GOARCH: amd64 + linux-arm64: + GOOS: linux + GOARCH: arm64 +--- kind: service.CodeCov spec: targetThreshold: 30 diff --git a/Dockerfile b/Dockerfile index ef0f888..b76d2b2 100644 --- a/Dockerfile +++ b/Dockerfile @@ -2,7 +2,7 @@ # THIS FILE WAS AUTOMATICALLY GENERATED, PLEASE DO NOT EDIT. # -# Generated on 2024-01-12T12:34:10Z by kres latest. +# Generated on 2024-01-22T17:51:41Z by kres latest. ARG TOOLCHAIN @@ -14,9 +14,9 @@ FROM ghcr.io/siderolabs/ca-certificates:v1.6.0 AS image-ca-certificates FROM ghcr.io/siderolabs/fhs:v1.6.0 AS image-fhs # runs markdownlint -FROM docker.io/node:21.4.0-alpine3.18 AS lint-markdown +FROM docker.io/node:21.5.0-alpine3.19 AS lint-markdown WORKDIR /src -RUN npm i -g markdownlint-cli@0.37.0 +RUN npm i -g markdownlint-cli@0.38.0 RUN npm i sentences-per-line@0.2.1 COPY .markdownlint.json . COPY ./README.md ./README.md @@ -70,7 +70,15 @@ COPY --from=generate / / WORKDIR /src/cmd/discovery-service ARG GO_BUILDFLAGS ARG GO_LDFLAGS -RUN --mount=type=cache,target=/root/.cache/go-build --mount=type=cache,target=/go/pkg go build ${GO_BUILDFLAGS} -ldflags "${GO_LDFLAGS}" -o /discovery-service-linux-amd64 +RUN --mount=type=cache,target=/root/.cache/go-build --mount=type=cache,target=/go/pkg GOARCH=amd64 GOOS=linux go build ${GO_BUILDFLAGS} -ldflags "${GO_LDFLAGS}" -o /discovery-service-linux-amd64 + +# builds discovery-service-linux-arm64 +FROM base AS discovery-service-linux-arm64-build +COPY --from=generate / / +WORKDIR /src/cmd/discovery-service +ARG GO_BUILDFLAGS +ARG GO_LDFLAGS +RUN --mount=type=cache,target=/root/.cache/go-build --mount=type=cache,target=/go/pkg GOARCH=arm64 GOOS=linux go build ${GO_BUILDFLAGS} -ldflags "${GO_LDFLAGS}" -o /discovery-service-linux-arm64 # runs gofumpt FROM base AS lint-gofumpt @@ -107,6 +115,9 @@ RUN --mount=type=cache,target=/root/.cache/go-build --mount=type=cache,target=/g FROM scratch AS discovery-service-linux-amd64 COPY --from=discovery-service-linux-amd64-build /discovery-service-linux-amd64 /discovery-service-linux-amd64 +FROM scratch AS discovery-service-linux-arm64 +COPY --from=discovery-service-linux-arm64-build /discovery-service-linux-arm64 /discovery-service-linux-arm64 + FROM scratch AS unit-tests COPY --from=unit-tests-run /src/coverage.txt /coverage-unit-tests.txt @@ -114,6 +125,7 @@ FROM discovery-service-linux-${TARGETARCH} AS discovery-service FROM scratch AS discovery-service-all COPY --from=discovery-service-linux-amd64 / / +COPY --from=discovery-service-linux-arm64 / / FROM scratch AS image-discovery-service ARG TARGETARCH diff --git a/Makefile b/Makefile index 0195ad9..08f9bc9 100644 --- a/Makefile +++ b/Makefile @@ -1,6 +1,6 @@ # THIS FILE WAS AUTOMATICALLY GENERATED, PLEASE DO NOT EDIT. # -# Generated on 2024-01-12T14:05:03Z by kres 0e666ea-dirty. +# Generated on 2024-01-22T17:51:41Z by kres latest. # common variables @@ -88,6 +88,23 @@ To create a builder instance, run: docker buildx create --name local --use +If running builds that needs to be cached aggresively create a builder instance with the following: + + docker buildx create --name local --use --config=config.toml + +config.toml contents: + +[worker.oci] + gc = true + gckeepstorage = 50000 + + [[worker.oci.gcpolicy]] + keepBytes = 10737418240 + keepDuration = 604800 + filters = [ "type==source.local", "type==exec.cachemount", "type==source.git.checkout"] + [[worker.oci.gcpolicy]] + all = true + keepBytes = 53687091200 If you already have a compatible builder instance, you may use that instead. @@ -167,8 +184,15 @@ $(ARTIFACTS)/discovery-service-linux-amd64: .PHONY: discovery-service-linux-amd64 discovery-service-linux-amd64: $(ARTIFACTS)/discovery-service-linux-amd64 ## Builds executable for discovery-service-linux-amd64. +.PHONY: $(ARTIFACTS)/discovery-service-linux-arm64 +$(ARTIFACTS)/discovery-service-linux-arm64: + @$(MAKE) local-discovery-service-linux-arm64 DEST=$(ARTIFACTS) + +.PHONY: discovery-service-linux-arm64 +discovery-service-linux-arm64: $(ARTIFACTS)/discovery-service-linux-arm64 ## Builds executable for discovery-service-linux-arm64. + .PHONY: discovery-service -discovery-service: discovery-service-linux-amd64 ## Builds executables for discovery-service. +discovery-service: discovery-service-linux-amd64 discovery-service-linux-arm64 ## Builds executables for discovery-service. .PHONY: lint-markdown lint-markdown: ## Runs markdownlint.