-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile.release
140 lines (126 loc) · 4.78 KB
/
Makefile.release
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
# Makefile for release
EMPTY:=
SPACE:=$(EMPTY) $(EMPTY)
COMMA:=$(EMPTY),$(EMPTY)
ifeq (, $(shell which curl))
$(error "No curl in $$PATH, please install")
endif
NAME:=dns
COMMANDS=ludns resolvcache resolvcheck resolvcollect
VERSION=$(shell git describe --match 'v[0-9]*' --dirty='.m' --always | sed 's/^v//')
LINUX_ARCH:=amd64 arm arm64 ppc64le s390x mips mips64le
FREEBSD_ARCH:=amd64
OPENBSD_ARCH:=amd64
WINDOWS_ARCH:=amd64
DARWIN_ARCH:=amd64
GITHUB_ORG:=luids-io
DOCKER_ORG:=luids
DOCKER_PLATFORMS="linux/amd64,linux/arm64,linux/arm/v6,linux/arm/v7,linux/ppc64le,linux/s390x"
all:
@echo "Use the 'release' target to build and 'github-push' or 'docker-push' to publish."
release: build tar installer
.PHONY: build
build:
@echo Cleaning old builds
@rm -rf build && mkdir build
@echo Building: freebsd/$(FREEBSD_ARCH) - $(VERSION) ;\
for arch in $(FREEBSD_ARCH); do \
mkdir -p build/freebsd/$$arch ; \
for cmd in $(COMMANDS); do \
$(MAKE) release COMMAND=$$cmd BINARY=build/freebsd/$${arch}/$${cmd} \
SYSTEM="GOOS=freebsd GOARCH=$$arch" CHECKS="" BUILDOPTS="" ;\
done ; \
done
@echo Building: openbsd/$(OPENBSD_ARCH) - $(VERSION) ;\
for arch in $(OPENBSD_ARCH); do \
mkdir -p build/openbsd/$$arch ; \
for cmd in $(COMMANDS); do \
$(MAKE) release COMMAND=$$cmd BINARY=build/openbsd/$${arch}/$${cmd} \
SYSTEM="GOOS=openbsd GOARCH=$$arch" CHECKS="" BUILDOPTS="" ;\
done ; \
done
@echo Building: linux/$(LINUX_ARCH) - $(VERSION) ;\
for arch in $(LINUX_ARCH); do \
mkdir -p build/linux/$$arch ; \
for cmd in $(COMMANDS); do \
$(MAKE) release COMMAND=$$cmd BINARY=build/linux/$${arch}/$${cmd} \
SYSTEM="GOOS=linux GOARCH=$$arch" CHECKS="" BUILDOPTS="" ;\
done ; \
done
@echo Building: darwin/$(DARWIN_ARCH) - $(VERSION) ;\
for arch in $(DARWIN_ARCH); do \
mkdir -p build/darwin/$$arch ; \
for cmd in $(COMMANDS); do \
$(MAKE) release COMMAND=$$cmd BINARY=build/darwin/$${arch}/$${cmd} \
SYSTEM="GOOS=darwin GOARCH=$$arch" CHECKS="" BUILDOPTS="" ;\
done ; \
done
@echo Building: windows/$(WINDOWS_ARCH) - $(VERSION) ;\
for arch in $(WINDOWS_ARCH); do \
mkdir -p build/windows/$$arch ; \
for cmd in $(COMMANDS); do \
$(MAKE) release COMMAND=$$cmd BINARY=build/windows/$${arch}/$${cmd} \
SYSTEM="GOOS=windows GOARCH=$$arch" CHECKS="" BUILDOPTS="" ;\
done ; \
done
.PHONY: tar
tar:
@echo Cleaning old releases
@rm -rf release && mkdir release
for arch in $(LINUX_ARCH); do \
tar -zcf release/$(NAME)_$(VERSION)_linux_$$arch.tgz -C build/linux/$$arch . ;\
done
for arch in $(FREEBSD_ARCH); do \
tar -zcf release/$(NAME)_$(VERSION)_freebsd_$$arch.tgz -C build/freebsd/$$arch . ;\
done
for arch in $(OPENBSD_ARCH); do \
tar -zcf release/$(NAME)_$(VERSION)_openbsd_$$arch.tgz -C build/openbsd/$$arch . ;\
done
for arch in $(DARWIN_ARCH); do \
tar -zcf release/$(NAME)_$(VERSION)_darwin_$$arch.tgz -C build/darwin/$$arch . ;\
done
for arch in $(WINDOWS_ARCH); do \
tar -zcf release/$(NAME)_$(VERSION)_windows_$$arch.tgz -C build/windows/$$arch . ;\
done
.PHONY: installer
installer:
cp deployments/installer/installer_linux.sh release/installer_linux.sh
sed -i 's/RELEASE="RELEASE"/RELEASE="$(VERSION)"/' release/installer_linux.sh
.PHONY: docker-push
docker-push:
@echo Creating docker multiplatform and pushing images
docker buildx build -t $(DOCKER_ORG)/ludns -t $(DOCKER_ORG)/ludns:$(VERSION) \
--platform $(DOCKER_PLATFORMS) -f Dockerfile.ludns --push .
docker buildx build -t $(DOCKER_ORG)/resolvcache -t $(DOCKER_ORG)/resolvcache:$(VERSION) \
--platform $(DOCKER_PLATFORMS) -f Dockerfile.resolvcache --push .
.PHONY: github-push
github-push:
@echo Releasing: $(VERSION)
@$(eval RELEASE:=$(shell curl -s -d '{"tag_name": "v$(VERSION)", "name": "v$(VERSION)"}' -H "Authorization: token ${GITHUB_ACCESS_TOKEN}" "https://api.github.com/repos/$(GITHUB_ORG)/$(NAME)/releases" | grep -m 1 '"id"' | tr -cd '[[:digit:]]'))
@echo ReleaseID: $(RELEASE)
@( cd release; for asset in `ls -A *tgz installer*`; do \
echo $$asset; \
curl -o /dev/null -X POST \
-H "Content-Type: application/gzip" \
-H "Authorization: token ${GITHUB_ACCESS_TOKEN}" \
--data-binary "@$$asset" \
"https://uploads.github.com/repos/$(GITHUB_ORG)/$(NAME)/releases/$(RELEASE)/assets?name=$${asset}" ; \
done )
@( cd release; for asset in `ls -A *tgz installer*`; do \
sha256sum $$asset > $$asset.sha256; \
done )
@( cd release; for asset in `ls -A *sha256`; do \
echo $$asset; \
curl -o /dev/null -X POST \
-H "Content-Type: text/plain" \
-H "Authorization: token ${GITHUB_ACCESS_TOKEN}" \
--data-binary "@$$asset" \
"https://uploads.github.com/repos/$(GITHUB_ORG)/$(NAME)/releases/$(RELEASE)/assets?name=$${asset}" ; \
done )
.PHONY: version
version:
@echo $(VERSION)
.PHONY: clean
clean:
rm -rf release
rm -rf build