refactor: use buildx for multiarch container builds (#64)

This commit is contained in:
Robert Kaussow 2023-01-14 22:45:25 +01:00 committed by GitHub
parent 36641787c3
commit ed127a7689
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 43 additions and 533 deletions

View File

@ -1,2 +0,0 @@
*
!dist/

View File

@ -1,351 +0,0 @@
local PipelineTest = {
kind: 'pipeline',
name: 'test',
platform: {
os: 'linux',
arch: 'amd64',
},
steps: [
{
name: 'deps',
image: 'golang:1.19',
commands: [
'make deps',
],
volumes: [
{
name: 'godeps',
path: '/go',
},
],
},
{
name: 'lint',
image: 'golang:1.19',
commands: [
'make lint',
],
volumes: [
{
name: 'godeps',
path: '/go',
},
],
},
{
name: 'test',
image: 'golang:1.19',
commands: [
'make test',
],
volumes: [
{
name: 'godeps',
path: '/go',
},
],
},
],
volumes: [
{
name: 'godeps',
temp: {},
},
],
trigger: {
ref: ['refs/heads/main', 'refs/tags/**', 'refs/pull/**'],
},
};
local PipelineBuildBinaries = {
kind: 'pipeline',
name: 'build-binaries',
platform: {
os: 'linux',
arch: 'amd64',
},
steps: [
{
name: 'build',
image: 'techknowlogick/xgo:go-1.19.x',
commands: [
'ln -s /drone/src /source',
'make release',
],
},
{
name: 'executable',
image: 'alpine',
commands: [
'apk --update add --no-cache libc6-compat',
'$(find dist/ -executable -type f -iname ${DRONE_REPO_NAME}-linux-amd64) --help',
],
},
{
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',
image: 'plugins/github-release',
settings: {
overwrite: true,
api_key: {
from_secret: 'github_token',
},
files: ['dist/*'],
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: 'build',
image: 'golang:1.19',
commands: [
'make build',
'ls -l dist/drone-s3-sync',
],
},
{
name: 'dryrun',
image: 'thegeeklab/drone-docker-buildx:20',
settings: {
dry_run: true,
dockerfile: 'docker/Dockerfile.' + arch,
repo: 'thegeeklab/${DRONE_REPO_NAME}',
},
depends_on: ['build'],
when: {
ref: ['refs/pull/**'],
},
},
{
name: 'publish-dockerhub',
image: 'thegeeklab/drone-docker-buildx:20',
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/**'],
},
depends_on: ['dryrun'],
},
{
name: 'publish-quay',
image: 'thegeeklab/drone-docker-buildx:20',
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: ['dryrun'],
},
],
depends_on: [
'test',
],
trigger: {
ref: ['refs/heads/main', 'refs/tags/**', 'refs/pull/**'],
},
};
local PipelineDocs = {
kind: 'pipeline',
name: 'docs',
platform: {
os: 'linux',
arch: 'amd64',
},
concurrency: {
limit: 1,
},
steps: [
{
name: 'markdownlint',
image: 'thegeeklab/markdownlint-cli',
commands: [
"markdownlint 'docs/content/**/*.md' 'README.md' 'CONTRIBUTING.md'",
],
},
{
name: 'spellcheck',
image: 'thegeeklab/alpine-tools',
commands: [
"spellchecker --files '_docs/**/*.md' 'README.md' 'CONTRIBUTING.md' -d .dictionary -p spell indefinite-article syntax-urls --no-suggestions",
],
environment: {
FORCE_COLOR: true,
NPM_CONFIG_LOGLEVEL: 'error',
},
},
{
name: 'publish',
image: 'plugins/gh-pages',
settings: {
username: { from_secret: 'github_username' },
password: { from_secret: 'github_token' },
pages_directory: '_docs/',
target_branch: 'docs',
},
when: {
ref: ['refs/heads/main'],
},
},
],
depends_on: [
'build-binaries',
'build-container-amd64',
'build-container-arm64',
],
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',
image: 'chko/docker-pushrm:1',
environment: {
DOCKER_PASS: {
from_secret: 'docker_password',
},
DOCKER_USER: {
from_secret: 'docker_username',
},
PUSHRM_FILE: 'README.md',
PUSHRM_SHORT: 'Drone plugin to synchronize a directory with an S3 bucket',
PUSHRM_TARGET: 'thegeeklab/${DRONE_REPO_NAME}',
},
when: {
status: ['success'],
},
},
{
name: 'pushrm-quay',
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 }}**<br/> Build: [{{ repo.Owner }}/{{ repo.Name }}]({{ build.Link }}){{#if build.Branch}} ({{ build.Branch }}){{/if}} by {{ commit.Author }}<br/> Message: {{ commit.Message.Title }}',
username: { from_secret: 'matrix_username' },
password: { from_secret: 'matrix_password' },
},
when: {
status: ['success', 'failure'],
},
},
],
depends_on: [
'docs',
],
trigger: {
ref: ['refs/heads/main', 'refs/tags/**'],
status: ['success', 'failure'],
},
};
[
PipelineTest,
PipelineBuildBinaries,
PipelineBuildContainer(arch='amd64'),
PipelineBuildContainer(arch='arm64'),
PipelineDocs,
PipelineNotifications,
]

View File

@ -59,7 +59,6 @@ steps:
- name: executable - name: executable
image: alpine image: alpine
commands: commands:
- apk --update add --no-cache libc6-compat
- $(find dist/ -executable -type f -iname ${DRONE_REPO_NAME}-linux-amd64) --help - $(find dist/ -executable -type f -iname ${DRONE_REPO_NAME}-linux-amd64) --help
- name: changelog-generate - name: changelog-generate
@ -99,39 +98,42 @@ depends_on:
--- ---
kind: pipeline kind: pipeline
name: build-container-amd64 name: build-container
platform: platform:
os: linux os: linux
arch: amd64 arch: amd64
steps: steps:
- name: build
image: golang:1.19
commands:
- make build
- ls -l dist/drone-s3-sync
- name: dryrun - name: dryrun
image: thegeeklab/drone-docker-buildx:20 image: thegeeklab/drone-docker-buildx:20
settings: settings:
dockerfile: docker/Dockerfile.amd64 dockerfile: Dockerfile.multiarch
dry_run: true dry_run: true
platforms:
- linux/amd64
- linux/arm64
- linux/arm/v7
- linux/arm/v6
provenance: false
repo: thegeeklab/${DRONE_REPO_NAME} repo: thegeeklab/${DRONE_REPO_NAME}
when: when:
ref: ref:
- refs/pull/** - refs/pull/**
depends_on:
- build
- name: publish-dockerhub - name: publish-dockerhub
image: thegeeklab/drone-docker-buildx:20 image: thegeeklab/drone-docker-buildx:20
settings: settings:
auto_tag: true auto_tag: true
auto_tag_suffix: amd64 dockerfile: Dockerfile.multiarch
dockerfile: docker/Dockerfile.amd64
password: password:
from_secret: docker_password from_secret: docker_password
platforms:
- linux/amd64
- linux/arm64
- linux/arm/v7
- linux/arm/v6
provenance: false
repo: thegeeklab/${DRONE_REPO_NAME} repo: thegeeklab/${DRONE_REPO_NAME}
username: username:
from_secret: docker_username from_secret: docker_username
@ -146,83 +148,15 @@ steps:
image: thegeeklab/drone-docker-buildx:20 image: thegeeklab/drone-docker-buildx:20
settings: settings:
auto_tag: true auto_tag: true
auto_tag_suffix: amd64 dockerfile: Dockerfile.multiarch
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/**
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
- ls -l dist/drone-s3-sync
- name: dryrun
image: thegeeklab/drone-docker-buildx:20
settings:
dockerfile: docker/Dockerfile.arm64
dry_run: true
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
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
password: password:
from_secret: quay_password from_secret: quay_password
platforms:
- linux/amd64
- linux/arm64
- linux/arm/v7
- linux/arm/v6
provenance: false
registry: quay.io registry: quay.io
repo: quay.io/thegeeklab/${DRONE_REPO_NAME} repo: quay.io/thegeeklab/${DRONE_REPO_NAME}
username: username:
@ -289,8 +223,7 @@ trigger:
depends_on: depends_on:
- build-binaries - build-binaries
- build-container-amd64 - build-container
- build-container-arm64
--- ---
kind: pipeline kind: pipeline
@ -301,34 +234,6 @@ platform:
arch: amd64 arch: amd64
steps: 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 - name: pushrm-dockerhub
image: chko/docker-pushrm:1 image: chko/docker-pushrm:1
environment: environment:
@ -384,6 +289,6 @@ depends_on:
--- ---
kind: signature kind: signature
hmac: 655db420fdf7a9dde23688e967a8ae3b8c7859804091376bacd4662f954eddb7 hmac: 38b69e9112311864ea30e7b4f0f1ad30ce1b775fce21afc3deb3e652532024de
... ...

View File

@ -1,3 +1,13 @@
FROM --platform=$BUILDPLATFORM golang:1.19@sha256:bb9811fad43a7d6fd2173248d8331b2dcf5ac9af20976b1937ecd214c5b8c383 as build
ARG TARGETOS
ARG TARGETARCH
ADD . /src
WORKDIR /src
RUN make build
FROM alpine:3.17@sha256:f271e74b17ced29b915d351685fd4644785c6d1559dd1f2d4189a5e851ef753a FROM alpine:3.17@sha256:f271e74b17ced29b915d351685fd4644785c6d1559dd1f2d4189a5e851ef753a
LABEL maintainer="Robert Kaussow <mail@thegeeklab.de>" LABEL maintainer="Robert Kaussow <mail@thegeeklab.de>"
@ -7,10 +17,5 @@ LABEL org.opencontainers.image.url="https://github.com/thegeeklab/drone-s3-sync"
LABEL org.opencontainers.image.source="https://github.com/thegeeklab/drone-s3-sync" LABEL org.opencontainers.image.source="https://github.com/thegeeklab/drone-s3-sync"
LABEL org.opencontainers.image.documentation="https://github.com/thegeeklab/drone-s3-sync" LABEL org.opencontainers.image.documentation="https://github.com/thegeeklab/drone-s3-sync"
RUN apk --update add --no-cache libc6-compat && \ COPY --from=build /src/dist/drone-s3-sync /bin/drone-s3-sync
rm -rf /var/cache/apk/* && \
rm -rf /tmp/*
ADD dist/drone-s3-sync /bin/
ENTRYPOINT ["/bin/drone-s3-sync"] ENTRYPOINT ["/bin/drone-s3-sync"]

View File

@ -20,9 +20,14 @@ XGO_PACKAGE ?= src.techknowlogick.com/xgo@latest
GENERATE ?= GENERATE ?=
XGO_VERSION := go-1.19.x XGO_VERSION := go-1.19.x
XGO_TARGETS ?= linux/amd64,linux/arm64 XGO_TARGETS ?= linux/amd64,linux/arm-6,linux/arm-7,linux/arm64
TAGS ?= netgo TARGETOS ?= linux
TARGETARCH ?= amd64
ifneq ("$(TARGETVARIANT)","")
GOARM ?= $(subst v,,$(TARGETVARIANT))
endif
TAGS ?= netgo,osusergo
ifndef VERSION ifndef VERSION
ifneq ($(DRONE_TAG),) ifneq ($(DRONE_TAG),)
@ -69,7 +74,7 @@ test:
build: $(DIST)/$(EXECUTABLE) build: $(DIST)/$(EXECUTABLE)
$(DIST)/$(EXECUTABLE): $(SOURCES) $(DIST)/$(EXECUTABLE): $(SOURCES)
$(GO) build -v -tags '$(TAGS)' -ldflags '-extldflags "-static" $(LDFLAGS)' -o $@ ./cmd/$(EXECUTABLE) GOOS=${TARGETOS} GOARCH=${TARGETARCH} GOARM=$(GOARM) $(GO) build -v -tags '$(TAGS)' -ldflags '-extldflags "-static" $(LDFLAGS)' -o $@ ./cmd/$(EXECUTABLE)
$(DIST_DIRS): $(DIST_DIRS):
mkdir -p $(DIST_DIRS) mkdir -p $(DIST_DIRS)

View File

@ -1,16 +0,0 @@
FROM arm64v8/alpine:3.17@sha256:41d876d4e44348d1c27445fdb0e64592e0eb926d4dbbcf09a3526dee7e628329
LABEL maintainer="Robert Kaussow <mail@thegeeklab.de>"
LABEL org.opencontainers.image.authors="Robert Kaussow <mail@thegeeklab.de>"
LABEL org.opencontainers.image.title="drone-s3-sync"
LABEL org.opencontainers.image.url="https://github.com/thegeeklab/drone-s3-sync"
LABEL org.opencontainers.image.source="https://github.com/thegeeklab/drone-s3-sync"
LABEL org.opencontainers.image.documentation="https://github.com/thegeeklab/drone-s3-sync"
RUN apk --update add --no-cache libc6-compat && \
rm -rf /var/cache/apk/* && \
rm -rf /tmp/*
ADD dist/drone-s3-sync /bin/
ENTRYPOINT ["/bin/drone-s3-sync"]

View File

@ -1,18 +0,0 @@
image: quay.io/thegeeklab/drone-s3-sync:{{#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/drone-s3-sync:{{#if build.tag}}{{trimPrefix "v" build.tag}}-{{/if}}amd64
platform:
architecture: amd64
os: linux
- image: quay.io/thegeeklab/drone-s3-sync:{{#if build.tag}}{{trimPrefix "v" build.tag}}-{{/if}}arm64
platform:
architecture: arm64
os: linux
variant: v8

View File

@ -1,18 +0,0 @@
image: thegeeklab/drone-s3-sync:{{#if build.tag}}{{trimPrefix "v" build.tag}}{{else}}latest{{/if}}
{{#if build.tags}}
tags:
{{#each build.tags}}
- {{this}}
{{/each}}
{{/if}}
manifests:
- image: thegeeklab/drone-s3-sync:{{#if build.tag}}{{trimPrefix "v" build.tag}}-{{/if}}amd64
platform:
architecture: amd64
os: linux
- image: thegeeklab/drone-s3-sync:{{#if build.tag}}{{trimPrefix "v" build.tag}}-{{/if}}arm64
platform:
architecture: arm64
os: linux
variant: v8