-
Notifications
You must be signed in to change notification settings - Fork 40
/
Makefile
332 lines (265 loc) · 10.4 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
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
#!/usr/bin/make
#
# Copyright 2018 CSP Config Management 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.
######################################################################
##### CONFIG #####
REPO := kpt.dev/configsync
# List of dirs containing go code owned by Nomos
NOMOS_CODE_DIRS := pkg cmd e2e
NOMOS_GO_PKG := $(foreach dir,$(NOMOS_CODE_DIRS),./$(dir)/...)
# Directory containing all build artifacts. We need abspath here since
# mounting a directory as a docker volume requires an abspath. This should
# eventually be pushed down into where docker commands are run rather than
# requiring all our paths to be absolute.
OUTPUT_DIR := $(abspath .output)
# Self-contained GOPATH dir.
GO_DIR := $(OUTPUT_DIR)/go
# Directory containing installed go binaries.
BIN_DIR := $(GO_DIR)/bin
KUSTOMIZE_VERSION := v5.1.0
HELM_VERSION := v3.12.2
# Directory used for staging Docker contexts.
STAGING_DIR := $(OUTPUT_DIR)/staging
# Directory used for staging the manifest primitives.
NOMOS_MANIFEST_STAGING_DIR := $(STAGING_DIR)/operator
OSS_MANIFEST_STAGING_DIR := $(STAGING_DIR)/oss
# Directory that gets mounted into /tmp for build and test containers.
TEMP_OUTPUT_DIR := $(OUTPUT_DIR)/tmp
# Directory containing Deployment yamls with image paths spliced in
GEN_DEPLOYMENT_DIR := $(OUTPUT_DIR)/deployment
# Directory containing generated test yamls
TEST_GEN_YAML_DIR := $(OUTPUT_DIR)/test/yaml
# Use git tags to set version string.
ifeq ($(origin VERSION), undefined)
VERSION := $(shell git describe --tags --always --dirty --long)
endif
# UID of current user
UID := $(shell id -u)
# GID of current user
GID := $(shell id -g)
# GCP project that owns container registry for local dev build.
ifeq ($(origin GCP_PROJECT), undefined)
GCP_PROJECT := $(shell gcloud config get-value project)
endif
# Use BUILD_ID as a unique identifier for prow jobs, otherwise default to USER
BUILD_ID ?= $(USER)
GCR_PREFIX ?= $(GCP_PROJECT)/$(BUILD_ID)
GCS_PREFIX ?= gs://$(GCP_PROJECT)/config-sync
GCS_BUCKET ?= $(GCS_PREFIX)/$(shell git rev-parse HEAD)
LOCATION ?= us
# Allow arbitrary registry name, but default to GCR with prefix if not provided
REGISTRY ?= gcr.io/$(GCR_PREFIX)
# Registry used for retagging previously built images
OLD_REGISTRY ?= $(REGISTRY)
# Registry which hosts images related to test infrastructure
TEST_INFRA_PROJECT ?= kpt-config-sync-ci-artifacts
TEST_INFRA_REGISTRY ?= $(LOCATION)-docker.pkg.dev/$(TEST_INFRA_PROJECT)/test-infra
# Docker image used for build and test. This image does not support CGO.
BUILDENV_IMAGE ?= $(TEST_INFRA_REGISTRY)/buildenv:v0.2.12
# Nomos docker images containing all binaries.
RECONCILER_IMAGE := reconciler
RECONCILER_MANAGER_IMAGE := reconciler-manager
ADMISSION_WEBHOOK_IMAGE := admission-webhook
HYDRATION_CONTROLLER_IMAGE := hydration-controller
HYDRATION_CONTROLLER_WITH_SHELL_IMAGE := $(HYDRATION_CONTROLLER_IMAGE)-with-shell
OCI_SYNC_IMAGE := oci-sync
HELM_SYNC_IMAGE := helm-sync
NOMOS_IMAGE := nomos
# nomos binary for local run.
NOMOS_LOCAL := $(BIN_DIR)/linux_amd64/nomos
# Allows an interactive docker build or test session to be interrupted
# by Ctrl-C. This must be turned off in case of non-interactive runs,
# like in CI/CD.
DOCKER_INTERACTIVE := --interactive
HAVE_TTY := $(shell [ -t 0 ] && echo 1 || echo 0)
ifeq ($(HAVE_TTY), 1)
DOCKER_INTERACTIVE += --tty
endif
# Suppresses docker output on build.
#
# To turn off, for example:
# make DOCKER_BUILD_QUIET="" deploy
DOCKER_BUILD_QUIET ?= --quiet
# Suppresses gcloud output.
GCLOUD_QUIET := --quiet
# Developer focused docker image tag.
ifeq ($(origin IMAGE_TAG), undefined)
IMAGE_TAG := $(shell git describe --tags --always --dirty --long)
endif
# Tag used for retagging previously built images
OLD_IMAGE_TAG ?= $(IMAGE_TAG)
# Base image names as given on gcr.io
RECONCILER_GCR := $(REGISTRY)/$(RECONCILER_IMAGE)
RECONCILER_MANAGER_GCR := $(REGISTRY)/$(RECONCILER_MANAGER_IMAGE)
ADMISSION_WEBHOOK_GCR := $(REGISTRY)/$(ADMISSION_WEBHOOK_IMAGE)
HYDRATION_CONTROLLER_GCR := $(REGISTRY)/$(HYDRATION_CONTROLLER_IMAGE)
HYDRATION_CONTROLLER_WITH_SHELL_GCR := $(REGISTRY)/$(HYDRATION_CONTROLLER_WITH_SHELL_IMAGE)
OCI_SYNC_GCR := $(REGISTRY)/$(OCI_SYNC_IMAGE)
HELM_SYNC_GCR := $(REGISTRY)/$(HELM_SYNC_IMAGE)
NOMOS_GCR := $(REGISTRY)/$(NOMOS_IMAGE)
# Full image tags as given on gcr.io
RECONCILER_TAG := $(RECONCILER_GCR):$(IMAGE_TAG)
RECONCILER_MANAGER_TAG := $(RECONCILER_MANAGER_GCR):$(IMAGE_TAG)
ADMISSION_WEBHOOK_TAG := $(ADMISSION_WEBHOOK_GCR):$(IMAGE_TAG)
HYDRATION_CONTROLLER_TAG := $(HYDRATION_CONTROLLER_GCR):$(IMAGE_TAG)
HYDRATION_CONTROLLER_WITH_SHELL_TAG := $(HYDRATION_CONTROLLER_WITH_SHELL_GCR):$(IMAGE_TAG)
OCI_SYNC_TAG := $(OCI_SYNC_GCR):$(IMAGE_TAG)
HELM_SYNC_TAG := $(HELM_SYNC_GCR):$(IMAGE_TAG)
NOMOS_TAG := $(NOMOS_GCR):$(IMAGE_TAG)
DOCKER_RUN_ARGS = \
$(DOCKER_INTERACTIVE) \
-u $(UID):$(GID) \
-v $(GO_DIR):/go \
-v $$(pwd):/go/src/$(REPO) \
-v $(GO_DIR)/std/linux_amd64_static:/usr/local/go/pkg/linux_amd64_static \
-v $(GO_DIR)/std/linux_arm64_static:/usr/local/go/pkg/linux_arm64_static \
-v $(GO_DIR)/std/darwin_amd64_static:/usr/local/go/pkg/darwin_amd64_static \
-v $(GO_DIR)/std/darwin_arm64_static:/usr/local/go/pkg/darwin_arm64_static \
-v $(GO_DIR)/std/windows_amd64_static:/usr/local/go/pkg/windows_amd64_static \
-v $(TEMP_OUTPUT_DIR):/tmp \
-w /go/src/$(REPO) \
--rm \
$(BUILDENV_IMAGE) \
# Get the currently used golang install path (in GOPATH/bin, unless GOBIN is set)
ifeq (,$(shell go env GOBIN))
GOBIN=$(shell go env GOPATH)/bin
else
GOBIN=$(shell go env GOBIN)
endif
# Add binary directories to PATH (prioritize .output/go/bin -> $GOPATH/bin -> $PATH)
PATH := $(BIN_DIR):$(GOBIN):$(PATH)
##### SETUP #####
.DEFAULT_GOAL := all
.PHONY: $(OUTPUT_DIR)
$(OUTPUT_DIR):
@echo "+++ Creating the local build output directory: $(OUTPUT_DIR)"
@mkdir -p \
$(STAGING_DIR) \
$(TEMP_OUTPUT_DIR) \
$(TEST_GEN_YAML_DIR) \
$(NOMOS_MANIFEST_STAGING_DIR) \
$(OSS_MANIFEST_STAGING_DIR) \
$(GEN_DEPLOYMENT_DIR)
# These directories get mounted by DOCKER_RUN_ARGS, so we have to create them
# before invoking docker.
.PHONY: buildenv-dirs
buildenv-dirs:
@mkdir -p \
$(BIN_DIR) \
$(GO_DIR)/src/$(REPO) \
$(GO_DIR)/std/linux_amd64_static \
$(GO_DIR)/std/linux_arm64_static \
$(GO_DIR)/std/darwin_amd64_static \
$(GO_DIR)/std/darwin_arm64_static \
$(GO_DIR)/std/windows_amd64_static \
$(TEMP_OUTPUT_DIR)
##### TARGETS #####
include Makefile.build
-include Makefile.docs
include Makefile.e2e
-include Makefile.prow
include Makefile.gen
include Makefile.oss
include Makefile.oss.prow
include Makefile.reconcilermanager
-include Makefile.release
.PHONY: all
all: test deps configsync-crds
# Cleans all artifacts.
.PHONY: clean
clean:
@echo "+++ Cleaning $(OUTPUT_DIR)"
@rm -rf $(OUTPUT_DIR)
.PHONY: build-status
build-status:
@./scripts/build-status.sh
.PHONY: test-unit
test-unit: pull-buildenv buildenv-dirs "$(BIN_DIR)/kustomize"
@echo "+++ Running unit tests in a docker container"
@docker run $(DOCKER_RUN_ARGS) ./scripts/test-unit.sh $(NOMOS_GO_PKG)
# Runs unit tests and linter.
.PHONY: test
test: test-unit lint
# The presubmits have made side-effects in the past, which makes their
# validation suspect (as the repository they are validating is different
# than what is checked in). Run `test` but verify that repository is clean.
.PHONY: test-presubmit
test-presubmit: all
@./scripts/fail-if-dirty-repo.sh
# Runs all tests.
# This only runs on local dev environment not CI environment.
.PHONY: test-all-local
test-all-local: test test-e2e
# Runs gofmt and goimports.
# Even though goimports runs gofmt, it runs it without the -s (simplify) flag
# and offers no option to turn it on. So we run them in sequence.
.PHONY: fmt-go
fmt-go: pull-buildenv buildenv-dirs
@docker run $(DOCKER_RUN_ARGS) gofmt -s -w $(NOMOS_CODE_DIRS)
@docker run $(DOCKER_RUN_ARGS) goimports -w $(NOMOS_CODE_DIRS)
# Runs shfmt.
.PHONY: fmt-sh
fmt-sh:
@./scripts/fmt-bash.sh
.PHONY: tidy
tidy:
go mod tidy
.PHONY: vendor
vendor:
go mod vendor
.PHONY: deps
deps: tidy vendor
.PHONY: lint
lint: lint-go lint-bash lint-yaml lint-license lint-license-headers
.PHONY: lint-go
lint-go: pull-buildenv buildenv-dirs
@docker run $(DOCKER_RUN_ARGS) ./scripts/lint-go.sh $(NOMOS_GO_PKG)
.PHONY: lint-bash
lint-bash:
@./scripts/lint-bash.sh
.PHONY: lint-license
lint-license: pull-buildenv buildenv-dirs
@docker run $(DOCKER_RUN_ARGS) ./scripts/lint-license.sh
"$(GOBIN)/addlicense":
go install github.com/google/addlicense@v1.0.0
"$(GOBIN)/kustomize":
CGO_ENABLED=0 go install sigs.k8s.io/kustomize/kustomize/v5@$(KUSTOMIZE_VERSION)
# install kustomize binary for containerized testing
"$(BIN_DIR)/kustomize": "$(GOBIN)/kustomize"
cp $(GOBIN)/kustomize $(BIN_DIR)/kustomize
.PHONY: install-kustomize
install-kustomize: "$(BIN_DIR)/kustomize"
.PHONY: license-headers
license-headers: "$(GOBIN)/addlicense"
GOBIN=$(GOBIN) ./scripts/license-headers.sh add
.PHONY: lint-license-headers
lint-license-headers: "$(GOBIN)/addlicense"
GOBIN=$(GOBIN) ./scripts/license-headers.sh lint
.PHONY: lint-yaml
lint-yaml:
@./scripts/lint-yaml.sh
.PHONY: test-loggers
test-loggers:
GOBIN=$(GOBIN) ./scripts/generate-test-loggers.sh
# Print the value of a variable
print-%:
@echo $($*)
####################################################################################################
# MANUAL TESTING COMMANDS
# Reapply the resources, including a new image. Use this to update with your code changes.
.PHONY: manual-test-refresh
manual-test-refresh: config-sync-manifest
kubectl apply -f ${NOMOS_MANIFEST_STAGING_DIR}/config-sync-manifest.yaml
####################################################################################################