From 18c6d8fa0340f5c9784b8e366bd4443c02879f5a Mon Sep 17 00:00:00 2001 From: Fernandez Ludovic Date: Sun, 26 Feb 2023 14:27:16 +0100 Subject: [PATCH] chore: use buildx for cross-platform image builds --- .github/workflows/release.yml | 33 ++++++-------- .goreleaser.yml | 82 +++++++++++++++++++++++++++++++++++ Dockerfile | 2 +- Makefile | 3 -- buildx.Dockerfile | 10 +++++ tmpl.Dockerfile | 26 ----------- 6 files changed, 107 insertions(+), 49 deletions(-) create mode 100644 buildx.Dockerfile delete mode 100644 tmpl.Dockerfile diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 986b721d..231cf499 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -12,7 +12,6 @@ jobs: runs-on: ubuntu-latest env: GO_VERSION: '1.20' - SEIHON_VERSION: v0.8.3 CGO_ENABLED: 0 steps: @@ -34,27 +33,23 @@ jobs: restore-keys: | ${{ runner.os }}-go- - # https://goreleaser.com/ci/actions/ - - name: Run GoReleaser - uses: goreleaser/goreleaser-action@v3 - with: - version: latest - args: release --rm-dist --timeout=60m - env: - GITHUB_TOKEN: ${{ secrets.GH_TOKEN_REPO }} - - # Install Docker image multi-arch builder - - name: Install Seihon ${{ env.SEIHON_VERSION }} - if: startsWith(github.ref, 'refs/tags/v') - run: | - curl -sSfL https://raw.githubusercontent.com/ldez/seihon/master/godownloader.sh | sh -s -- -b $(go env GOPATH)/bin ${SEIHON_VERSION} - seihon --version - - name: Docker Login env: DOCKER_USERNAME: ${{ secrets.DOCKER_USERNAME }} DOCKER_PASSWORD: ${{ secrets.DOCKER_PASSWORD }} run: echo "${DOCKER_PASSWORD}" | docker login --username "${DOCKER_USERNAME}" --password-stdin - - name: Publish Docker Images (Seihon) - run: make publish-images + - name: Set up QEMU + uses: docker/setup-qemu-action@v2 + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v2 + + # https://goreleaser.com/ci/actions/ + - name: Run GoReleaser + uses: goreleaser/goreleaser-action@v3 + with: + version: latest + args: release --clean --timeout=90m + env: + GITHUB_TOKEN: ${{ secrets.GH_TOKEN_REPO }} diff --git a/.goreleaser.yml b/.goreleaser.yml index 7d1337bd..ee4198cd 100644 --- a/.goreleaser.yml +++ b/.goreleaser.yml @@ -51,3 +51,85 @@ archives: files: - LICENSE - CHANGELOG.md + +docker_manifests: + - name_template: 'goacme/lego:{{ .Tag }}' + image_templates: + - 'goacme/lego:{{ .Tag }}-amd64' + - 'goacme/lego:{{ .Tag }}-arm64' + - 'goacme/lego:{{ .Tag }}-armv7' + - name_template: 'goacme/lego:latest' + image_templates: + - 'goacme/lego:{{ .Tag }}-amd64' + - 'goacme/lego:{{ .Tag }}-arm64' + - 'goacme/lego:{{ .Tag }}-armv7' + - name_template: 'goacme/lego:v{{ .Major }}.{{ .Minor }}' + image_templates: + - 'goacme/lego:v{{ .Major }}.{{ .Minor }}-amd64' + - 'goacme/lego:v{{ .Major }}.{{ .Minor }}-arm64' + - 'goacme/lego:v{{ .Major }}.{{ .Minor }}-armv7' + +dockers: + - use: buildx + goos: linux + goarch: amd64 + dockerfile: buildx.Dockerfile + image_templates: + - 'goacme/lego:latest-amd64' + - 'goacme/lego:{{ .Tag }}-amd64' + - 'goacme/lego:v{{ .Major }}.{{ .Minor }}-amd64' + build_flag_templates: + - '--pull' + # https://github.com/opencontainers/image-spec/blob/main/annotations.md#pre-defined-annotation-keys + - '--label=org.opencontainers.image.title={{.ProjectName}}' + - '--label=org.opencontainers.image.description=Lets Encrypt/ACME client and library written in Go' + - '--label=org.opencontainers.image.source={{.GitURL}}' + - '--label=org.opencontainers.image.url={{.GitURL}}' + - '--label=org.opencontainers.image.documentation=https://go-acme.github.io/lego' + - '--label=org.opencontainers.image.created={{.Date}}' + - '--label=org.opencontainers.image.revision={{.FullCommit}}' + - '--label=org.opencontainers.image.version={{.Version}}' + - '--platform=linux/amd64' + + - use: buildx + goos: linux + goarch: arm64 + dockerfile: buildx.Dockerfile + image_templates: + - 'goacme/lego:latest-arm64' + - 'goacme/lego:{{ .Tag }}-arm64' + - 'goacme/lego:v{{ .Major }}.{{ .Minor }}-arm64' + build_flag_templates: + - '--pull' + # https://github.com/opencontainers/image-spec/blob/main/annotations.md#pre-defined-annotation-keys + - '--label=org.opencontainers.image.title={{.ProjectName}}' + - '--label=org.opencontainers.image.description=Lets Encrypt/ACME client and library written in Go' + - '--label=org.opencontainers.image.source={{.GitURL}}' + - '--label=org.opencontainers.image.url={{.GitURL}}' + - '--label=org.opencontainers.image.documentation=https://go-acme.github.io/lego' + - '--label=org.opencontainers.image.created={{.Date}}' + - '--label=org.opencontainers.image.revision={{.FullCommit}}' + - '--label=org.opencontainers.image.version={{.Version}}' + - '--platform=linux/arm64' + + - use: buildx + goos: linux + goarch: arm + goarm: '7' + dockerfile: buildx.Dockerfile + image_templates: + - 'goacme/lego:latest-armv7' + - 'goacme/lego:{{ .Tag }}-armv7' + - 'goacme/lego:v{{ .Major }}.{{ .Minor }}-armv7' + build_flag_templates: + - '--pull' + # https://github.com/opencontainers/image-spec/blob/main/annotations.md#pre-defined-annotation-keys + - '--label=org.opencontainers.image.title={{.ProjectName}}' + - '--label=org.opencontainers.image.description=Lets Encrypt/ACME client and library written in Go' + - '--label=org.opencontainers.image.source={{.GitURL}}' + - '--label=org.opencontainers.image.url={{.GitURL}}' + - '--label=org.opencontainers.image.documentation=https://go-acme.github.io/lego' + - '--label=org.opencontainers.image.created={{.Date}}' + - '--label=org.opencontainers.image.revision={{.FullCommit}}' + - '--label=org.opencontainers.image.version={{.Version}}' + - '--platform=linux/arm/v7' diff --git a/Dockerfile b/Dockerfile index 586b4e3e..6dbdc22a 100644 --- a/Dockerfile +++ b/Dockerfile @@ -14,7 +14,7 @@ RUN go mod download COPY . . RUN make build -FROM alpine:3.12 +FROM alpine:3 RUN apk update \ && apk add --no-cache ca-certificates tzdata \ && update-ca-certificates diff --git a/Makefile b/Makefile index dbc90b56..bd341e1a 100644 --- a/Makefile +++ b/Makefile @@ -26,9 +26,6 @@ image: @echo Version: $(VERSION) docker build -t $(LEGO_IMAGE) . -publish-images: - seihon publish -v "$(TAG_NAME)" -v "latest" --image-name="$(LEGO_IMAGE)" --dry-run=false - test: clean go test -v -cover ./... diff --git a/buildx.Dockerfile b/buildx.Dockerfile new file mode 100644 index 00000000..92a86dd3 --- /dev/null +++ b/buildx.Dockerfile @@ -0,0 +1,10 @@ +# syntax=docker/dockerfile:1.4 +FROM alpine:3 + +RUN apk --no-cache --no-progress add git ca-certificates tzdata \ + && rm -rf /var/cache/apk/* + +COPY lego / + +ENTRYPOINT ["/lego"] +EXPOSE 80 diff --git a/tmpl.Dockerfile b/tmpl.Dockerfile deleted file mode 100644 index 5f64f613..00000000 --- a/tmpl.Dockerfile +++ /dev/null @@ -1,26 +0,0 @@ -# Dockerfile template used by Seihon to create multi-arch images. -# https://github.com/ldez/seihon -FROM golang:1-alpine as builder - -RUN apk --update upgrade \ - && apk --no-cache --no-progress add git make ca-certificates tzdata - -WORKDIR /go/lego - -ENV GO111MODULE on - -# Download go modules -COPY go.mod . -COPY go.sum . -RUN go mod download - -COPY . . -RUN GOARCH={{ .GoARCH }} GOARM={{ .GoARM }} make build - -FROM {{ .RuntimeImage }} - -COPY --from=builder /usr/share/zoneinfo /usr/share/zoneinfo -COPY --from=builder /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/ -COPY --from=builder /go/lego/dist/lego /usr/bin/lego - -ENTRYPOINT [ "/usr/bin/lego" ]