Skip to content

Commit

Permalink
chore: Use goreleaser to build a docker image (#1371)
Browse files Browse the repository at this point in the history
* chore: snapshot.name_template

`snapshot.name_template` should not be used anymore, check https://goreleaser.com/deprecations#snapshotname_template for more info

* chore: Use goreleaser to build a docker image
  • Loading branch information
PairZhu authored Jan 18, 2025
1 parent c68080b commit 7cdbf87
Show file tree
Hide file tree
Showing 4 changed files with 98 additions and 67 deletions.
51 changes: 0 additions & 51 deletions .github/workflows/docker-image.yml

This file was deleted.

21 changes: 21 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ on:

permissions:
contents: write
packages: write

jobs:
goreleaser:
Expand All @@ -24,6 +25,25 @@ jobs:
with:
go-version-file: 'go.mod'

- name: Set up QEMU
uses: docker/setup-qemu-action@v3

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3

- name: Login to Docker Hub
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}

- name: Login to GitHub Container Registry
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Run GoReleaser
uses: goreleaser/goreleaser-action@v6
if: startsWith(github.ref, 'refs/tags/')
Expand All @@ -33,6 +53,7 @@ jobs:
args: release --clean
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
DOCKER_USERNAME: ${{ secrets.DOCKER_USERNAME }}

homebrew:
needs: goreleaser
Expand Down
76 changes: 74 additions & 2 deletions .goreleaser.yml
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,12 @@ builds:
goarch: '386'
- goos: android
goarch: amd64

ldflags:
- -s -w -X main.version={{.Tag}} -X main.buildTime={{.Date}}
hooks:
post:
- sh -c '[ ! -d "zoneinfo" ] && cp -r /usr/share/zoneinfo . || true'

archives:
# use zip for windows archives
- format_overrides:
Expand All @@ -62,13 +65,82 @@ archives:
{{- else }}{{ .Arch }}{{ end }}
{{- if .Mips }}_{{ .Mips }}{{ end }}
{{- if .Arm }}v{{ .Arm }}{{ end }}
checksum:
name_template: 'checksums.txt'
snapshot:
name_template: '{{ .Tag }}-next'
version_template: "{{ incpatch .Version }}-devel"
changelog:
sort: asc
filters:
exclude:
- '^docs:'
- '^test:'

dockers:
- image_templates:
- "{{ .Env.DOCKER_USERNAME }}/ddns-go:{{ .Tag }}-amd64"
- "ghcr.io/{{ tolower .Env.GITHUB_REPOSITORY }}:{{ .Tag }}-amd64"
use: buildx
extra_files:
- zoneinfo
build_flag_templates:
- "--platform=linux/amd64"
- "--label=org.opencontainers.image.created={{.Date}}"
- "--label=org.opencontainers.image.title={{.ProjectName}}"
- "--label=org.opencontainers.image.revision={{.FullCommit}}"
- "--label=org.opencontainers.image.version={{.Version}}"

- image_templates:
- "{{ .Env.DOCKER_USERNAME }}/ddns-go:{{ .Tag }}-arm64"
- "ghcr.io/{{ tolower .Env.GITHUB_REPOSITORY }}:{{ .Tag }}-arm64"
use: buildx
extra_files:
- zoneinfo
build_flag_templates:
- "--platform=linux/arm64"
- "--label=org.opencontainers.image.created={{.Date}}"
- "--label=org.opencontainers.image.title={{.ProjectName}}"
- "--label=org.opencontainers.image.revision={{.FullCommit}}"
- "--label=org.opencontainers.image.version={{.Version}}"
goarch: arm64

- image_templates:
- "{{ .Env.DOCKER_USERNAME }}/ddns-go:{{ .Tag }}-armv7"
- "ghcr.io/{{ tolower .Env.GITHUB_REPOSITORY }}:{{ .Tag }}-armv7"
use: buildx
extra_files:
- zoneinfo
build_flag_templates:
- "--platform=linux/arm/v7"
- "--label=org.opencontainers.image.created={{.Date}}"
- "--label=org.opencontainers.image.title={{.ProjectName}}"
- "--label=org.opencontainers.image.revision={{.FullCommit}}"
- "--label=org.opencontainers.image.version={{.Version}}"
goarch: arm
goarm: 7

docker_manifests:
- name_template: "{{ .Env.DOCKER_USERNAME }}/ddns-go:{{ .Tag }}"
image_templates:
- "{{ .Env.DOCKER_USERNAME }}/ddns-go:{{ .Tag }}-amd64"
- "{{ .Env.DOCKER_USERNAME }}/ddns-go:{{ .Tag }}-arm64"
- "{{ .Env.DOCKER_USERNAME }}/ddns-go:{{ .Tag }}-armv7"

- name_template: "{{ .Env.DOCKER_USERNAME }}/ddns-go:latest"
image_templates:
- "{{ .Env.DOCKER_USERNAME }}/ddns-go:{{ .Tag }}-amd64"
- "{{ .Env.DOCKER_USERNAME }}/ddns-go:{{ .Tag }}-arm64"
- "{{ .Env.DOCKER_USERNAME }}/ddns-go:{{ .Tag }}-armv7"

- name_template: "ghcr.io/{{ tolower .Env.GITHUB_REPOSITORY }}:{{ .Tag }}"
image_templates:
- "ghcr.io/{{ tolower .Env.GITHUB_REPOSITORY }}:{{ .Tag }}-amd64"
- "ghcr.io/{{ tolower .Env.GITHUB_REPOSITORY }}:{{ .Tag }}-arm64"
- "ghcr.io/{{ tolower .Env.GITHUB_REPOSITORY }}:{{ .Tag }}-armv7"

- name_template: "ghcr.io/{{ tolower .Env.GITHUB_REPOSITORY }}:latest"
image_templates:
- "ghcr.io/{{ tolower .Env.GITHUB_REPOSITORY }}:{{ .Tag }}-amd64"
- "ghcr.io/{{ tolower .Env.GITHUB_REPOSITORY }}:{{ .Tag }}-arm64"
- "ghcr.io/{{ tolower .Env.GITHUB_REPOSITORY }}:{{ .Tag }}-armv7"
17 changes: 3 additions & 14 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,23 +1,12 @@
# build stage
FROM --platform=$BUILDPLATFORM golang:1.20-alpine AS builder

WORKDIR /app
COPY . .
ARG TARGETOS TARGETARCH

RUN apk add --no-cache git make tzdata \
&& GOOS=$TARGETOS GOARCH=$TARGETARCH make clean build

# final stage
FROM alpine
LABEL name=ddns-go
LABEL url=https://github.com/jeessy2/ddns-go
RUN apk add --no-cache curl grep

WORKDIR /app
COPY --from=builder /usr/share/zoneinfo /usr/share/zoneinfo
COPY ddns-go /app/
COPY zoneinfo /usr/share/zoneinfo
ENV TZ=Asia/Shanghai
COPY --from=builder /app/ddns-go /app/ddns-go
EXPOSE 9876
ENTRYPOINT ["/app/ddns-go"]
CMD ["-l", ":9876", "-f", "300"]
CMD ["-l", ":9876", "-f", "300"]

0 comments on commit 7cdbf87

Please sign in to comment.