diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..ba10357 --- /dev/null +++ b/.dockerignore @@ -0,0 +1,5 @@ +* +!cmd/ +!go.mod +!go.sum +!main.go diff --git a/.github/workflows/flow-pr.yml b/.github/workflows/flow-pr.yml index 76d560c..dddbba4 100644 --- a/.github/workflows/flow-pr.yml +++ b/.github/workflows/flow-pr.yml @@ -4,7 +4,7 @@ name: PR Flow on: pull_request: branches: - - master + - main paths: - "main.go" - "go.mod" diff --git a/.goreleaser.yml b/.goreleaser.yml index c3bff51..9e332b9 100644 --- a/.goreleaser.yml +++ b/.goreleaser.yml @@ -1,5 +1,4 @@ -# Make sure to check the documentation at https://goreleaser.com ---- +project_name: cloudflare-dynamic-dns before: hooks: - go mod tidy @@ -31,7 +30,7 @@ archives: - README.md - systemd/* checksum: - name_template: "checksums.txt" + name_template: checksums.txt snapshot: name_template: "{{ incpatch .Version }}-next" changelog: @@ -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 diff --git a/.goreleaser.ytt.yml b/.goreleaser.ytt.yml new file mode 100644 index 0000000..ecd9ce7 --- /dev/null +++ b/.goreleaser.ytt.yml @@ -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) diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..a09d32f --- /dev/null +++ b/Dockerfile @@ -0,0 +1,3 @@ +FROM scratch +COPY . / +ENTRYPOINT ["/cloudflare-dynamic-dns"] diff --git a/README.md b/README.md index f3f50a9..63094be 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/Taskfile.yaml b/Taskfile.yaml index f3a917c..040206e 100644 --- a/Taskfile.yaml +++ b/Taskfile.yaml @@ -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 diff --git a/dev.Dockerfile b/dev.Dockerfile new file mode 100644 index 0000000..dd1223a --- /dev/null +++ b/dev.Dockerfile @@ -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"]