-
Notifications
You must be signed in to change notification settings - Fork 86
/
Makefile.calico
168 lines (135 loc) · 5.29 KB
/
Makefile.calico
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
# BUILDARCH is the host architecture
# ARCH is the target architecture
# we need to keep track of them separately
BUILDARCH ?= $(shell uname -m)
BUILDOS ?= $(shell uname -s | tr A-Z a-z)
# canonicalized names for host architecture
ifeq ($(BUILDARCH),aarch64)
BUILDARCH=arm64
endif
ifeq ($(BUILDARCH),x86_64)
BUILDARCH=amd64
endif
ifeq ($(BUILDARCH),armv7l)
BUILDARCH=armv7
endif
# unless otherwise set, I am building for my own architecture, i.e. not cross-compiling
ARCH ?= $(BUILDARCH)
# canonicalized names for target architecture
ifeq ($(ARCH),aarch64)
override ARCH=arm64
endif
ifeq ($(ARCH),x86_64)
override ARCH=amd64
endif
ifeq ($(BUILDARCH),armv7l)
BUILDARCH=armv7
endif
ARCHES=$(patsubst docker-image/Dockerfile.%,%,$(wildcard docker-image/Dockerfile.*))
EXCLUDEARCH ?=
VALIDARCHES = $(filter-out $(EXCLUDEARCH),$(ARCHES))
BINARIES_FILES = bird birdcl bird6
BINARIES = $(addprefix dist/$(ARCH)/,$(BINARIES_FILES))
CONTAINER_BASENAME ?= bird
CONTAINER_NAME ?= calico/$(CONTAINER_BASENAME)
DIND_CONTAINER_BASENAME ?= bird-dind
DIND_CONTAINER_NAME ?= calico/$(DIND_CONTAINER_BASENAME)
# Version of this repository as reported by git.
CALICO_GIT_VER := $(shell git describe --tags --dirty --always)
# because we are not using the default Makefile
where-am-i = $(word $(words $(MAKEFILE_LIST)),$(MAKEFILE_LIST))
# so we can use names in targets
escapefs = $(subst :,---,$(subst /,___,$(1)))
unescapefs = $(subst ---,:,$(subst ___,/,$(1)))
# Variables for controlling image tagging and pushing.
DOCKER_REPOS=calico
ifeq ($(RELEASE),true)
# If this is a release, also tag and push GCR images.
DOCKER_REPOS+=gcr.io/projectcalico-org eu.gcr.io/projectcalico-org asia.gcr.io/projectcalico.org us.gcr.io/projectcalico.org
endif
.PHONY: do-build build build-all image image-all push push-all ci cd
MYMAKE = $(MAKE) -f $(call where-am-i)
build: $(BINARIES)
$(BINARIES):
$(MYMAKE) do-build ARCH=$(ARCH)
do-build:
ARCH=$(ARCH) ./build.sh
build-all:
ARCH=all ./build.sh
image: $(CONTAINER_NAME)
$(CONTAINER_NAME): $(BINARIES)
docker build -t $(CONTAINER_NAME):latest-$(ARCH) -f docker-image/Dockerfile.$(ARCH) dist/$(ARCH)
image-all: $(addprefix sub-image-,$(VALIDARCHES))
sub-image-%:
$(MYMAKE) image ARCH=$*
$(MYMAKE) dind-image ARCH=$*
.PHONY: dind-image
dind-image: $(DIND_CONTAINER_NAME)
$(DIND_CONTAINER_NAME): $(BINARIES)
docker build -t $@:latest-$(ARCH) -f dind-image/Dockerfile.$(ARCH) dist/$(ARCH)
## push one arch
push: imagetag $(addprefix sub-single-push-,$(call escapefs,$(DOCKER_REPOS)))
sub-single-push-%:
docker push $(call unescapefs,$*/$(CONTAINER_BASENAME):$(IMAGETAG)-$(ARCH))
docker push $(call unescapefs,$*/$(DIND_CONTAINER_BASENAME):$(IMAGETAG)-$(ARCH))
ifeq ($(ARCH),amd64)
docker push $(call unescapefs,$*/$(CONTAINER_BASENAME):$(IMAGETAG))
docker push $(call unescapefs,$*/$(DIND_CONTAINER_BASENAME):$(IMAGETAG))
endif
## push all supported arches
push-all: imagetag $(addprefix sub-push-,$(VALIDARCHES))
sub-push-%:
$(MYMAKE) push ARCH=$* IMAGETAG=$(IMAGETAG)
## tag images of one arch
tag-images: imagetag $(addprefix sub-single-tag-images-,$(call escapefs,$(DOCKER_REPOS)))
sub-single-tag-images-%:
docker tag $(CONTAINER_NAME):latest-$(ARCH) $(call unescapefs,$*/$(CONTAINER_BASENAME):$(IMAGETAG)-$(ARCH))
docker tag $(DIND_CONTAINER_NAME):latest-$(ARCH) $(call unescapefs,$*/$(DIND_CONTAINER_BASENAME):$(IMAGETAG)-$(ARCH))
ifeq ($(ARCH),amd64)
docker tag $(CONTAINER_NAME):latest-$(ARCH) $(call unescapefs,$*/$(CONTAINER_BASENAME):$(IMAGETAG))
docker tag $(DIND_CONTAINER_NAME):latest-$(ARCH) $(call unescapefs,$*/$(DIND_CONTAINER_BASENAME):$(IMAGETAG))
endif
## tag images of all archs
tag-images-all: imagetag $(addprefix sub-tag-images-,$(VALIDARCHES))
sub-tag-images-%:
$(MYMAKE) tag-images ARCH=$* IMAGETAG=$(IMAGETAG)
imagetag:
ifndef IMAGETAG
$(error IMAGETAG is undefined - run using make <target> IMAGETAG=X.Y.Z)
endif
###############################################################################
# CI/CD
###############################################################################
.PHONY: ci cd
## Run what CI runs
ci: image-all test-protocol-support
## Deploys images to registry
cd: image-all
ifndef CONFIRM
$(error CONFIRM is undefined - run using make <target> CONFIRM=true)
endif
ifndef BRANCH_NAME
$(error BRANCH_NAME is undefined - run using make <target> BRANCH_NAME=var or set an environment variable)
endif
$(MYMAKE) tag-images-all push-all IMAGETAG=${BRANCH_NAME} EXCLUDEARCH="$(EXCLUDEARCH)"
$(MYMAKE) tag-images-all push-all IMAGETAG=$(shell git describe --tags --dirty --always --long) EXCLUDEARCH="$(EXCLUDEARCH)"
# Test that the image we've just built supports the BIRD config that
# we expect it to.
TEST_CONFIG := docker run --rm \
-v `pwd`/docker-image/test-config:/test-config \
-w /test-config \
--entrypoint=/bird \
$(CONTAINER_NAME):latest-$(BUILDARCH) \
-p -c
test-protocol-support: image
# invalid.conf is not BIRD config at all, so we expect BIRD to
# find it invalid. So here we're testing that our testing is
# effective.
! $(TEST_CONFIG) invalid.conf
# bird.cfg (plus its includes bird_aggr.cfg and bird_ipam.cfg)
# is actual confd-generated config grabbed from a confd test
# run.
$(TEST_CONFIG) bird.cfg
# bfd.conf contains an empty "protocol bfd" block, so tests
# that our image supports BFD.
$(TEST_CONFIG) bfd.conf