From 3a8582141d294406136c6509c1d4ccf348de603e Mon Sep 17 00:00:00 2001 From: Robert Kaussow Date: Sat, 14 Jan 2023 23:49:36 +0100 Subject: [PATCH] refactor: use buildx for multiarch container builds (#13) --- .drone.jsonnet | 248 ------------------ .drone.yml | 206 +++------------ .../Dockerfile.amd64 => Dockerfile.multiarch | 0 docker/Dockerfile.arm | 14 - docker/Dockerfile.arm64 | 14 - docker/manifest-quay.tmpl | 24 -- docker/manifest.tmpl | 24 -- 7 files changed, 31 insertions(+), 499 deletions(-) delete mode 100644 .drone.jsonnet rename docker/Dockerfile.amd64 => Dockerfile.multiarch (100%) delete mode 100644 docker/Dockerfile.arm delete mode 100644 docker/Dockerfile.arm64 delete mode 100644 docker/manifest-quay.tmpl delete mode 100644 docker/manifest.tmpl diff --git a/.drone.jsonnet b/.drone.jsonnet deleted file mode 100644 index 698e6ab..0000000 --- a/.drone.jsonnet +++ /dev/null @@ -1,248 +0,0 @@ -local PipelineTest = { - kind: 'pipeline', - name: 'test', - platform: { - os: 'linux', - arch: 'amd64', - }, - steps: [ - { - name: 'lint', - image: 'koalaman/shellcheck-alpine:stable', - commands: [ - 'shellcheck ./retry', - ], - }, - { - name: 'test', - image: 'bats/bats', - commands: [ - 'bats ./retry.bats', - ], - }, - ], - trigger: { - ref: ['refs/heads/main', 'refs/tags/**', 'refs/pull/**'], - }, -}; - -local PipelineBuildPackage = { - kind: 'pipeline', - name: 'build-package', - platform: { - os: 'linux', - arch: 'amd64', - }, - steps: [ - { - name: 'checksum', - image: 'alpine', - commands: [ - 'sha256sum retry > sha256sum.txt', - ], - }, - { - name: 'changelog-generate', - image: 'thegeeklab/git-chglog', - commands: [ - 'git fetch -tq', - 'git-chglog --no-color --no-emoji -o CHANGELOG.md ${DRONE_TAG:---next-tag unreleased unreleased}', - ], - }, - { - name: 'changelog-format', - image: 'thegeeklab/alpine-tools', - commands: [ - 'prettier CHANGELOG.md', - 'prettier -w CHANGELOG.md', - ], - }, - { - name: 'publish-github', - image: 'plugins/github-release', - settings: { - overwrite: true, - api_key: { from_secret: 'github_token' }, - files: ['retry', 'sha256sum.txt'], - title: '${DRONE_TAG}', - note: 'CHANGELOG.md', - }, - when: { - ref: ['refs/tags/**'], - }, - }, - ], - depends_on: [ - 'test', - ], - trigger: { - ref: ['refs/heads/main', 'refs/tags/**', 'refs/pull/**'], - }, -}; - -local PipelineBuildContainer(arch='amd64') = { - kind: 'pipeline', - name: 'build-container-' + arch, - platform: { - os: 'linux', - arch: arch, - }, - steps: [ - { - name: 'dryrun', - image: 'thegeeklab/drone-docker:19', - settings: { - dry_run: true, - dockerfile: 'docker/Dockerfile.' + arch, - repo: 'thegeeklab/${DRONE_REPO_NAME}', - username: { from_secret: 'docker_username' }, - password: { from_secret: 'docker_password' }, - }, - when: { - ref: ['refs/pull/**'], - }, - }, - { - name: 'publish-dockerhub', - image: 'thegeeklab/drone-docker:19', - settings: { - auto_tag: true, - auto_tag_suffix: arch, - dockerfile: 'docker/Dockerfile.' + arch, - repo: 'thegeeklab/${DRONE_REPO_NAME}', - username: { from_secret: 'docker_username' }, - password: { from_secret: 'docker_password' }, - }, - when: { - ref: ['refs/heads/main', 'refs/tags/**'], - }, - }, - { - name: 'publish-quay', - image: 'thegeeklab/drone-docker:19', - settings: { - auto_tag: true, - auto_tag_suffix: arch, - dockerfile: 'docker/Dockerfile.' + arch, - registry: 'quay.io', - repo: 'quay.io/thegeeklab/${DRONE_REPO_NAME}', - username: { from_secret: 'quay_username' }, - password: { from_secret: 'quay_password' }, - }, - when: { - ref: ['refs/heads/main', 'refs/tags/**'], - }, - }, - ], - depends_on: [ - 'test', - ], - trigger: { - ref: ['refs/heads/main', 'refs/tags/**', 'refs/pull/**'], - }, -}; - -local PipelineNotifications = { - kind: 'pipeline', - name: 'notifications', - platform: { - os: 'linux', - arch: 'amd64', - }, - steps: [ - { - image: 'plugins/manifest', - name: 'manifest-dockerhub', - settings: { - ignore_missing: true, - auto_tag: true, - username: { from_secret: 'docker_username' }, - password: { from_secret: 'docker_password' }, - spec: 'docker/manifest.tmpl', - }, - when: { - status: ['success'], - }, - }, - { - image: 'plugins/manifest', - name: 'manifest-quay', - settings: { - ignore_missing: true, - auto_tag: true, - username: { from_secret: 'quay_username' }, - password: { from_secret: 'quay_password' }, - spec: 'docker/manifest-quay.tmpl', - }, - when: { - status: ['success'], - }, - }, - { - name: 'pushrm-dockerhub', - pull: 'always', - image: 'chko/docker-pushrm:1', - environment: { - DOCKER_PASS: { - from_secret: 'docker_password', - }, - DOCKER_USER: { - from_secret: 'docker_username', - }, - PUSHRM_FILE: 'README.md', - PUSHRM_SHORT: 'Poor-mans docker service synchronizer', - PUSHRM_TARGET: 'thegeeklab/${DRONE_REPO_NAME}', - }, - when: { - status: ['success'], - }, - }, - { - name: 'pushrm-quay', - pull: 'always', - image: 'chko/docker-pushrm:1', - environment: { - APIKEY__QUAY_IO: { - from_secret: 'quay_token', - }, - PUSHRM_FILE: 'README.md', - PUSHRM_TARGET: 'quay.io/thegeeklab/${DRONE_REPO_NAME}', - }, - when: { - status: ['success'], - }, - }, - { - name: 'matrix', - image: 'thegeeklab/drone-matrix', - settings: { - homeserver: { from_secret: 'matrix_homeserver' }, - roomid: { from_secret: 'matrix_roomid' }, - template: 'Status: **{{ build.Status }}**
Build: [{{ repo.Owner }}/{{ repo.Name }}]({{ build.Link }}){{#if build.Branch}} ({{ build.Branch }}){{/if}} by {{ commit.Author }}
Message: {{ commit.Message.Title }}', - username: { from_secret: 'matrix_username' }, - password: { from_secret: 'matrix_password' }, - }, - when: { - status: ['success', 'failure'], - }, - }, - ], - depends_on: [ - 'build-container-amd64', - 'build-container-arm', - 'build-container-arm64', - ], - trigger: { - ref: ['refs/heads/main', 'refs/tags/**'], - status: ['success', 'failure'], - }, -}; - -[ - PipelineTest, - PipelineBuildPackage, - PipelineBuildContainer(arch='amd64'), - PipelineBuildContainer(arch='arm64'), - PipelineBuildContainer(arch='arm'), - PipelineNotifications, -] diff --git a/.drone.yml b/.drone.yml index f282fa6..ff6f850 100644 --- a/.drone.yml +++ b/.drone.yml @@ -75,7 +75,7 @@ depends_on: --- kind: pipeline -name: build-container-amd64 +name: build-container platform: os: linux @@ -83,27 +83,34 @@ platform: steps: - name: dryrun - image: thegeeklab/drone-docker:19 + image: thegeeklab/drone-docker-buildx:20 settings: - dockerfile: docker/Dockerfile.amd64 + dockerfile: Dockerfile.multiarch dry_run: true - password: - from_secret: docker_password + platforms: + - linux/amd64 + - linux/arm64 + - linux/arm/v7 + - linux/arm/v6 + provenance: false repo: thegeeklab/${DRONE_REPO_NAME} - username: - from_secret: docker_username when: ref: - refs/pull/** - name: publish-dockerhub - image: thegeeklab/drone-docker:19 + 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 + - linux/arm/v7 + - linux/arm/v6 + provenance: false repo: thegeeklab/${DRONE_REPO_NAME} username: from_secret: docker_username @@ -111,145 +118,22 @@ steps: ref: - refs/heads/main - refs/tags/** + depends_on: + - dryrun - name: publish-quay - image: thegeeklab/drone-docker:19 + image: thegeeklab/drone-docker-buildx:20 settings: auto_tag: true - auto_tag_suffix: amd64 - dockerfile: docker/Dockerfile.amd64 - password: - from_secret: quay_password - registry: quay.io - repo: quay.io/thegeeklab/${DRONE_REPO_NAME} - username: - from_secret: quay_username - when: - ref: - - refs/heads/main - - refs/tags/** - -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: dryrun - image: thegeeklab/drone-docker:19 - settings: - dockerfile: docker/Dockerfile.arm64 - dry_run: true - password: - from_secret: docker_password - repo: thegeeklab/${DRONE_REPO_NAME} - username: - from_secret: docker_username - when: - ref: - - refs/pull/** - - - name: publish-dockerhub - image: thegeeklab/drone-docker:19 - settings: - auto_tag: true - auto_tag_suffix: arm64 - dockerfile: docker/Dockerfile.arm64 - password: - from_secret: docker_password - repo: thegeeklab/${DRONE_REPO_NAME} - username: - from_secret: docker_username - when: - ref: - - refs/heads/main - - refs/tags/** - - - name: publish-quay - image: thegeeklab/drone-docker:19 - settings: - auto_tag: true - auto_tag_suffix: arm64 - dockerfile: docker/Dockerfile.arm64 - password: - from_secret: quay_password - registry: quay.io - repo: quay.io/thegeeklab/${DRONE_REPO_NAME} - username: - from_secret: quay_username - when: - ref: - - refs/heads/main - - refs/tags/** - -trigger: - ref: - - refs/heads/main - - refs/tags/** - - refs/pull/** - -depends_on: - - test - ---- -kind: pipeline -name: build-container-arm - -platform: - os: linux - arch: arm - -steps: - - name: dryrun - image: thegeeklab/drone-docker:19 - settings: - dockerfile: docker/Dockerfile.arm - dry_run: true - password: - from_secret: docker_password - repo: thegeeklab/${DRONE_REPO_NAME} - username: - from_secret: docker_username - when: - ref: - - refs/pull/** - - - name: publish-dockerhub - image: thegeeklab/drone-docker:19 - settings: - auto_tag: true - auto_tag_suffix: arm - dockerfile: docker/Dockerfile.arm - password: - from_secret: docker_password - repo: thegeeklab/${DRONE_REPO_NAME} - username: - from_secret: docker_username - when: - ref: - - refs/heads/main - - refs/tags/** - - - name: publish-quay - image: thegeeklab/drone-docker:19 - settings: - auto_tag: true - auto_tag_suffix: arm - dockerfile: docker/Dockerfile.arm + dockerfile: Dockerfile.multiarch password: from_secret: quay_password + platforms: + - linux/amd64 + - linux/arm64 + - linux/arm/v7 + - linux/arm/v6 + provenance: false registry: quay.io repo: quay.io/thegeeklab/${DRONE_REPO_NAME} username: @@ -258,6 +142,8 @@ steps: ref: - refs/heads/main - refs/tags/** + depends_on: + - dryrun trigger: ref: @@ -277,34 +163,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 pull: always image: chko/docker-pushrm:1 @@ -358,12 +216,10 @@ trigger: - failure depends_on: - - build-container-amd64 - - build-container-arm - - build-container-arm64 + - build-container --- kind: signature -hmac: 1cb682c6e2f382da9704f103c97b12d5ce10f407b0bda7d0a8377581fea34ae3 +hmac: e9515399fab753740664373fe3c612dcd57fa6f5552fd0872c3881e94188b1ff ... diff --git a/docker/Dockerfile.amd64 b/Dockerfile.multiarch similarity index 100% rename from docker/Dockerfile.amd64 rename to Dockerfile.multiarch diff --git a/docker/Dockerfile.arm b/docker/Dockerfile.arm deleted file mode 100644 index 0be5332..0000000 --- a/docker/Dockerfile.arm +++ /dev/null @@ -1,14 +0,0 @@ -FROM arm32v7/alpine:3.16@sha256:92cd2f468f336f3aad520d6039be09c423c4ad62bb60e0154bb1a9cd072f4c1e - -LABEL maintainer="Robert Kaussow " -LABEL org.opencontainers.image.authors="Robert Kaussow " -LABEL org.opencontainers.image.title="retry" -LABEL org.opencontainers.image.url="https://github.com/thegeeklab/retry" -LABEL org.opencontainers.image.source="https://github.com/thegeeklab/retry" -LABEL org.opencontainers.image.documentation="https://github.com/thegeeklab/retry" - -ADD retry /usr/local/bin/retry - -USER root -CMD [] -ENTRYPOINT ["/usr/local/bin/retry"] diff --git a/docker/Dockerfile.arm64 b/docker/Dockerfile.arm64 deleted file mode 100644 index ea6b357..0000000 --- a/docker/Dockerfile.arm64 +++ /dev/null @@ -1,14 +0,0 @@ -FROM arm64v8/alpine:3.16@sha256:559254f7ee68d88649077bd0cc6dfb94c337aadb8411d0fe5eae3b037578ec13 - -LABEL maintainer="Robert Kaussow " -LABEL org.opencontainers.image.authors="Robert Kaussow " -LABEL org.opencontainers.image.title="retry" -LABEL org.opencontainers.image.url="https://github.com/thegeeklab/retry" -LABEL org.opencontainers.image.source="https://github.com/thegeeklab/retry" -LABEL org.opencontainers.image.documentation="https://github.com/thegeeklab/retry" - -ADD retry /usr/local/bin/retry - -USER root -CMD [] -ENTRYPOINT ["/usr/local/bin/retry"] diff --git a/docker/manifest-quay.tmpl b/docker/manifest-quay.tmpl deleted file mode 100644 index 14c6a70..0000000 --- a/docker/manifest-quay.tmpl +++ /dev/null @@ -1,24 +0,0 @@ -image: quay.io/thegeeklab/retry:{{#if build.tag}}{{trimPrefix "v" build.tag}}{{else}}latest{{/if}} -{{#if build.tags}} -tags: -{{#each build.tags}} - - {{this}} -{{/each}} -{{/if}} -manifests: - - image: quay.io/thegeeklab/retry:{{#if build.tag}}{{trimPrefix "v" build.tag}}-{{/if}}amd64 - platform: - architecture: amd64 - os: linux - - - image: quay.io/thegeeklab/retry:{{#if build.tag}}{{trimPrefix "v" build.tag}}-{{/if}}arm64 - platform: - architecture: arm64 - os: linux - variant: v8 - - - image: quay.io/thegeeklab/retry:{{#if build.tag}}{{trimPrefix "v" build.tag}}-{{/if}}arm - platform: - architecture: arm - os: linux - variant: v7 diff --git a/docker/manifest.tmpl b/docker/manifest.tmpl deleted file mode 100644 index 93ce499..0000000 --- a/docker/manifest.tmpl +++ /dev/null @@ -1,24 +0,0 @@ -image: thegeeklab/retry:{{#if build.tag}}{{trimPrefix "v" build.tag}}{{else}}latest{{/if}} -{{#if build.tags}} -tags: -{{#each build.tags}} - - {{this}} -{{/each}} -{{/if}} -manifests: - - image: thegeeklab/retry:{{#if build.tag}}{{trimPrefix "v" build.tag}}-{{/if}}amd64 - platform: - architecture: amd64 - os: linux - - - image: thegeeklab/retry:{{#if build.tag}}{{trimPrefix "v" build.tag}}-{{/if}}arm64 - platform: - architecture: arm64 - os: linux - variant: v8 - - - image: thegeeklab/retry:{{#if build.tag}}{{trimPrefix "v" build.tag}}-{{/if}}arm - platform: - architecture: arm - os: linux - variant: v7