-
Notifications
You must be signed in to change notification settings - Fork 6
/
Makefile
153 lines (132 loc) · 4.35 KB
/
Makefile
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
141
142
143
144
145
146
147
148
149
150
151
152
153
# override these values at runtime as desired
# eg. make build ARCH=arm32v6 BUILD_OPTIONS=--no-cache
ARCH := amd64
DOCKER_REPO := commonshost/dohnut
BUILD_OPTIONS +=
# ARCH to GOARCH mapping (don't change these)
# supported ARCH values: https://github.com/docker-library/official-images#architectures-other-than-amd64
# supported GOARCH values: https://golang.org/doc/install/source#environment
ifeq "${ARCH}" "amd64"
GOARCH := amd64
GOARM :=
endif
ifeq "${ARCH}" "arm32v6"
GOARCH := arm
GOARM := 6
endif
ifeq "${ARCH}" "arm64v8"
GOARCH := arm64
GOARM :=
endif
# these values are used for container labels at build time
BUILD_DATE := $(strip $(shell docker run --rm busybox date -u +'%Y-%m-%dT%H:%M:%SZ'))
BUILD_VERSION := $(strip $(shell git describe --tags --always --dirty))
VCS_REF := $(strip $(shell git rev-parse --short HEAD))
VCS_TAG := $(strip $(shell git describe --abbrev=0 --tags))
DOCKER_TAG := ${VCS_TAG}-${GOARCH}
.DEFAULT_GOAL := build
.EXPORT_ALL_VARIABLES:
## -- General --
## Display this help message
.PHONY: help
help:
@awk '{ \
if ($$0 ~ /^.PHONY: [a-zA-Z\-\_0-9]+$$/) { \
helpCommand = substr($$0, index($$0, ":") + 2); \
if (helpMessage) { \
printf "\033[36m%-20s\033[0m %s\n", \
helpCommand, helpMessage; \
helpMessage = ""; \
} \
} else if ($$0 ~ /^[a-zA-Z\-\_0-9.]+:/) { \
helpCommand = substr($$0, 0, index($$0, ":")); \
if (helpMessage) { \
printf "\033[36m%-20s\033[0m %s\n", \
helpCommand, helpMessage; \
helpMessage = ""; \
} \
} else if ($$0 ~ /^##/) { \
if (helpMessage) { \
helpMessage = helpMessage"\n "substr($$0, 3); \
} else { \
helpMessage = substr($$0, 3); \
} \
} else { \
if (helpMessage) { \
print "\n "helpMessage"\n" \
} \
helpMessage = ""; \
} \
}' \
$(MAKEFILE_LIST)
.PHONY: qemu-user-static
qemu-user-static:
@docker run --rm --privileged multiarch/qemu-user-static:register --reset
qemu-arm-static:
wget -q https://github.com/multiarch/qemu-user-static/releases/download/v4.0.0/qemu-arm-static \
&& chmod +x qemu-arm-static
qemu-aarch64-static:
wget -q https://github.com/multiarch/qemu-user-static/releases/download/v4.0.0/qemu-aarch64-static \
&& chmod +x qemu-aarch64-static
## -- Parameters --
## Select a target architecture (optional): amd64|arm32v6|arm64v8
## eg. make ARCH=arm32v6
##
.PHONY: ARCH
## Provide additional docker build flags (optional)
## eg. make BUILD_OPTIONS=--no-cache
##
.PHONY: BUILD_OPTIONS
## Override default docker repo (optional)
## eg. make DOCKER_REPO=myrepo/myapp
.PHONY: DOCKER_REPO
## -- Docker --
## Build, test, and push the image in one step
## eg. make release [ARCH=] [BUILD_OPTIONS=] [DOCKER_REPO=]
##
.PHONY: release
release: build test push
## Build an image for the selected platform
## eg. make build [ARCH=] [BUILD_OPTIONS=] [DOCKER_REPO=]
##
.PHONY: build
build: qemu-user-static
@docker build ${BUILD_OPTIONS} \
--build-arg ARCH \
--build-arg BUILD_VERSION \
--build-arg BUILD_DATE \
--build-arg VCS_REF \
--tag ${DOCKER_REPO}:${DOCKER_TAG} .
## Test an image by running it locally and requesting DNS lookups
## eg. make test [ARCH=] [DOCKER_REPO=]
##
.PHONY: test
test: qemu-user-static qemu-arm-static qemu-aarch64-static
$(eval CONTAINER_ID=$(shell docker run --rm -d \
-v "$(CURDIR)/qemu-arm-static:/usr/bin/qemu-arm-static" \
-v "$(CURDIR)/qemu-aarch64-static:/usr/bin/qemu-aarch64-static" \
-p 53:53/tcp -p 53:53/udp ${DOCKER_REPO}:${DOCKER_TAG} --listen 0.0.0.0:53 --doh commonshost))
dig sigok.verteiltesysteme.net @127.0.0.1 | grep NOERROR || (docker stop ${CONTAINER_ID}; exit 1)
dig sigfail.verteiltesysteme.net @127.0.0.1 | grep SERVFAIL || (docker stop ${CONTAINER_ID}; exit 1)
@docker stop ${CONTAINER_ID}
## Push an image to the configured docker repo
## eg. make push [ARCH=] [DOCKER_REPO=]
##
.PHONY: push
push:
@docker push ${DOCKER_REPO}:${DOCKER_TAG}
## Create and push a multi-arch manifest list
## eg. make manifest [DOCKER_REPO=]
##
.PHONY: manifest
manifest:
@manifest-tool push from-args \
--platforms linux/amd64,linux/arm,linux/arm64 \
--template ${DOCKER_REPO}:${VCS_TAG}-ARCH \
--target ${DOCKER_REPO}:${VCS_TAG} \
--ignore-missing
@manifest-tool push from-args \
--platforms linux/amd64,linux/arm,linux/arm64 \
--template ${DOCKER_REPO}:${VCS_TAG}-ARCH \
--target ${DOCKER_REPO}:latest \
--ignore-missing