forked from kubernetes/dns
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
176 lines (146 loc) · 5.02 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
# 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 ?= gcr.io/google-containers
ARCH ?= amd64
DNSMASQ_VERSION ?= dnsmasq-2.76
CONTAINER_PREFIX ?= k8s-dns
ALL_ARCH := amd64 arm arm64 ppc64le s390x
IMAGE := $(CONTAINER_PREFIX)-dnsmasq-$(ARCH)
COMPILE_IMAGE := gcr.io/google-containers/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
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
BINARY:= $(OUTPUT_DIR)/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) dnsmasq.conf
@echo "building :" $(BINARY)
@mkdir -p $(@D)
@cp Dockerfile.cross $(OUTPUT_DIR)/Dockerfile
@cd $(OUTPUT_DIR) && sed -i- "s|__BASEIMAGE__|$(BASEIMAGE)|g" Dockerfile && rm Dockerfile-
ifeq ($(ARCH),amd64)
@cd $(OUTPUT_DIR) && 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 \
&& tar -xJf /build/dnsmasq.tar.xz \
&& cd $(DNSMASQ_VERSION) \
&& make -j \
&& cp src/dnsmasq /build" $(VERBOSE_OUTPUT)
else
@cd $(OUTPUT_DIR) \
&& sed -i- "s|__ARCH__|$(QEMUARCH)|g" Dockerfile && rm Dockerfile- \
&& sed -i- "s/__CROSS_BUILD_COPY__/COPY/g" Dockerfile && rm Dockerfile-
@cd $(OUTPUT_DIR) \
&& 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 \
"tar -xJf /build/dnsmasq.tar.xz \
&& cd $(DNSMASQ_VERSION) \
&& CC=$(TRIPLE)-gcc make -j \
&& cp src/dnsmasq /build" $(VERBOSE_OUTPUT)
endif
@cp dnsmasq.conf $(OUTPUT_DIR)
$(DNSMASQ_ARCHIVE):
@mkdir -p $(@D)
@curl -sSL $(DNSMASQ_URL) > $@
.PHONY: containers
containers: $(CONTAINER_STAMP)
$(CONTAINER_STAMP): $(BINARY)
@echo "container:" $(REGISTRY)/$(IMAGE):$(VERSION)
@docker build --pull \
-q -t $(REGISTRY)/$(IMAGE):$(VERSION) $(OUTPUT_DIR) > $@
.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)