Skip to content

Commit

Permalink
feat: add multiarch docker build support (#1344)
Browse files Browse the repository at this point in the history
* feat: add multiarch docker build support

adds docker build support for the following platforms:
- amd64 (default)
- arm64v8
- armv6
- armv7

also adds GOOS and GOARCH information to the buildString

utilizes docker manifest to store image architecture metadata

* chore: update goreleaser action to v4

* chore: update docker login action to v2

* chore: format buildstring
  • Loading branch information
Thunderbottom committed Jul 18, 2023
1 parent e1c0bf5 commit 3663a8b
Show file tree
Hide file tree
Showing 2 changed files with 110 additions and 9 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/release.yml
Expand Up @@ -20,7 +20,7 @@ jobs:
go-version: 1.19

- name: Login to Docker Registry
uses: docker/login-action@v1
uses: docker/login-action@v2
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
Expand All @@ -37,9 +37,9 @@ jobs:
make dist
- name: Run GoReleaser
uses: goreleaser/goreleaser-action@v2
uses: goreleaser/goreleaser-action@v4
with:
version: latest
args: --parallelism 1 --rm-dist --skip-validate
args: release --parallelism 1 --clean --skip-validate
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
113 changes: 107 additions & 6 deletions .goreleaser.yml
Expand Up @@ -24,7 +24,7 @@ builds:
- 6
- 7
ldflags:
- -s -w -X "main.buildString={{ .Tag }} ({{ .ShortCommit }} {{ .Date }})" -X "main.versionString={{ .Tag }}"
- -s -w -X "main.buildString={{ .Tag }} ({{ .ShortCommit }} {{ .Date }}, {{ .Os }}/{{ .Arch }})" -X "main.versionString={{ .Tag }}"

hooks:
# stuff executables with static assets.
Expand All @@ -37,15 +37,16 @@ archives:
- LICENSE

dockers:
- goos: linux
- use: buildx
goos: linux
goarch: amd64
ids:
- listmonk
image_templates:
- "listmonk/listmonk:latest"
- "listmonk/listmonk:{{ .Tag }}"
- "ghcr.io/knadh/{{ .ProjectName }}:latest"
- "ghcr.io/knadh/{{ .ProjectName }}:{{ .Tag }}"
- "listmonk/{{ .ProjectName }}:latest-amd64"
- "listmonk/{{ .ProjectName }}:{{ .Tag }}-amd64"
- "ghcr.io/knadh/{{ .ProjectName }}:latest-amd64"
- "ghcr.io/knadh/{{ .ProjectName }}:{{ .Tag }}-amd64"
build_flag_templates:
- --platform=linux/amd64
- --label=org.opencontainers.image.title={{ .ProjectName }}
Expand All @@ -60,3 +61,103 @@ dockers:
extra_files:
- config.toml.sample
- config-demo.toml
- use: buildx
goos: linux
goarch: arm64
ids:
- listmonk
image_templates:
- "listmonk/{{ .ProjectName }}:latest-arm64v8"
- "listmonk/{{ .ProjectName }}:{{ .Tag }}-arm64v8"
- "ghcr.io/knadh/{{ .ProjectName }}:latest-arm64v8"
- "ghcr.io/knadh/{{ .ProjectName }}:{{ .Tag }}-arm64v8"
build_flag_templates:
- --platform=linux/arm64/v8
- --label=org.opencontainers.image.title={{ .ProjectName }}
- --label=org.opencontainers.image.description={{ .ProjectName }}
- --label=org.opencontainers.image.url=https://github.com/knadh/{{ .ProjectName }}
- --label=org.opencontainers.image.source=https://github.com/knadh/{{ .ProjectName }}
- --label=org.opencontainers.image.version={{ .Version }}
- --label=org.opencontainers.image.created={{ time "2006-01-02T15:04:05Z07:00" }}
- --label=org.opencontainers.image.revision={{ .FullCommit }}
- --label=org.opencontainers.image.licenses=AGPL-3.0
dockerfile: Dockerfile
extra_files:
- config.toml.sample
- config-demo.toml
- use: buildx
goos: linux
goarch: arm
goarm: 6
ids:
- listmonk
image_templates:
- "listmonk/{{ .ProjectName }}:latest-armv6"
- "listmonk/{{ .ProjectName }}:{{ .Tag }}-armv6"
- "ghcr.io/knadh/{{ .ProjectName }}:latest-armv6"
- "ghcr.io/knadh/{{ .ProjectName }}:{{ .Tag }}-armv6"
build_flag_templates:
- --platform=linux/arm/v6
- --label=org.opencontainers.image.title={{ .ProjectName }}
- --label=org.opencontainers.image.description={{ .ProjectName }}
- --label=org.opencontainers.image.url=https://github.com/knadh/{{ .ProjectName }}
- --label=org.opencontainers.image.source=https://github.com/knadh/{{ .ProjectName }}
- --label=org.opencontainers.image.version={{ .Version }}
- --label=org.opencontainers.image.created={{ time "2006-01-02T15:04:05Z07:00" }}
- --label=org.opencontainers.image.revision={{ .FullCommit }}
- --label=org.opencontainers.image.licenses=AGPL-3.0
dockerfile: Dockerfile
extra_files:
- config.toml.sample
- config-demo.toml
- use: buildx
goos: linux
goarch: arm
goarm: 7
ids:
- listmonk
image_templates:
- "listmonk/{{ .ProjectName }}:latest-armv7"
- "listmonk/{{ .ProjectName }}:{{ .Tag }}-armv7"
- "ghcr.io/knadh/{{ .ProjectName }}:latest-armv7"
- "ghcr.io/knadh/{{ .ProjectName }}:{{ .Tag }}-armv7"
build_flag_templates:
- --platform=linux/arm/v7
- --label=org.opencontainers.image.title={{ .ProjectName }}
- --label=org.opencontainers.image.description={{ .ProjectName }}
- --label=org.opencontainers.image.url=https://github.com/knadh/{{ .ProjectName }}
- --label=org.opencontainers.image.source=https://github.com/knadh/{{ .ProjectName }}
- --label=org.opencontainers.image.version={{ .Version }}
- --label=org.opencontainers.image.created={{ time "2006-01-02T15:04:05Z07:00" }}
- --label=org.opencontainers.image.revision={{ .FullCommit }}
- --label=org.opencontainers.image.licenses=AGPL-3.0
dockerfile: Dockerfile
extra_files:
- config.toml.sample
- config-demo.toml

docker_manifests:
- name_template: listmonk/{{ .ProjectName }}:latest
image_templates:
- listmonk/{{ .ProjectName }}:latest-amd64
- listmonk/{{ .ProjectName }}:latest-arm64v8
- listmonk/{{ .ProjectName }}:latest-armv6
- listmonk/{{ .ProjectName }}:latest-armv7
- name_template: listmonk/{{ .ProjectName }}:{{ .Tag }}
image_templates:
- listmonk/{{ .ProjectName }}:{{ .Tag }}-amd64
- listmonk/{{ .ProjectName }}:{{ .Tag }}-arm64v8
- listmonk/{{ .ProjectName }}:{{ .Tag }}-armv6
- listmonk/{{ .ProjectName }}:{{ .Tag }}-armv7
- name_template: ghcr.io/knadh/{{ .ProjectName }}:latest
image_templates:
- ghcr.io/knadh/{{ .ProjectName }}:latest-amd64
- ghcr.io/knadh/{{ .ProjectName }}:latest-arm64v8
- ghcr.io/knadh/{{ .ProjectName }}:latest-armv6
- ghcr.io/knadh/{{ .ProjectName }}:latest-armv7
- name_template: ghcr.io/knadh/{{ .ProjectName }}:{{ .Tag }}
image_templates:
- ghcr.io/knadh/{{ .ProjectName }}:{{ .Tag }}-amd64
- ghcr.io/knadh/{{ .ProjectName }}:{{ .Tag }}-arm64v8
- ghcr.io/knadh/{{ .ProjectName }}:{{ .Tag }}-armv6
- ghcr.io/knadh/{{ .ProjectName }}:{{ .Tag }}-armv7

0 comments on commit 3663a8b

Please sign in to comment.