This repository has been archived by the owner on Dec 11, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathMakefile
144 lines (108 loc) · 5.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
# Copyright 2022 TriggerMesh Inc.
# SPDX-License-Identifier: Apache-2.0
KREPO = triggermesh-core
KREPO_DESC = TriggerMesh Core Components (broker, triggers)
BASE_DIR ?= $(CURDIR)
OUTPUT_DIR ?= $(BASE_DIR)/_output
# Dynamically generate the list of commands based on the directory name cited in the cmd directory
COMMANDS := $(notdir $(wildcard cmd/*))
# Commands and images that require custom build proccess
CUSTOM_BUILD_IMAGES :=
BIN_OUTPUT_DIR ?= $(OUTPUT_DIR)
DOCS_OUTPUT_DIR ?= $(OUTPUT_DIR)
TEST_OUTPUT_DIR ?= $(OUTPUT_DIR)
COVER_OUTPUT_DIR ?= $(OUTPUT_DIR)
DIST_DIR ?= $(OUTPUT_DIR)
# Rely on ko for building/publishing images and generating/deploying manifests
KO ?= ko
KOFLAGS ?=
IMAGE_TAG ?= $(shell git rev-parse HEAD)
BROKERS_IMAGE_TAG ?= $(IMAGE_TAG)
# Go build variables
GO ?= go
GOFMT ?= gofmt
GOLINT ?= golangci-lint run --timeout 5m
GOTOOL ?= go tool
GOTEST ?= gotestsum --junitfile $(TEST_OUTPUT_DIR)/$(KREPO)-unit-tests.xml --format pkgname-and-test-fails --
GOMODULE = github.com/triggermesh/triggermesh-core
GOPKGS = ./cmd/... ./pkg/apis/... ./pkg/reconciler/...
GOPKGS_SKIP_TESTS =
# List of packages that expect the environment to have installed
# the dependencies for running tests:
#
# ...
#
GOPKGS_TESTS_WITH_DEPENDENCIES =
# This environment variable should be set when dependencies have been installed
# at the running instance.
WITH_DEPENDENCIES ?=
LDFLAGS = -w -s
LDFLAGS_STATIC = $(LDFLAGS) -extldflags=-static
TAG_REGEX := ^v([0-9]{1,}\.){2}[0-9]{1,}$
HAS_GOTESTSUM := $(shell command -v gotestsum;)
HAS_GOLANGCI_LINT := $(shell command -v golangci-lint;)
.PHONY: help all build release test lint fmt fmt-test images clean install-gotestsum install-golangci-lint deploy undeploy
.DEFAULT_GOAL := build
all: codegen build test lint
# Verify lint and tests
install-gotestsum:
ifndef HAS_GOTESTSUM
curl -SL https://github.com/gotestyourself/gotestsum/releases/download/v1.8.0/gotestsum_1.8.0_linux_amd64.tar.gz | tar -C $(shell go env GOPATH)/bin -zxf -
endif
install-golangci-lint:
ifndef HAS_GOLANGCI_LINT
curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(shell go env GOPATH)/bin v1.45.2
endif
help: ## Display this help
@awk 'BEGIN {FS = ":.*?## "; printf "\n$(KREPO_DESC)\n\nUsage:\n make \033[36m<cmd>\033[0m\n"} /^[a-zA-Z0-9._-]+:.*?## / {printf " \033[36m%-20s\033[0m %s\n", $$1, $$2}' $(MAKEFILE_LIST)
build: $(COMMANDS) ## Build all artifacts
$(COMMANDS): ## Build artifact
$(GO) build -ldflags "$(LDFLAGS_STATIC)" -o $(BIN_OUTPUT_DIR)/$@ ./cmd/$@
deploy: ## Deploy TriggerMesh stack to default Kubernetes cluster
$(KO) resolve -f $(BASE_DIR)/config > $(BASE_DIR)/triggermesh-core-$(IMAGE_TAG).yaml
$(KO) apply -f $(BASE_DIR)/triggermesh-core-$(IMAGE_TAG).yaml
@rm $(BASE_DIR)/triggermesh-core-$(IMAGE_TAG).yaml
undeploy: ## Remove TriggerMesh stack from default Kubernetes cluster
$(KO) delete -f $(BASE_DIR)/config
release: ## Publish container images and generate release manifests
@mkdir -p $(DIST_DIR)
$(KO) resolve -f config/ -l 'triggermesh.io/crd-install' > $(DIST_DIR)/triggermesh-core-crds.yaml
@cp config/namespace/100-namespace.yaml $(DIST_DIR)/triggermesh-core.yaml
ifeq ($(shell echo ${IMAGE_TAG} | egrep "${TAG_REGEX}"),${IMAGE_TAG})
$(KO) resolve $(KOFLAGS) -B -t latest -f config/ -l '!triggermesh.io/crd-install' > /dev/null
endif
$(KO) resolve $(KOFLAGS) -B -t $(IMAGE_TAG) --tag-only -f config/ -l '!triggermesh.io/crd-install' >> $(DIST_DIR)/triggermesh-core.yaml
# Update broker image references.
sed -i 's/memory-broker:latest/memory-broker:$(BROKERS_IMAGE_TAG)/g' $(DIST_DIR)/triggermesh-core.yaml
sed -i 's/redis-broker:latest/redis-broker:$(BROKERS_IMAGE_TAG)/g' $(DIST_DIR)/triggermesh-core.yaml
gen-apidocs: ## Generate API docs
GOPATH="" OUTPUT_DIR=$(DOCS_OUTPUT_DIR) ./hack/gen-api-reference-docs.sh
GOPKGS_LIST ?= $(filter-out $(GOPKGS_SKIP_TESTS), $(shell go list $(GOPKGS)))
ifdef WITH_DEPENDENCIES
GOPKGS_LIST += $(GOPKGS_TESTS_WITH_DEPENDENCIES)
endif
test: install-gotestsum ## Run unit tests
@mkdir -p $(TEST_OUTPUT_DIR)
$(GOTEST) -p=1 -race -cover -coverprofile=$(TEST_OUTPUT_DIR)/$(KREPO)-c.out $(GOPKGS_LIST)
cover: test ## Generate code coverage
@mkdir -p $(COVER_OUTPUT_DIR)
$(GOTOOL) cover -html=$(TEST_OUTPUT_DIR)/$(KREPO)-c.out -o $(COVER_OUTPUT_DIR)/$(KREPO)-coverage.html
lint: install-golangci-lint ## Lint source files
$(GOLINT) $(GOPKGS)
fmt: ## Format source files
$(GOFMT) -s -w $(shell $(GO) list -f '{{$$d := .Dir}}{{range .GoFiles}}{{$$d}}/{{.}} {{end}} {{$$d := .Dir}}{{range .TestGoFiles}}{{$$d}}/{{.}} {{end}}' $(GOPKGS))
fmt-test: ## Check source formatting
@test -z $(shell $(GOFMT) -l $(shell $(GO) list -f '{{$$d := .Dir}}{{range .GoFiles}}{{$$d}}/{{.}} {{end}} {{$$d := .Dir}}{{range .TestGoFiles}}{{$$d}}/{{.}} {{end}}' $(GOPKGS)))
KO_IMAGES = $(foreach cmd,$(COMMANDS),$(cmd).image)
images: $(KO_IMAGES) ## Build container images
$(KO_IMAGES): %.image:
$(KO) publish --push=false -B --tag-only -t $(IMAGE_TAG) ./cmd/$*
clean: ## Clean build artifacts
@for bin in $(COMMANDS) ; do \
$(RM) -v $(BIN_OUTPUT_DIR)/$$bin; \
done
@$(RM) -v $(DIST_DIR)/triggermesh-core-crds.yaml $(DIST_DIR)/triggermesh-core.yaml
@$(RM) -v $(TEST_OUTPUT_DIR)/$(KREPO)-c.out $(TEST_OUTPUT_DIR)/$(KREPO)-unit-tests.xml
@$(RM) -v $(COVER_OUTPUT_DIR)/$(KREPO)-coverage.html
# Code generation
include $(BASE_DIR)/hack/inc.Codegen.mk