forked from kubernetes/dns
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
192 lines (162 loc) · 5.79 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
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
# Copyright 2016 The Kubernetes Authors All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
VERSION ?= $(shell git describe --tags --always --dirty)
REGISTRY ?= staging-k8s.gcr.io
ARCH ?= amd64
DNSMASQ_VERSION ?= dnsmasq-2.78
CONTAINER_PREFIX ?= k8s-dns
ALL_ARCH := amd64 arm arm64 ppc64le s390x
IMAGE := $(CONTAINER_PREFIX)-dnsmasq-$(ARCH)
COMPILE_IMAGE := k8s.gcr.io/kube-cross:v1.7.6-k8s1.6-0
OUTPUT_DIR := _output/$(ARCH)
ifeq ($(ARCH),amd64)
BASEIMAGE ?= alpine:3.6
COMPILE_IMAGE := alpine:3.6
else ifeq ($(ARCH),arm)
BASEIMAGE ?= armhf/busybox:glibc
TRIPLE ?= arm-linux-gnueabihf
QEMUARCH := arm
else ifeq ($(ARCH),arm64)
BASEIMAGE ?= aarch64/busybox:glibc
TRIPLE ?= aarch64-linux-gnu
QEMUARCH := aarch64
else ifeq ($(ARCH),ppc64le)
BASEIMAGE ?= ppc64le/busybox:glibc
TRIPLE ?= powerpc64le-linux-gnu
QEMUARCH := ppc64le
else ifeq ($(ARCH),s390x)
BASEIMAGE ?=s390x/busybox:glibc
TRIPLE ?=s390x-linux-gnu
QEMUARCH :=s390x
else
$(error Unsupported ARCH: $(ARCH))
endif
DNSMASQ_URL := http://www.thekelleys.org.uk/dnsmasq/$(DNSMASQ_VERSION).tar.xz
# SHA-256 computed from GPG-verified download:
# $ gpg --recv 15CDDA6AE19135A2
# ...
# $ gpg --verify dnsmasq-2.78.tar.xz.asc dnsmasq-2.78.tar.xz
# gpg: Signature made Mon 02 Oct 2017 06:40:03 AM PDT
# gpg: using RSA key 15CDDA6AE19135A2
# gpg: Good signature from "Simon Kelley <[email protected]>" [unknown]
# gpg: aka "Simon Kelley <[email protected]>" [unknown]
# ...
# $ sha256sum dnsmasq-2.78.tar.xz
DNSMASQ_SHA256 := 89949f438c74b0c7543f06689c319484bd126cc4b1f8c745c742ab397681252b
DNSMASQ_ARCHIVE := $(OUTPUT_DIR)/dnsmasq.tar.xz
MULTIARCH_CONTAINER := multiarch/qemu-user-static:register
MULTIARCH_RELEASE := https://github.com/multiarch/qemu-user-static/releases/download/v2.5.0/x86_64_qemu-$(QEMUARCH)-static.tar.xz
DOCKER := docker
ifeq ($(findstring gcr.io/,$(REGISTRY)),gcr.io/)
DOCKER := gcloud docker --
endif
PATCHES := $(shell find patches/ -name *.patch)
BINARY := $(OUTPUT_DIR)/docker/dnsmasq
BUILDSTAMP := $(subst :,_,$(subst /,_,$(REGISTRY))_$(IMAGE)_$(VERSION))
CONTAINER_STAMP := .$(BUILDSTAMP)-container
PUSH_STAMP := .$(BUILDSTAMP)-push
ifeq ($(VERBOSE), 1)
VERBOSE_OUTPUT := >&1
else
VERBOSE_OUTPUT := >/dev/null 2>/dev/null
endif
all: build
build-%:
@$(MAKE) --no-print-directory ARCH=$* build
containers-%:
@$(MAKE) --no-print-directory ARCH=$* containers
test-%:
@$(MAKE) --no-print-directory ARCH=$* test
push-%:
@$(MAKE) --no-print-directory ARCH=$* push
.PHONY: all-build
all-build: $(addprefix build-, $(ALL_ARCH))
.PHONY: all-containers
all-containers: $(addprefix containers-, $(ALL_ARCH))
.PHONY: all-test
all-test: $(addprefix test-, $(ALL_ARCH))
.PHONY: all-push
all-push: $(addprefix push-, $(ALL_ARCH))
.PHONY: build
build: $(BINARY)
$(BINARY): Dockerfile.cross $(DNSMASQ_ARCHIVE) $(PATCHES) dnsmasq.conf
@echo "building :" $(BINARY)
@mkdir -p $(@D)
@mkdir -p $(@D)/docker
@cp Dockerfile.cross $(OUTPUT_DIR)/docker/Dockerfile
@cd $(OUTPUT_DIR)/docker && sed -i- "s|__BASEIMAGE__|$(BASEIMAGE)|g" Dockerfile && rm Dockerfile-
@cd $(OUTPUT_DIR) && tar -xJf dnsmasq.tar.xz
@for patch in $(PATCHES); do patch -p0 -d $(OUTPUT_DIR)/$(DNSMASQ_VERSION) < $${patch}; done
@cp dnsmasq.conf $(OUTPUT_DIR)/docker
ifeq ($(ARCH),amd64)
@cd $(OUTPUT_DIR)/docker && \
sed -i- "/__CROSS_BUILD_COPY__/d" Dockerfile && rm Dockerfile-
@docker pull $(COMPILE_IMAGE)
@docker run --rm --sig-proxy=true \
-v `pwd`/$(OUTPUT_DIR):/build \
-v `pwd`:/src \
$(COMPILE_IMAGE) \
/bin/sh -c \
"apk update \
&& apk add alpine-sdk xz libcap-dev \
&& cd /build/$(DNSMASQ_VERSION) \
&& make -j \
&& cp src/dnsmasq /build/docker/dnsmasq" $(VERBOSE_OUTPUT)
else
@cd $(OUTPUT_DIR)/docker \
&& sed -i- "s|__ARCH__|$(QEMUARCH)|g" Dockerfile && rm Dockerfile- \
&& sed -i- "s/__CROSS_BUILD_COPY__/COPY/g" Dockerfile && rm Dockerfile-
@cd $(OUTPUT_DIR)/docker \
&& curl -sSL $(MULTIARCH_RELEASE) | tar -xJ
@docker run --sig-proxy=true --rm \
--privileged $(MULTIARCH_CONTAINER) \
--reset $(VERBOSE_OUTPUT)
@docker pull $(COMPILE_IMAGE)
@docker run --rm --sig-proxy=true \
-v `pwd`/$(OUTPUT_DIR):/build \
-v `pwd`:/src \
$(COMPILE_IMAGE) \
/bin/bash -c \
"cd /build/$(DNSMASQ_VERSION) \
&& CC=$(TRIPLE)-gcc make -j \
&& cp src/dnsmasq /build/docker/dnsmasq" $(VERBOSE_OUTPUT)
endif
$(DNSMASQ_ARCHIVE):
@mkdir -p $(@D)
@curl -sSL $(DNSMASQ_URL) > $@
@echo "$(DNSMASQ_SHA256) $(DNSMASQ_ARCHIVE)" > $(@D)/sha256.txt
@sha256sum -c $(@D)/sha256.txt
.PHONY: containers
containers: $(CONTAINER_STAMP)
$(CONTAINER_STAMP): $(BINARY)
@echo "container:" $(REGISTRY)/$(IMAGE):$(VERSION)
@docker build --pull \
-q -t $(REGISTRY)/$(IMAGE):$(VERSION) $(OUTPUT_DIR)/docker > $@
.PHONY: test
test: containers
@ARCH=$(ARCH) IMAGE=$(REGISTRY)/$(IMAGE):$(VERSION) ./validate.sh
.PHONY: push
push: $(PUSH_STAMP)
$(PUSH_STAMP): $(CONTAINER_STAMP)
@echo "pushing :" $(REGISTRY)/$(IMAGE):$(VERSION)
@$(DOCKER) push $(REGISTRY)/$(IMAGE):$(VERSION)
@cat $< > $@
.PHONY: clean
clean:
rm -f .*-container
rm -f .*-push
rm -rf _output/
.PHONY: version
version:
@echo $(VERSION)