forked from triggermesh/triggermesh
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
197 lines (152 loc) · 8.46 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
# Copyright 2022 TriggerMesh Inc.
#
# 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.
KREPO = triggermesh
KREPO_DESC = TriggerMesh Open Source Components (sources, targets, filter, router, etc.)
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_BINARIES := confluenttarget-adapter ibmmqsource-adapter ibmmqtarget-adapter xslttransformation-adapter dataweavetransformation-adapter
CUSTOM_BUILD_IMAGES := ibmmqsource-adapter ibmmqtarget-adapter xslttransformation-adapter dataweavetransformation-adapter
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)
# 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
GOPKGS = ./cmd/... ./pkg/apis/... ./pkg/extensions/... ./pkg/flow/... ./pkg/metrics/... ./pkg/mturl/... ./pkg/reconciler/... ./pkg/routing/... ./pkg/sources/... ./pkg/status/... ./pkg/targets/...
GOPKGS_SKIP_TESTS = $(GOMODULE)/pkg/sources/reconciler/ibmmqsource \
$(GOMODULE)/pkg/targets/reconciler/ibmmqtarget \
$(GOMODULE)/pkg/sources/adapter/ibmmqsource/mq \
$(GOMODULE)/pkg/targets/adapter/ibmmqtarget/mq \
$(GOMODULE)/pkg/targets/adapter/ibmmqtarget \
$(GOMODULE)/pkg/sources/adapter/ibmmqsource \
$(GOMODULE)/cmd/ibmmqsource-adapter \
$(GOMODULE)/cmd/ibmmqtarget-adapter \
$(GOMODULE)/cmd/xslttransformation-adapter \
$(GOMODULE)/pkg/flow/adapter/xslttransformation
# List of packages that expect the environment to have installed
# the dependencies for running tests:
#
# libxml2-dev
#
GOPKGS_TESTS_WITH_DEPENDENCIES = $(GOMODULE)/cmd/xslttransformation-adapter \
$(GOMODULE)/pkg/flow/adapter/xslttransformation
# 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
HAS_GOTESTSUM := $(shell command -v gotestsum;)
HAS_GOLANGCI_LINT := $(shell command -v golangci-lint;)
SED := sed -i
OS := $(shell sh -c 'uname 2>/dev/null || echo Unknown')
ifeq ($(OS),$(filter $(OS),Darwin FreeBSD NetBSD))
SED += ''
endif
.PHONY: help all build release vm-images 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
$(filter-out $(CUSTOM_BUILD_BINARIES), $(COMMANDS)): ## Build artifact
$(GO) build -ldflags "$(LDFLAGS_STATIC)" -o $(BIN_OUTPUT_DIR)/$@ ./cmd/$@
confluenttarget-adapter:
CGO_ENABLED=1 $(GO) build -ldflags "$(LDFLAGS_STATIC)" -o $(BIN_OUTPUT_DIR)/$@ ./cmd/$@
dataweavetransformation-adapter: ## Builds DataWeave
$(GO) build -ldflags "$(LDFLAGS)" -o $(BIN_OUTPUT_DIR)/$@ ./cmd/$@
deploy: ## Deploy TriggerMesh stack to default Kubernetes cluster
$(KO) resolve -f $(BASE_DIR)/config > $(BASE_DIR)/triggermesh-$(IMAGE_TAG).yaml
@for component in $(CUSTOM_BUILD_IMAGES); do \
$(MAKE) -C ./cmd/$$component build CONTEXT=$(BASE_DIR) IMAGE_TAG=$(KO_DOCKER_REPO)/$$component-$(IMAGE_TAG) && \
$(MAKE) -C ./cmd/$$component push IMAGE_TAG=$(KO_DOCKER_REPO)/$$component-$(IMAGE_TAG) && \
$(SED) 's|value: .*'$$component'.*|value: $(KO_DOCKER_REPO)/'$$component'-$(IMAGE_TAG)|g' $(BASE_DIR)/triggermesh-$(IMAGE_TAG).yaml || exit 1; \
done
$(KO) apply -f $(BASE_DIR)/triggermesh-$(IMAGE_TAG).yaml
@rm $(BASE_DIR)/triggermesh-$(IMAGE_TAG).yaml
undeploy: ## Remove TriggerMesh stack from default Kubernetes cluster
$(KO) delete -f $(BASE_DIR)/config
vm-images:
@$(MAKE) -C packer/
release: ## Publish container images and generate release manifests
@mkdir -p $(DIST_DIR)
$(KO) resolve -f config/ -l 'triggermesh.io/crd-install' > $(DIST_DIR)/triggermesh-crds.yaml
@cp config/namespace/100-namespace.yaml $(DIST_DIR)/triggermesh.yaml
$(KO) resolve $(KOFLAGS) -B -t latest -f config/ -l '!triggermesh.io/crd-install' > /dev/null
$(KO) resolve $(KOFLAGS) -B -t $(IMAGE_TAG) --tag-only -f config/ -l '!triggermesh.io/crd-install' >> $(DIST_DIR)/triggermesh.yaml
@for component in $(CUSTOM_BUILD_IMAGES); do \
$(MAKE) -C ./cmd/$$component build CONTEXT=$(BASE_DIR) IMAGE_TAG=$(KO_DOCKER_REPO)/$$component:$(IMAGE_TAG) && \
$(MAKE) -C ./cmd/$$component tag IMAGE_TAG=$(KO_DOCKER_REPO)/$$component:$(IMAGE_TAG) TAGS=$(KO_DOCKER_REPO)/$$component:latest && \
$(MAKE) -C ./cmd/$$component push IMAGE_TAG=$(KO_DOCKER_REPO)/$$component && \
$(SED) 's/'$$component':.*/'$$component':$(IMAGE_TAG)/g' $(DIST_DIR)/triggermesh.yaml || exit 1; \
done
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)
@for component in $(CUSTOM_BUILD_IMAGES); do \
$(MAKE) -C ./cmd/$$component test || exit 1; \
done
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) ./test/...
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_PUBLISHABLE = $(filter-out $(CUSTOM_BUILD_IMAGES), $(COMMANDS))
KO_IMAGES = $(foreach cmd,$(KO_PUBLISHABLE),$(cmd).image)
CUSTOM_IMAGES = $(foreach cmd,$(CUSTOM_BUILD_IMAGES),$(cmd).image)
images: $(KO_IMAGES) $(CUSTOM_IMAGES) ## Build container images
$(KO_IMAGES): %.image:
$(KO) publish --push=false -B --tag-only -t $(IMAGE_TAG) ./cmd/$*
$(CUSTOM_IMAGES): %.image:
@$(MAKE) -C ./cmd/$* image CONTEXT=$(BASE_DIR) IMAGE_TAG=$(KO_DOCKER_REPO)/$*:$(IMAGE_TAG)
clean: ## Clean build artifacts
@for bin in $(COMMANDS) ; do \
$(RM) -v $(BIN_OUTPUT_DIR)/$$bin; \
done
@$(RM) -v $(DIST_DIR)/triggermesh-crds.yaml $(DIST_DIR)/triggermesh.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