Skip to content

Commit 15f4927

Browse files
committed
Multiarch Docker build and publish
1 parent ef0efd0 commit 15f4927

File tree

3 files changed

+50
-24
lines changed

3 files changed

+50
-24
lines changed

.github/workflows/release.yml

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,28 +15,41 @@ jobs:
1515
- name: Install Go
1616
uses: actions/setup-go@v2
1717
with:
18-
go-version: 1.16.x
18+
go-version: 1.17.x
19+
1920
- name: Get release version
2021
id: get_version
2122
run: echo ::set-env name=RELEASE_VERSION::$(echo ${GITHUB_REF:10})
23+
2224
- name: Checkout code
2325
uses: actions/checkout@v2
26+
2427
- name: Get CloudFlare Token
2528
run: echo ::set-env name=CLOUDFLARE_TOKEN::${{ secrets.CLOUDFLARE_TOKEN }}
29+
2630
- name: Get Test Domain Name
2731
run: echo ::set-env name=TEST_DOMAIN::${{ secrets.TEST_DOMAIN }}
32+
2833
- name: Test and Build
2934
run: make test all shasums
35+
3036
- name: Release
3137
uses: softprops/action-gh-release@v1
3238
with:
3339
files: dist/cloudflare-ddns-*
3440
env:
3541
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
42+
43+
# https://github.com/docker/setup-qemu-action
44+
- name: Set up QEMU
45+
uses: docker/setup-qemu-action@v1
46+
47+
# https://github.com/docker/setup-buildx-action
48+
- name: Set up Docker Buildx
49+
uses: docker/setup-buildx-action@v1
50+
51+
- name: Login to Docker Hub
52+
run: echo "${{ secrets.DOCKER_PASSWORD }}" | docker login -u "${{ secrets.DOCKER_USERNAME }}" --password-stdin
53+
3654
- name: Publish to Docker Hub
37-
uses: elgohr/Publish-Docker-Github-Action@master
38-
with:
39-
name: ${{ secrets.DOCKER_USERNAME }}/cloudflare-ddns-client
40-
username: ${{ secrets.DOCKER_USERNAME }}
41-
password: ${{ secrets.DOCKER_PASSWORD }}
42-
tags: "latest,${{ env.RELEASE_VERSION }}"
55+
run: make docker-publish

Dockerfile

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
FROM alpine
2+
ARG TARGETOS
3+
ARG TARGETARCH
24
RUN apk add --no-cache ca-certificates
3-
COPY dist/cloudflare-ddns-linux-amd64 /bin/cloudflare-ddns
4-
ENTRYPOINT [ "/bin/cloudflare-ddns" ]
5+
COPY dist/cloudflare-ddns-${TARGETOS}-${TARGETARCH} /bin/cloudflare-ddns
6+
ENTRYPOINT [ "/bin/cloudflare-ddns" ]
7+
CMD ["--daemon"]

Makefile

Lines changed: 25 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,40 @@
11
# Version and linker flags
22
# This will return either the current tag, branch, or commit hash of this repo.
3-
MODULE := $(shell awk 'NR==1{print $$2}' go.mod)
4-
REPO_NAME := cloudflare-ddns
5-
VERSION := $(shell echo $$(ver=$$(git tag -l --points-at HEAD) && [ -z $$ver ] && ver=$$(git describe --always --dirty); printf $$ver))
6-
LDFLAGS := -s -w -X $(MODULE)/conf.Version=$(VERSION) -X $(MODULE)/conf.ModuleName=$(MODULE)
7-
FLAGS := -trimpath
8-
PROJECT_ROOT := $(shell cd -P -- '$(shell dirname -- "$0")' && pwd -P)
9-
BIN_NAME := cloudflare-ddns
10-
DIST := dist
11-
UNAME := $(shell uname)
12-
GOTESTSUM := go run gotest.tools/gotestsum
13-
GOVERALLS := go run github.com/mattn/goveralls
14-
SOURCE := $(shell find $(PROJECT_ROOT) -name '*.go')
15-
BINS := $(shell find $(DIST) -name '$(BIN_NAME)-*')
16-
PLATFORMS ?= darwin-amd64 dragonfly-amd64 freebsd-amd64 freebsd-arm freebsd-arm64 linux-amd64 linux-arm linux-arm64 netbsd-amd64 netbsd-arm netbsd-arm64 openbsd-amd64 openbsd-arm openbsd-arm64 windows-amd64 windows-arm
3+
MODULE := $(shell awk 'NR==1{print $$2}' go.mod)
4+
REPO_NAME := cloudflare-ddns
5+
VERSION := $(shell echo $$(ver=$$(git tag -l --points-at HEAD) && [ -z $$ver ] && ver=$$(git describe --always --dirty); printf $$ver))
6+
# This is set during CI in .github/workflows/release.yml
7+
RELEASE_VERSION ?= $(VERSION)
8+
LDFLAGS := -s -w -X $(MODULE)/conf.Version=$(VERSION) -X $(MODULE)/conf.ModuleName=$(MODULE)
9+
FLAGS := -trimpath
10+
PROJECT_ROOT := $(shell cd -P -- '$(shell dirname -- "$0")' && pwd -P)
11+
BIN_NAME := cloudflare-ddns
12+
DIST := dist
13+
UNAME := $(shell uname)
14+
GOTESTSUM := go run gotest.tools/gotestsum
15+
GOVERALLS := go run github.com/mattn/goveralls
16+
SOURCE := $(shell find $(PROJECT_ROOT) -name '*.go')
17+
BINS := $(shell find $(DIST) -name '$(BIN_NAME)-*')
18+
PLATFORMS ?= darwin-amd64 dragonfly-amd64 freebsd-amd64 freebsd-arm freebsd-arm64 linux-amd64 linux-arm linux-arm64 netbsd-amd64 netbsd-arm netbsd-arm64 openbsd-amd64 openbsd-arm openbsd-arm64 windows-amd64 windows-arm
19+
DOCKER_PLATFORMS ?= linux/amd64 linux/arm64
20+
DOCKER_REPO ?= mattolenik
21+
DOCKER_TAG ?= $(DOCKER_REPO)/cloudflare-ddns-client
22+
DOCKER_TAG_LATEST := $(DOCKER_TAG):latest
23+
DOCKER_TAG_VERSIONED := $(DOCKER_TAG):$(RELEASE_VERSION)
1724

1825
export TEST_BINARY := $(DIST)/$(BIN_NAME)
1926

20-
default: all shasums test readme
27+
default: all shasums readme test
2128

2229
build: $(DIST)/$(BIN_NAME)
2330
$(DIST)/$(BIN_NAME): $(SOURCE)
2431
go build $(ARGS) $(FLAGS) -ldflags="$(LDFLAGS)" -o $@
2532

2633
all: $(addprefix $(DIST)/$(BIN_NAME)-,$(PLATFORMS))
2734

35+
docker-publish:
36+
docker buildx build --push --tag $(DOCKER_TAG_LATEST) --tag $(DOCKER_TAG_VERSIONED) --platform linux/amd64,linux/arm64 .
37+
2838
clean:
2939
rm -rf dist && mkdir dist
3040

0 commit comments

Comments
 (0)