From a2f76571d612231c18dd7275c5ce0d45a00279ed Mon Sep 17 00:00:00 2001 From: Robert Kaussow Date: Thu, 12 Jan 2023 21:21:43 +0100 Subject: [PATCH] ci: test buildx multiarch builds (#172) --- .dockerignore | 2 - .drone.yml | 134 ++---------------- .../Dockerfile.amd64 => Dockerfile.multiarch | 12 +- Makefile | 4 +- 4 files changed, 29 insertions(+), 123 deletions(-) delete mode 100644 .dockerignore rename docker/Dockerfile.amd64 => Dockerfile.multiarch (86%) diff --git a/.dockerignore b/.dockerignore deleted file mode 100644 index 92d6c40..0000000 --- a/.dockerignore +++ /dev/null @@ -1,2 +0,0 @@ -* -!dist/ diff --git a/.drone.yml b/.drone.yml index 90c743b..7cd34ca 100644 --- a/.drone.yml +++ b/.drone.yml @@ -98,39 +98,37 @@ depends_on: --- kind: pipeline -name: build-container-amd64 +name: build-container platform: os: linux arch: amd64 steps: - - name: build - image: golang:1.19 - commands: - - make build - - name: dryrun image: thegeeklab/drone-docker-buildx:20 settings: - dockerfile: docker/Dockerfile.amd64 + dockerfile: Dockerfile.multiarch dry_run: true + platforms: + - linux/amd64 + - linux/arm64 provenance: false repo: thegeeklab/${DRONE_REPO_NAME} when: ref: - refs/pull/** - depends_on: - - build - name: publish-dockerhub image: thegeeklab/drone-docker-buildx:20 settings: auto_tag: true - auto_tag_suffix: amd64 - dockerfile: docker/Dockerfile.amd64 + dockerfile: Dockerfile.multiarch password: from_secret: docker_password + platforms: + - linux/amd64 + - linux/arm64 provenance: false repo: thegeeklab/${DRONE_REPO_NAME} username: @@ -146,85 +144,12 @@ steps: image: thegeeklab/drone-docker-buildx:20 settings: auto_tag: true - auto_tag_suffix: amd64 - dockerfile: docker/Dockerfile.amd64 - password: - from_secret: quay_password - provenance: false - registry: quay.io - repo: quay.io/thegeeklab/${DRONE_REPO_NAME} - username: - from_secret: quay_username - when: - ref: - - refs/heads/main - - refs/tags/** - depends_on: - - dryrun - -trigger: - ref: - - refs/heads/main - - refs/tags/** - - refs/pull/** - -depends_on: - - test - ---- -kind: pipeline -name: build-container-arm64 - -platform: - os: linux - arch: arm64 - -steps: - - name: build - image: golang:1.19 - commands: - - make build - - - name: dryrun - image: thegeeklab/drone-docker-buildx:20 - settings: - dockerfile: docker/Dockerfile.arm64 - dry_run: true - provenance: false - repo: thegeeklab/${DRONE_REPO_NAME} - when: - ref: - - refs/pull/** - depends_on: - - build - - - name: publish-dockerhub - image: thegeeklab/drone-docker-buildx:20 - settings: - auto_tag: true - auto_tag_suffix: arm64 - dockerfile: docker/Dockerfile.arm64 - password: - from_secret: docker_password - provenance: false - repo: thegeeklab/${DRONE_REPO_NAME} - username: - from_secret: docker_username - when: - ref: - - refs/heads/main - - refs/tags/** - depends_on: - - dryrun - - - name: publish-quay - image: thegeeklab/drone-docker-buildx:20 - settings: - auto_tag: true - auto_tag_suffix: arm64 - dockerfile: docker/Dockerfile.arm64 + dockerfile: Dockerfile.multiarch password: from_secret: quay_password + platforms: + - linux/amd64 + - linux/arm64 provenance: false registry: quay.io repo: quay.io/thegeeklab/${DRONE_REPO_NAME} @@ -292,8 +217,7 @@ trigger: depends_on: - build-binaries - - build-container-amd64 - - build-container-arm64 + - build-container --- kind: pipeline @@ -304,34 +228,6 @@ platform: arch: amd64 steps: - - name: manifest-dockerhub - image: plugins/manifest - settings: - auto_tag: true - ignore_missing: true - password: - from_secret: docker_password - spec: docker/manifest.tmpl - username: - from_secret: docker_username - when: - status: - - success - - - name: manifest-quay - image: plugins/manifest - settings: - auto_tag: true - ignore_missing: true - password: - from_secret: quay_password - spec: docker/manifest-quay.tmpl - username: - from_secret: quay_username - when: - status: - - success - - name: pushrm-dockerhub image: chko/docker-pushrm:1 environment: @@ -387,6 +283,6 @@ depends_on: --- kind: signature -hmac: 0263cf6df573ba55933b837db50a6f7e3a8fd422bb4506bc09a97e89085473bd +hmac: 0a2edb569e156dbb6c32a44b812757a28156b31a44325585c0f19ee0c6706fd4 ... diff --git a/docker/Dockerfile.amd64 b/Dockerfile.multiarch similarity index 86% rename from docker/Dockerfile.amd64 rename to Dockerfile.multiarch index c3e21f0..6acba7c 100644 --- a/docker/Dockerfile.amd64 +++ b/Dockerfile.multiarch @@ -1,3 +1,13 @@ +FROM --platform=$BUILDPLATFORM golang:1.19 as build + +ARG TARGETOS +ARG TARGETARCH + +ADD . /src +WORKDIR /src + +RUN make build + FROM docker:20.10-dind@sha256:2e0135466bcb3398e7f3943b87aef5c036dbaf1683805b8bfe992a477f7269e9 LABEL maintainer="Robert Kaussow " @@ -23,6 +33,6 @@ RUN apk --update add --virtual .build-deps curl && \ rm -rf /var/cache/apk/* && \ rm -rf /tmp/* -ADD dist/drone-docker-buildx /bin/ +COPY --from=build /src/dist/drone-docker-buildx /bin/drone-docker-buildx ENTRYPOINT ["/usr/local/bin/dockerd-entrypoint.sh", "drone-docker-buildx"] diff --git a/Makefile b/Makefile index 69eafc8..bdd477c 100644 --- a/Makefile +++ b/Makefile @@ -22,6 +22,8 @@ GENERATE ?= XGO_VERSION := go-1.19.x XGO_TARGETS ?= linux/amd64,linux/arm64 +TARGETOS ?= linux +TARGETARCH ?= amd64 TAGS ?= netgo ifndef VERSION @@ -69,7 +71,7 @@ test: build: $(DIST)/$(EXECUTABLE) $(DIST)/$(EXECUTABLE): $(SOURCES) - $(GO) build -v -tags '$(TAGS)' -ldflags '-extldflags "-static" $(LDFLAGS)' -o $@ ./cmd/$(EXECUTABLE) + GOOS=${TARGETOS} GOARCH=${TARGETARCH} $(GO) build -v -tags '$(TAGS)' -ldflags '-extldflags "-static" $(LDFLAGS)' -o $@ ./cmd/$(EXECUTABLE) $(DIST_DIRS): mkdir -p $(DIST_DIRS)