forked from projectcalico/calico
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
263 lines (214 loc) · 11.5 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
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
##############################################################################
# The build architecture is select by setting the ARCH variable.
# # For example: When building on ppc64le you could use ARCH=ppc64le make <....>.
# # When ARCH is undefined it defaults to amd64.
ARCH?=amd64
ifeq ($(ARCH),amd64)
ARCHTAG?=
GO_BUILD_VER?=v0.12
endif
ifeq ($(ARCH),ppc64le)
ARCHTAG:=-ppc64le
GO_BUILD_VER?=latest
endif
ifeq ($(ARCH),s390x)
ARCHTAG:=-s390x
GO_BUILD_VER?=latest
endif
##############################################################################
CALICO_BUILD?=calico/go-build$(ARCHTAG):$(GO_BUILD_VER)
CALICO_DIR=$(shell git rev-parse --show-toplevel)
VERSIONS_FILE?=$(CALICO_DIR)/_data/versions.yml
JEKYLL_VERSION=pages
DEV?=false
CONFIG=--config _config.yml
ifeq ($(DEV),true)
CONFIG:=$(CONFIG),_config_dev.yml
endif
# Determine whether there's a local yaml installed or use dockerized version.
# Note in order to install local (faster) yaml: "go get github.com/mikefarah/yaml"
YAML_CMD:=$(shell which yaml || echo docker run --rm -i $(CALICO_BUILD) yaml)
##############################################################################
# Version information used for cutting a release.
RELEASE_STREAM?=
# Use := so that these V_ variables are computed only once per make run.
CALICO_VER := $(shell cat $(VERSIONS_FILE) | $(YAML_CMD) read - '"$(RELEASE_STREAM)".[0].title')
NODE_VER := $(shell cat $(VERSIONS_FILE) | $(YAML_CMD) read - '"$(RELEASE_STREAM)".[0].title')
CTL_VER := $(shell cat $(VERSIONS_FILE) | $(YAML_CMD) read - '"$(RELEASE_STREAM)".[0].components.calicoctl.version')
CNI_VER := $(shell cat $(VERSIONS_FILE) | $(YAML_CMD) read - '"$(RELEASE_STREAM)".[0].components.calico/cni.version')
KUBE_CONTROLLERS_VER := $(shell cat $(VERSIONS_FILE) | $(YAML_CMD) read - '"$(RELEASE_STREAM)".[0].components.calico/kube-controllers.version')
TYPHA_VER := $(shell cat $(VERSIONS_FILE) | $(YAML_CMD) read - '"$(RELEASE_STREAM)".[0].components.typha.version')
$(info $(shell printf "%-21s = %-10s\n" "NODE_VER" $(NODE_VER)))
$(info $(shell printf "%-21s = %-10s\n" "CNI_VER" $(CNI_VER)))
$(info $(shell printf "%-21s = %-10s\n" "CTL_VER" $(CTL_VER)))
$(info $(shell printf "%-21s = %-10s\n" "KUBE_CONTROLLERS_VER" $(KUBE_CONTROLLERS_VER)))
$(info $(shell printf "%-21s = %-10s\n" "TYPHA_VER" $(TYPHA_VER)))
##############################################################################
serve:
docker run --rm -ti -e JEKYLL_UID=`id -u` -p 4000:4000 -v $$PWD:/srv/jekyll jekyll/jekyll:$(JEKYLL_VERSION) jekyll serve --incremental $(CONFIG)
.PHONY: build
_site build:
docker run --rm -ti -e JEKYLL_UID=`id -u` -v $$PWD:/srv/jekyll jekyll/jekyll:$(JEKYLL_VERSION) jekyll build --incremental $(CONFIG)
## Clean enough that a new release build will be clean
clean:
# Clean jekyll
docker run --rm -ti -e JEKYLL_UID=`id -u` -v $$PWD:/srv/jekyll jekyll/jekyll:$(JEKYLL_VERSION) jekyll clean
# Remove any release directories
rm -rf _output
###############################################################################
# CI / test targets
###############################################################################
ci: htmlproofer kubeval
htmlproofer: clean _site
# Run htmlproofer, failing if we hit any errors.
./htmlproofer.sh
kubeval:
# Run kubeval to check master manifests are valid Kubernetes resources.
docker run -v $$PWD:/calico --entrypoint /bin/sh -ti garethr/kubeval:0.1.1 -c 'ok=true; for f in `find /calico/_site/master -name "*.yaml" |grep -v "\(config\|allow-istio-pilot\|30-policy\).yaml"`; do echo Running kubeval on $$f; /kubeval $$f || ok=false; done; $$ok'
htmlproofer-all:
# Run htmlproofer across _all_ files. This is not part of CI.
echo "Running a soft check across all files"
docker run -ti -e JEKYLL_UID=`id -u` --rm -v $(pwd)/_site:/_site/ quay.io/calico/htmlproofer:${HP_VERSION} /_site --assume-extension --check-html --empty-alt-ignore --url-ignore "#"
###############################################################################
# Docs automation
###############################################################################
strip_redirects:
find \( -name '*.md' -o -name '*.html' \) -exec sed -i'' '/redirect_from:/d' '{}' \;
add_redirects_for_latest: strip_redirects
ifndef VERSION
$(error VERSION is undefined - run using make add_redirects_for_latest VERSION=vX.Y)
endif
# Check that the VERSION directory already exists
@test -d $(VERSION)
# Add the redirect line - look at .md files only and add "redirect_from: XYZ" on a new line after each "title:"
find $(VERSION) \( -name '*.md' -o -name '*.html' \) -exec sed -i 's#^title:.*#&\nredirect_from: {}#' '{}' \;
# Check the redirect_from lines and update the version to be "latest"
find $(VERSION) \( -name '*.md' -o -name '*.html' \) -exec sed -i 's#^\(redirect_from: \)$(VERSION)#\1latest#' '{}' \;
# Check the redirect_from lines and strip the .md from the URL
find $(VERSION) \( -name '*.md' -o -name '*.html' \) -exec sed -i 's#^\(redirect_from:.*\)\.md#\1#' '{}' \;
update_canonical_urls:
# You must pass two version numbers into this command, e.g., make update_canonical_urls OLD=v3.0 NEW=v3.1
# Looks through all directories and replaces previous latest release version numbers in canonical URLs with new
find . \( -name '*.md' -o -name '*.html' \) -exec sed -i '/canonical_url:/s/$(OLD)/$(NEW)/g' {} \;
###############################################################################
# Release targets
###############################################################################
## Tags and builds a release from start to finish.
release: release-prereqs
$(MAKE) release-tag
$(MAKE) release-build
$(MAKE) release-verify
@echo ""
@echo "Release build complete. Next, push the release."
@echo ""
@echo " make RELEASE_STREAM=$(RELEASE_STREAM) release-publish"
@echo ""
## Produces a git tag for the release.
release-tag: release-prereqs
git tag $(CALICO_VER)
## Produces a clean build of release artifacts at the specified version.
release-build: release-prereqs clean
# Create the release archive.
$(MAKE) release-archive
## Verifies the release artifacts produces by `make release-build` are correct.
release-verify: release-prereqs
@echo "TODO: Implement release tar verification"
## Pushes a github release and release artifacts produced by `make release-build`.
release-publish: release-prereqs
# Push the git tag.
git push origin $(CALICO_VER)
@echo "Finalize the GitHub release based on the pushed tag and attach release-$(CALICO_VER).tgz"
@echo ""
@echo " https://github.com/projectcalico/calico/releases/tag/$(CALICO_VER)"
@echo ""
## Generates release notes for the given version.
release-notes: release-prereqs
VERSION=$(CALICO_VER) GITHUB_TOKEN=$(GITHUB_TOKEN) python2 ./release-scripts/generate-release-notes.py
# release-prereqs checks that the environment is configured properly to create a release.
release-prereqs:
ifndef RELEASE_STREAM
$(error RELEASE_STREAM is undefined - run using make release RELEASE_STREAM=vX.Y)
endif
@if [ $(CALICO_VER) != $(NODE_VER) ]; then \
echo "Expected CALICO_VER $(CALICO_VER) to equal NODE_VER $(NODE_VER)"; \
exit 1; fi
RELEASE_DIR?=_output/release-$(CALICO_VER)
RELEASE_DIR_K8S_MANIFESTS?=$(RELEASE_DIR)/k8s-manifests
RELEASE_DIR_IMAGES?=$(RELEASE_DIR)/images
RELEASE_DIR_BIN?=$(RELEASE_DIR)/bin
MANIFEST_SRC ?= ./_site/$(RELEASE_STREAM)/getting-started/kubernetes/installation
## Create an archive that contains a complete "Calico" release
release-archive: release-prereqs $(RELEASE_DIR).tgz
$(RELEASE_DIR).tgz: $(RELEASE_DIR) $(RELEASE_DIR_K8S_MANIFESTS) $(RELEASE_DIR_IMAGES) $(RELEASE_DIR_BIN) $(RELEASE_DIR)/README
tar -czvf $(RELEASE_DIR).tgz $(RELEASE_DIR)/*
$(RELEASE_DIR_IMAGES): $(RELEASE_DIR_IMAGES)/calico-node.tar $(RELEASE_DIR_IMAGES)/calico-typha.tar $(RELEASE_DIR_IMAGES)/calico-cni.tar $(RELEASE_DIR_IMAGES)/calico-kube-controllers.tar
$(RELEASE_DIR_BIN): $(RELEASE_DIR_BIN)/calicoctl $(RELEASE_DIR_BIN)/calicoctl-windows-amd64.exe $(RELEASE_DIR_BIN)/calicoctl-darwin-amd64
$(RELEASE_DIR)/README:
@echo "This directory contains a complete release of Calico $(CALICO_VER)" >> $@
@echo "Documentation for this release can be found at http://docs.projectcalico.org/$(RELEASE_STREAM)" >> $@
@echo "" >> $@
@echo "Docker images (under 'images'). Load them with 'docker load'" >> $@
@echo "* The calico/node docker image (version $(NODE_VERS))" >> $@
@echo "* The calico/typha docker image (version $(TYPHA_VER))" >> $@
@echo "* The calico/cni docker image (version $(CNI_VERS))" >> $@
@echo "* The calico/kube-controllers docker image (version $(KUBE_CONTROLLERS_VER))" >> $@
@echo "" >> $@
@echo "Binaries (for amd64) (under 'bin')" >> $@
@echo "* The calicoctl binary (for Linux) (version $(CTL_VER))" >> $@
@echo "* The calicoctl-windows-amd64.exe binary (for Windows) (version $(CTL_VER))" >> $@
@echo "* The calicoctl-darwin-amd64 binary (for Mac) (version $(CTL_VER))" >> $@
@echo "" >> $@
@echo "Kubernetes manifests (under 'k8s-manifests directory')" >> $@
$(RELEASE_DIR):
mkdir -p $(RELEASE_DIR)
$(RELEASE_DIR_K8S_MANIFESTS):
# Ensure that the docs site is generated
rm -rf ../_site
$(MAKE) _site
# Find all the hosted manifests and copy them into the release dir. Use xargs to mkdir the destination directory structure before copying them.
# -printf "%P\n" prints the file name and directory structure with the search dir stripped off
find $(MANIFEST_SRC)/hosted -name '*.yaml' -printf "%P\n" | \
xargs -I FILE sh -c \
'mkdir -p $(RELEASE_DIR_K8S_MANIFESTS)/hosted/`dirname FILE`;\
cp $(MANIFEST_SRC)/hosted/FILE $(RELEASE_DIR_K8S_MANIFESTS)/hosted/`dirname FILE`;'
# Copy the non-hosted manifets too
cp $(MANIFEST_SRC)/*.yaml $(RELEASE_DIR_K8S_MANIFESTS)
$(RELEASE_DIR_IMAGES)/calico-node.tar:
mkdir -p $(RELEASE_DIR_IMAGES)
docker pull calico/node:$(NODE_VER)
docker save --output $@ calico/node:$(NODE_VER)
$(RELEASE_DIR_IMAGES)/calico-typha.tar:
mkdir -p $(RELEASE_DIR_IMAGES)
docker pull calico/typha:$(TYPHA_VER)
docker save --output $@ calico/typha:$(TYPHA_VER)
$(RELEASE_DIR_IMAGES)/calico-cni.tar:
mkdir -p $(RELEASE_DIR_IMAGES)
docker pull calico/cni:$(CNI_VER)
docker save --output $@ calico/cni:$(CNI_VER)
$(RELEASE_DIR_IMAGES)/calico-kube-controllers.tar:
mkdir -p $(RELEASE_DIR_IMAGES)
docker pull calico/kube-controllers:$(KUBE_CONTROLLERS_VER)
docker save --output $@ calico/kube-controllers:$(KUBE_CONTROLLERS_VER)
$(RELEASE_DIR_BIN)/%:
mkdir -p $(RELEASE_DIR_BIN)
wget https://github.com/projectcalico/calicoctl/releases/download/$(CTL_VER)/$(@F) -O $@
chmod +x $@
###############################################################################
# Utilities
###############################################################################
.PHONY: help
## Display this help text
help: # Some kind of magic from https://gist.github.com/rcmachado/af3db315e31383502660
$(info Available targets)
@awk '/^[a-zA-Z\-\_0-9\/]+:/ { \
nb = sub( /^## /, "", helpMsg ); \
if(nb == 0) { \
helpMsg = $$0; \
nb = sub( /^[^:]*:.* ## /, "", helpMsg ); \
} \
if (nb) \
printf "\033[1;31m%-" width "s\033[0m %s\n", $$1, helpMsg; \
} \
{ helpMsg = $$0 }' \
width=20 \
$(MAKEFILE_LIST)