-
Notifications
You must be signed in to change notification settings - Fork 182
Expand file tree
/
Copy pathMakefile
More file actions
194 lines (169 loc) · 7.5 KB
/
Makefile
File metadata and controls
194 lines (169 loc) · 7.5 KB
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
# Copyright 2018 The Kubernetes Authors.
#
# 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.
CONTAINER_ENGINE ?= docker
STAGING_IMAGE_REGISTRY := us-central1-docker.pkg.dev/k8s-staging-images
IMAGE_REGISTRY ?= ${STAGING_IMAGE_REGISTRY}/contributor-site
IMAGE_NAME := k8s-contrib-site-hugo
IMAGE_REPO := $(IMAGE_REGISTRY)/$(IMAGE_NAME)
IMAGE_VERSION := $(shell scripts/hash-files.sh Dockerfile Makefile netlify.toml .dockerignore cloudbuild.yaml package.json package-lock.json | cut -c 1-12)
COMMIT := $(shell git rev-parse --short HEAD)
CONTAINER_RUN := $(CONTAINER_ENGINE) run --rm -it -v "$(CURDIR):/src"
CONTAINER_RUN_TTY := $(CONTAINER_ENGINE) run --rm -it
HUGO_VERSION := $(shell grep ^HUGO_VERSION netlify.toml | tail -n 1 | cut -d '=' -f 2 | tr -d " \"\n")
GIT_TAG ?= v$(HUGO_VERSION)-$(IMAGE_VERSION)
CONTAINER_IMAGE := $(IMAGE_REPO):$(GIT_TAG)
# Docker buildx related settings for multi-arch images
DOCKER_BUILDX ?= docker buildx
CONTAINER_HUGO_MOUNTS = \
--read-only \
--mount type=bind,source=$(CURDIR)/.git,target=/src/.git,readonly \
--mount type=bind,source=$(CURDIR)/assets,target=/src/assets,readonly \
--mount type=bind,source=$(CURDIR)/content,target=/src/content,readonly \
--mount type=bind,source=$(CURDIR)/external-sources,target=/src/external-sources,readonly \
--mount type=bind,source=$(CURDIR)/hack,target=/src/hack,readonly \
--mount type=bind,source=$(CURDIR)/layouts,target=/src/layouts,readonly \
--mount type=bind,source=$(CURDIR)/static,target=/src/static,readonly \
--mount type=tmpfs,destination=/tmp,tmpfs-mode=01777 \
--mount type=bind,source=$(CURDIR)/hugo.yaml,target=/src/hugo.yaml,readonly
# Fast NONBLOCKING IO to stdout caused by the hack/gen-content.sh script can
# cause Netlify builds to terminate unexpectedly. This forces stdout to block.
BLOCK_STDOUT_CMD := python -c "import os,sys,fcntl; \
flags = fcntl.fcntl(sys.stdout, fcntl.F_GETFL); \
fcntl.fcntl(sys.stdout, fcntl.F_SETFL, flags&~os.O_NONBLOCK);"
.DEFAULT_GOAL := help
.PHONY: targets container-targets
targets: help gen-content render server clean clean-all production-build preview-build
container-targets: container-image container-push container-gen-content container-render container-server
help: ## Show this help text.
@grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-20s\033[0m %s\n", $$1, $$2}'
dependencies:
npm ci
gen-content: ## Generates content from external sources.
hack/gen-content.sh
render: dependencies ## Build the site using Hugo on the host.
hugo --logLevel info --ignoreCache --minify
server: dependencies ## Run Hugo locally (if Hugo "extended" is installed locally)
hugo server \
--logLevel info \
--buildDrafts \
--buildFuture \
--disableFastRender \
--ignoreCache
docker-image:
@echo -e "**** The use of docker-image is deprecated. Use container-image instead. ****" 1>&2
$(MAKE) container-image
container-image: ## Build container image for use with container-* targets.
$(CONTAINER_ENGINE) build . -t $(CONTAINER_IMAGE) --label git_commit=$(COMMIT) --build-arg HUGO_VERSION=$(HUGO_VERSION)
container-push: container-image ## Push container image for the preview of the website
$(CONTAINER_ENGINE) push $(CONTAINER_IMAGE)
PLATFORMS ?= linux/arm64,linux/amd64
docker-push: ## Build a multi-architecture image and push that into the registry
docker run --rm --privileged tonistiigi/binfmt:qemu-v8.1.5-43@sha256:46c5a036f13b8ad845d6703d38f8cce6dd7c0a1e4d42ac80792279cabaeff7fb --install all
docker version
$(DOCKER_BUILDX) version
$(DOCKER_BUILDX) inspect image-builder > /dev/null 2>&1 || $(DOCKER_BUILDX) create --name image-builder --use
# copy existing Dockerfile and insert --platform=${TARGETPLATFORM} into Dockerfile.cross, and preserve the original Dockerfile
sed -e 's/\(^FROM\)/FROM --platform=\$$\{TARGETPLATFORM\}/' Dockerfile > Dockerfile.cross
$(DOCKER_BUILDX) build \
--push \
--platform=$(PLATFORMS) \
--build-arg HUGO_VERSION=$(HUGO_VERSION) \
--tag $(CONTAINER_IMAGE) \
-f Dockerfile.cross .
$(DOCKER_BUILDX) stop image-builder
rm Dockerfile.cross
docker-gen-content:
@echo -e "**** The use of docker-gen-content is deprecated. Use container-gen-content instead. ****" 1>&2
$(MAKE) container-gen-content
container-gen-content: ## Generates content from external sources within a container (equiv to gen-content).
$(CONTAINER_RUN) $(CONTAINER_IMAGE) hack/gen-content.sh
docker-render:
@echo -e "**** The use of docker-render is deprecated. Use container-render instead. ****" 1>&2
$(MAKE) container-render
container-render: ## Build the site using Hugo within a container (equiv to render).
$(CONTAINER_RUN_TTY) $(CONTAINER_HUGO_MOUNTS) $(CONTAINER_IMAGE) hugo --logLevel info --ignoreCache --minify
docker-server:
@echo -e "**** The use of docker-server is deprecated. Use container-server instead. ****" 1>&2
$(MAKE) container-server
container-server: ## Run Hugo locally within a container, available at http://localhost:1313/
# no build lock to allow for read-only mounts
$(CONTAINER_RUN_TTY) -p 1313:1313 \
$(CONTAINER_HUGO_MOUNTS) \
--cap-drop=ALL \
--cap-drop=AUDIT_WRITE \
$(CONTAINER_IMAGE) \
bash -c 'cd /src && hack/gen-content.sh --in-container && \
cd /tmp/src && \
hugo server \
--environment preview \
--logLevel info \
--noBuildLock \
--bind 0.0.0.0 \
--buildDrafts \
--buildFuture \
--disableFastRender \
--ignoreCache \
--destination /tmp/hugo \
--cleanDestinationDir'
clean: ## Cleans build artifacts.
rm -rf public/ resources/ _tmp/
clean-all: ## Cleans both build artifacts and files synced to content directory
rm -rf public/ resources/ _tmp/
rm -f content/en/events/community-meeting.md
rm -f content/en/events/meet-our-contributors.md
rm -f content/en/events/office-hours.md
rm -f content/en/docs/cheatsheet.md
rm -f content/en/resources/rename.md
find content/en/docs/guide -maxdepth 1 \
-not -path content/en/docs/guide \
-not -name ".gitignore" \
-exec rm -rf {} \;
find content/en/docs/comms -maxdepth 1 \
-not -path content/en/docs/comms \
-not -name ".gitignore" \
-not -name "_index.md" \
-exec rm -rf {} \;
find content/en/resources/release -maxdepth 1 \
-not -path content/en/resources/release \
-not -name ".gitignore" \
-exec rm -rf {} \;
find content/en/docs/orientation -maxdepth 1 \
-not -path content/en/docs/orientation \
-not -name ".gitignore" \
-exec rm -rf {} \;
find content/en/community -maxdepth 1 \
-not -path content/en/community \
-not -name ".gitignore" \
-not -name "_index.md" \
-not -name "code-of-conduct.md" \
-exec rm -rf {} \;
production-build: ## Builds the production site (this command used only by Netlify).
$(BLOCK_STDOUT_CMD)
hack/gen-content.sh
hugo \
--environment production \
--logLevel info \
--ignoreCache \
--minify
preview-build: ## Builds a deploy preview of the site (this command used only by Netlify).
$(BLOCK_STDOUT_CMD)
hack/gen-content.sh
hugo \
--environment preview \
--logLevel info \
--baseURL $(DEPLOY_PRIME_URL) \
--buildDrafts \
--buildFuture \
--ignoreCache \
--minify