Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add Docker support #64

Merged
merged 6 commits into from
Aug 30, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
*
!cmd/
!go.mod
!go.sum
!main.go
2 changes: 1 addition & 1 deletion .github/workflows/flow-pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ name: PR Flow
on:
pull_request:
branches:
- master
- main
paths:
- "main.go"
- "go.mod"
Expand Down
199 changes: 196 additions & 3 deletions .goreleaser.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
# Make sure to check the documentation at https://goreleaser.com
---
project_name: cloudflare-dynamic-dns
before:
hooks:
- go mod tidy
Expand Down Expand Up @@ -31,7 +30,7 @@ archives:
- README.md
- systemd/*
checksum:
name_template: "checksums.txt"
name_template: checksums.txt
snapshot:
name_template: "{{ incpatch .Version }}-next"
changelog:
Expand All @@ -40,3 +39,197 @@ changelog:
exclude:
- "^docs:"
- "^test:"
dockers:
- goos: linux
goarch: amd64
image_templates:
- ghcr.io/zebradil/cloudflare-dynamic-dns:{{ .Tag }}-linux-amd64
- ghcr.io/zebradil/cloudflare-dynamic-dns:{{ .Major }}-linux-amd64
- ghcr.io/zebradil/cloudflare-dynamic-dns:{{ .Major }}.{{ .Minor }}-linux-amd64
- ghcr.io/zebradil/cloudflare-dynamic-dns:latest-linux-amd64
use: buildx
build_flag_templates:
- --platform=linux/amd64
- goos: linux
goarch: "386"
image_templates:
- ghcr.io/zebradil/cloudflare-dynamic-dns:{{ .Tag }}-linux-386
- ghcr.io/zebradil/cloudflare-dynamic-dns:{{ .Major }}-linux-386
- ghcr.io/zebradil/cloudflare-dynamic-dns:{{ .Major }}.{{ .Minor }}-linux-386
- ghcr.io/zebradil/cloudflare-dynamic-dns:latest-linux-386
use: buildx
build_flag_templates:
- --platform=linux/386
- goos: linux
goarch: arm64
image_templates:
- ghcr.io/zebradil/cloudflare-dynamic-dns:{{ .Tag }}-linux-arm64
- ghcr.io/zebradil/cloudflare-dynamic-dns:{{ .Major }}-linux-arm64
- ghcr.io/zebradil/cloudflare-dynamic-dns:{{ .Major }}.{{ .Minor }}-linux-arm64
- ghcr.io/zebradil/cloudflare-dynamic-dns:latest-linux-arm64
use: buildx
build_flag_templates:
- --platform=linux/arm64
- goos: linux
goarch: arm
goarm: "6"
image_templates:
- ghcr.io/zebradil/cloudflare-dynamic-dns:{{ .Tag }}-linux-arm-6
- ghcr.io/zebradil/cloudflare-dynamic-dns:{{ .Major }}-linux-arm-6
- ghcr.io/zebradil/cloudflare-dynamic-dns:{{ .Major }}.{{ .Minor }}-linux-arm-6
- ghcr.io/zebradil/cloudflare-dynamic-dns:latest-linux-arm-6
use: buildx
build_flag_templates:
- --platform=linux/arm/6
- goos: linux
goarch: arm
goarm: "7"
image_templates:
- ghcr.io/zebradil/cloudflare-dynamic-dns:{{ .Tag }}-linux-arm-7
- ghcr.io/zebradil/cloudflare-dynamic-dns:{{ .Major }}-linux-arm-7
- ghcr.io/zebradil/cloudflare-dynamic-dns:{{ .Major }}.{{ .Minor }}-linux-arm-7
- ghcr.io/zebradil/cloudflare-dynamic-dns:latest-linux-arm-7
use: buildx
build_flag_templates:
- --platform=linux/arm/7
- goos: linux
goarch: mips
image_templates:
- ghcr.io/zebradil/cloudflare-dynamic-dns:{{ .Tag }}-linux-mips
- ghcr.io/zebradil/cloudflare-dynamic-dns:{{ .Major }}-linux-mips
- ghcr.io/zebradil/cloudflare-dynamic-dns:{{ .Major }}.{{ .Minor }}-linux-mips
- ghcr.io/zebradil/cloudflare-dynamic-dns:latest-linux-mips
use: buildx
build_flag_templates:
- --platform=linux/mips
- goos: linux
goarch: mipsle
image_templates:
- ghcr.io/zebradil/cloudflare-dynamic-dns:{{ .Tag }}-linux-mipsle
- ghcr.io/zebradil/cloudflare-dynamic-dns:{{ .Major }}-linux-mipsle
- ghcr.io/zebradil/cloudflare-dynamic-dns:{{ .Major }}.{{ .Minor }}-linux-mipsle
- ghcr.io/zebradil/cloudflare-dynamic-dns:latest-linux-mipsle
use: buildx
build_flag_templates:
- --platform=linux/mipsle
- goos: linux
goarch: mips64
image_templates:
- ghcr.io/zebradil/cloudflare-dynamic-dns:{{ .Tag }}-linux-mips64
- ghcr.io/zebradil/cloudflare-dynamic-dns:{{ .Major }}-linux-mips64
- ghcr.io/zebradil/cloudflare-dynamic-dns:{{ .Major }}.{{ .Minor }}-linux-mips64
- ghcr.io/zebradil/cloudflare-dynamic-dns:latest-linux-mips64
use: buildx
build_flag_templates:
- --platform=linux/mips64
- goos: linux
goarch: mips64le
image_templates:
- ghcr.io/zebradil/cloudflare-dynamic-dns:{{ .Tag }}-linux-mips64le
- ghcr.io/zebradil/cloudflare-dynamic-dns:{{ .Major }}-linux-mips64le
- ghcr.io/zebradil/cloudflare-dynamic-dns:{{ .Major }}.{{ .Minor }}-linux-mips64le
- ghcr.io/zebradil/cloudflare-dynamic-dns:latest-linux-mips64le
use: buildx
build_flag_templates:
- --platform=linux/mips64le
- goos: darwin
goarch: amd64
image_templates:
- ghcr.io/zebradil/cloudflare-dynamic-dns:{{ .Tag }}-darwin-amd64
- ghcr.io/zebradil/cloudflare-dynamic-dns:{{ .Major }}-darwin-amd64
- ghcr.io/zebradil/cloudflare-dynamic-dns:{{ .Major }}.{{ .Minor }}-darwin-amd64
- ghcr.io/zebradil/cloudflare-dynamic-dns:latest-darwin-amd64
use: buildx
build_flag_templates:
- --platform=darwin/amd64
- goos: darwin
goarch: arm64
image_templates:
- ghcr.io/zebradil/cloudflare-dynamic-dns:{{ .Tag }}-darwin-arm64
- ghcr.io/zebradil/cloudflare-dynamic-dns:{{ .Major }}-darwin-arm64
- ghcr.io/zebradil/cloudflare-dynamic-dns:{{ .Major }}.{{ .Minor }}-darwin-arm64
- ghcr.io/zebradil/cloudflare-dynamic-dns:latest-darwin-arm64
use: buildx
build_flag_templates:
- --platform=darwin/arm64
- goos: windows
goarch: amd64
image_templates:
- ghcr.io/zebradil/cloudflare-dynamic-dns:{{ .Tag }}-windows-amd64
- ghcr.io/zebradil/cloudflare-dynamic-dns:{{ .Major }}-windows-amd64
- ghcr.io/zebradil/cloudflare-dynamic-dns:{{ .Major }}.{{ .Minor }}-windows-amd64
- ghcr.io/zebradil/cloudflare-dynamic-dns:latest-windows-amd64
use: buildx
build_flag_templates:
- --platform=windows/amd64
- goos: windows
goarch: "386"
image_templates:
- ghcr.io/zebradil/cloudflare-dynamic-dns:{{ .Tag }}-windows-386
- ghcr.io/zebradil/cloudflare-dynamic-dns:{{ .Major }}-windows-386
- ghcr.io/zebradil/cloudflare-dynamic-dns:{{ .Major }}.{{ .Minor }}-windows-386
- ghcr.io/zebradil/cloudflare-dynamic-dns:latest-windows-386
use: buildx
build_flag_templates:
- --platform=windows/386
docker_manifests:
- name_template: ghcr.io/zebradil/cloudflare-dynamic-dns:{{ .Tag }}
image_templates:
- ghcr.io/zebradil/cloudflare-dynamic-dns:{{ .Tag }}-linux-amd64
- ghcr.io/zebradil/cloudflare-dynamic-dns:{{ .Tag }}-linux-386
- ghcr.io/zebradil/cloudflare-dynamic-dns:{{ .Tag }}-linux-arm64
- ghcr.io/zebradil/cloudflare-dynamic-dns:{{ .Tag }}-linux-arm-6
- ghcr.io/zebradil/cloudflare-dynamic-dns:{{ .Tag }}-linux-arm-7
- ghcr.io/zebradil/cloudflare-dynamic-dns:{{ .Tag }}-linux-mips
- ghcr.io/zebradil/cloudflare-dynamic-dns:{{ .Tag }}-linux-mipsle
- ghcr.io/zebradil/cloudflare-dynamic-dns:{{ .Tag }}-linux-mips64
- ghcr.io/zebradil/cloudflare-dynamic-dns:{{ .Tag }}-linux-mips64le
- ghcr.io/zebradil/cloudflare-dynamic-dns:{{ .Tag }}-darwin-amd64
- ghcr.io/zebradil/cloudflare-dynamic-dns:{{ .Tag }}-darwin-arm64
- ghcr.io/zebradil/cloudflare-dynamic-dns:{{ .Tag }}-windows-amd64
- ghcr.io/zebradil/cloudflare-dynamic-dns:{{ .Tag }}-windows-386
- name_template: ghcr.io/zebradil/cloudflare-dynamic-dns:{{ .Major }}
image_templates:
- ghcr.io/zebradil/cloudflare-dynamic-dns:{{ .Major }}-linux-amd64
- ghcr.io/zebradil/cloudflare-dynamic-dns:{{ .Major }}-linux-386
- ghcr.io/zebradil/cloudflare-dynamic-dns:{{ .Major }}-linux-arm64
- ghcr.io/zebradil/cloudflare-dynamic-dns:{{ .Major }}-linux-arm-6
- ghcr.io/zebradil/cloudflare-dynamic-dns:{{ .Major }}-linux-arm-7
- ghcr.io/zebradil/cloudflare-dynamic-dns:{{ .Major }}-linux-mips
- ghcr.io/zebradil/cloudflare-dynamic-dns:{{ .Major }}-linux-mipsle
- ghcr.io/zebradil/cloudflare-dynamic-dns:{{ .Major }}-linux-mips64
- ghcr.io/zebradil/cloudflare-dynamic-dns:{{ .Major }}-linux-mips64le
- ghcr.io/zebradil/cloudflare-dynamic-dns:{{ .Major }}-darwin-amd64
- ghcr.io/zebradil/cloudflare-dynamic-dns:{{ .Major }}-darwin-arm64
- ghcr.io/zebradil/cloudflare-dynamic-dns:{{ .Major }}-windows-amd64
- ghcr.io/zebradil/cloudflare-dynamic-dns:{{ .Major }}-windows-386
- name_template: ghcr.io/zebradil/cloudflare-dynamic-dns:{{ .Major }}.{{ .Minor }}
image_templates:
- ghcr.io/zebradil/cloudflare-dynamic-dns:{{ .Major }}.{{ .Minor }}-linux-amd64
- ghcr.io/zebradil/cloudflare-dynamic-dns:{{ .Major }}.{{ .Minor }}-linux-386
- ghcr.io/zebradil/cloudflare-dynamic-dns:{{ .Major }}.{{ .Minor }}-linux-arm64
- ghcr.io/zebradil/cloudflare-dynamic-dns:{{ .Major }}.{{ .Minor }}-linux-arm-6
- ghcr.io/zebradil/cloudflare-dynamic-dns:{{ .Major }}.{{ .Minor }}-linux-arm-7
- ghcr.io/zebradil/cloudflare-dynamic-dns:{{ .Major }}.{{ .Minor }}-linux-mips
- ghcr.io/zebradil/cloudflare-dynamic-dns:{{ .Major }}.{{ .Minor }}-linux-mipsle
- ghcr.io/zebradil/cloudflare-dynamic-dns:{{ .Major }}.{{ .Minor }}-linux-mips64
- ghcr.io/zebradil/cloudflare-dynamic-dns:{{ .Major }}.{{ .Minor }}-linux-mips64le
- ghcr.io/zebradil/cloudflare-dynamic-dns:{{ .Major }}.{{ .Minor }}-darwin-amd64
- ghcr.io/zebradil/cloudflare-dynamic-dns:{{ .Major }}.{{ .Minor }}-darwin-arm64
- ghcr.io/zebradil/cloudflare-dynamic-dns:{{ .Major }}.{{ .Minor }}-windows-amd64
- ghcr.io/zebradil/cloudflare-dynamic-dns:{{ .Major }}.{{ .Minor }}-windows-386
- name_template: ghcr.io/zebradil/cloudflare-dynamic-dns:latest
image_templates:
- ghcr.io/zebradil/cloudflare-dynamic-dns:latest-linux-amd64
- ghcr.io/zebradil/cloudflare-dynamic-dns:latest-linux-386
- ghcr.io/zebradil/cloudflare-dynamic-dns:latest-linux-arm64
- ghcr.io/zebradil/cloudflare-dynamic-dns:latest-linux-arm-6
- ghcr.io/zebradil/cloudflare-dynamic-dns:latest-linux-arm-7
- ghcr.io/zebradil/cloudflare-dynamic-dns:latest-linux-mips
- ghcr.io/zebradil/cloudflare-dynamic-dns:latest-linux-mipsle
- ghcr.io/zebradil/cloudflare-dynamic-dns:latest-linux-mips64
- ghcr.io/zebradil/cloudflare-dynamic-dns:latest-linux-mips64le
- ghcr.io/zebradil/cloudflare-dynamic-dns:latest-darwin-amd64
- ghcr.io/zebradil/cloudflare-dynamic-dns:latest-darwin-arm64
- ghcr.io/zebradil/cloudflare-dynamic-dns:latest-windows-amd64
- ghcr.io/zebradil/cloudflare-dynamic-dns:latest-windows-386
98 changes: 98 additions & 0 deletions .goreleaser.ytt.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
#@ project_name = 'cloudflare-dynamic-dns'
#@ targets = [
#@ ("linux", "amd64", ""),
#@ ("linux", "386", ""),
#@ ("linux", "arm64", ""),
#@ ("linux", "arm", "6"),
#@ ("linux", "arm", "7"),
#@ ("linux", "mips", ""),
#@ ("linux", "mipsle", ""),
#@ ("linux", "mips64", ""),
#@ ("linux", "mips64le", ""),
#@ ("darwin", "amd64", ""),
#@ ("darwin", "arm64", ""),
#@ ("windows", "amd64", ""),
#@ ("windows", "386", ""),
#@ ]
#@ versions = [
#@ '{{ .Tag }}',
#@ '{{ .Major }}',
#@ '{{ .Major }}.{{ .Minor }}',
#@ 'latest',
#@ ]

#@ base_image = 'ghcr.io/zebradil/' + project_name

#@ def make_target(os, arch, arm):
#@ target = os + "_" + arch
#@ if arm:
#@ target += "_" + arm
#@ end
#@ return target
#@ end

#@ def make_image(version, os, arch, arm):
#@ image = base_image + ":" + version + "-" + os + "-" + arch
#@ if arm:
#@ image += "-" + arm
#@ end
#@ return image
#@ end

#@ def make_platform(os, arch, arm):
#@ platform = "--platform=" + os + "/" + arch
#@ if arm:
#@ platform += "/" + arm
#@ end
#@ return platform
#@ end

---
project_name: #@ project_name
before:
hooks:
- go mod tidy
builds:
- binary: #@ project_name
env:
- CGO_ENABLED=0
targets:
#@ for/end os, arch, arm in targets:
- #@ make_target(os, arch, arm)
archives:
- name_template: "{{ .ProjectName }}_{{ .Os }}_{{ .Arch }}{{ if .Arm }}v{{ .Arm }}{{ end }}"
format_overrides:
- goos: windows
format: zip
files:
- LICENSE
- README.md
- systemd/*
checksum:
name_template: "checksums.txt"
snapshot:
name_template: "{{ incpatch .Version }}-next"
changelog:
sort: asc
filters:
exclude:
- "^docs:"
- "^test:"
dockers:
#@ for/end os, arch, arm in targets:
- goos: #@ os
goarch: #@ arch
#@ if/end arm:
goarm: #@ arm
image_templates:
#@ for/end version in versions:
- #@ make_image(version, os, arch, arm)
use: buildx
build_flag_templates:
- #@ make_platform(os, arch, arm)
docker_manifests:
#@ for/end version in versions:
- name_template: #@ base_image + ":" + version
image_templates:
#@ for/end os, arch, arm in targets:
- #@ make_image(version, os, arch, arm)
3 changes: 3 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
FROM scratch
COPY . /
ENTRYPOINT ["/cloudflare-dynamic-dns"]
12 changes: 10 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -148,12 +148,20 @@ Use the following Taskfile tasks to build the application:

```shell
# Build with go for the current platform
task build
go build -o cloudflare-dynamic-dns main.go

# Build with GoReleaser for all configured platforms
task goreleaser:build
task build

# Use Docker
docker build -t cloudflare-dynamic-dns -f dev.Dockerfile .
```

### GeReleaser

Do not change `.goreleaser.yml` manually, do changes in `.goreleaser.ytt.yml` and run
`task misc:build:goreleaser-config` instead (requires [`ytt`](https://carvel.dev/ytt/) installed).

## License

MIT
5 changes: 5 additions & 0 deletions Taskfile.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -45,3 +45,8 @@ tasks:
- go:build
cmds:
- bin/{{.BIN_NAME}} {{.CLI_ARGS}}

misc:build:goreleaser-config:
desc: Renders .gorleaser.yml from .goreleaser.ytt.yml
cmds:
- ytt -f .goreleaser.ytt.yml > .goreleaser.yml
12 changes: 12 additions & 0 deletions dev.Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
FROM golang:1.21

WORKDIR /app

COPY go.mod go.sum ./

RUN go mod download

COPY . .
RUN go build -o bin/cloudflare-dynamic-dns main.go

ENTRYPOINT ["/app/bin/cloudflare-dynamic-dns"]