This repository has been archived by the owner on Oct 12, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Makefile
127 lines (99 loc) · 5.13 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
KREPO = transformations
KREPO_DESC = Triggermesh Transformation engine
COMMANDS = transformation-controller transformation-adapter
TARGETS ?= linux/amd64
BASE_DIR ?= $(CURDIR)
OUTPUT_DIR ?= $(BASE_DIR)/_output
BIN_OUTPUT_DIR ?= $(OUTPUT_DIR)
TEST_OUTPUT_DIR ?= $(OUTPUT_DIR)
COVER_OUTPUT_DIR ?= $(OUTPUT_DIR)
DIST_DIR ?= $(OUTPUT_DIR)
DOCKER ?= docker
IMAGE_REPO ?= gcr.io/triggermesh
IMAGE_TAG ?= latest
IMAGE_SHA ?= $(shell git rev-parse HEAD)
GO ?= go
GOFMT ?= gofmt
GOLINT ?= golangci-lint run
GOTOOL ?= go tool
GOTEST ?= gotestsum --junitfile $(TEST_OUTPUT_DIR)/$(KREPO)-unit-tests.xml --format pkgname-and-test-fails --
KUBECTL ?= kubectl
SED ?= sed
GOPKGS = ./cmd/... ./pkg/apis/... ./pkg/pipeline/... ./pkg/reconciler/...
LDFLAGS = -extldflags=-static -w -s
HAS_GOTESTSUM := $(shell command -v gotestsum;)
HAS_GOLANGCI_LINT := $(shell command -v golangci-lint;)
.PHONY: help mod-download build install release test coverage lint fmt fmt-test images cloudbuild-test cloudbuild clean
all: build
install-gotestsum:
ifndef HAS_GOTESTSUM
curl -SL https://github.com/gotestyourself/gotestsum/releases/download/v0.4.2/gotestsum_0.4.2_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.26.0
endif
$(COMMANDS):
@mkdir -p $(BIN_OUTPUT_DIR)
$(GO) build -ldflags "$(LDFLAGS)" -o $(BIN_OUTPUT_DIR)/ ./cmd/$@
help: ## Display this help
@awk 'BEGIN {FS = ":.*?## "; printf "\n$(KREPO_DESC)\nUsage:\n make \033[36m<source>\033[0m\n"} /^[a-zA-Z0-9._-]+:.*?## / {printf " \033[36m%-20s\033[0m %s\n", $$1, $$2}' $(MAKEFILE_LIST)
mod-download: ## Download go modules
$(GO) mod download
build: $(COMMANDS) ## Build the binary
release: ## Build release artifacts
@set -e ; \
for bin in $(COMMANDS) ; do \
for platform in $(TARGETS); do \
GOOS=$${platform%/*} ; \
GOARCH=$${platform#*/} ; \
RELEASE_BINARY=$$bin-$${GOOS}-$${GOARCH} ; \
[ $${GOOS} = "windows" ] && RELEASE_BINARY=$${RELEASE_BINARY}.exe ; \
echo "GOOS=$${GOOS} GOARCH=$${GOARCH} $(GO) build -ldflags "$(LDFLAGS)" -o $(DIST_DIR)/$${RELEASE_BINARY}" ./cmd/$$bin ; \
GOOS=$${GOOS} GOARCH=$${GOARCH} $(GO) build -ldflags "$(LDFLAGS)" -o $(DIST_DIR)/$${RELEASE_BINARY} ./cmd/$$bin ; \
done ; \
done
$(KUBECTL) create -f config --dry-run=client -o yaml |\
$(SED) 's|ko://github.com/triggermesh/bumblebee/cmd/\(.*\)|$(IMAGE_REPO)/\1:${IMAGE_TAG}|' > $(DIST_DIR)/transformation.yaml
test: install-gotestsum ## Run unit tests
@mkdir -p $(TEST_OUTPUT_DIR)
$(GOTEST) -p=1 -race -cover -coverprofile=$(TEST_OUTPUT_DIR)/$(KREPO)-c.out $(GOPKGS)
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)))
IMAGES = $(foreach cmd,$(COMMANDS),$(cmd).image)
images: $(IMAGES) ## Builds container images
$(IMAGES): %.image:
$(DOCKER) build -t $(IMAGE_REPO)/$* -f ./cmd/$*/Dockerfile . ;
CLOUDBUILD_TEST = $(foreach cmd,$(COMMANDS),$(cmd).cloudbuild-test)
cloudbuild-test: $(CLOUDBUILD_TEST) ## Test container image build with Google Cloud Build
$(CLOUDBUILD_TEST): %.cloudbuild-test:
# NOTE (antoineco): Cloud Build started failing recently with authentication errors when --no-push is specified.
# Pushing images with the "_" tag is our hack to avoid those errors and ensure the build cache is always updated.
gcloud builds submit $(BASE_DIR) --config cloudbuild.yaml --substitutions _CMD=$*,COMMIT_SHA=${IMAGE_SHA},_KANIKO_IMAGE_TAG=_
CLOUDBUILD = $(foreach cmd,$(COMMANDS),$(cmd).cloudbuild)
cloudbuild: $(CLOUDBUILD) ## Build and publish image to GCR
$(CLOUDBUILD): %.cloudbuild:
gcloud builds submit $(BASE_DIR) --config cloudbuild.yaml --substitutions _CMD=$*,COMMIT_SHA=${IMAGE_SHA},_KANIKO_IMAGE_TAG=${IMAGE_TAG}
clean: ## Clean build artifacts
@for bin in $(COMMANDS) ; do \
for platform in $(TARGETS); do \
GOOS=$${platform%/*} ; \
GOARCH=$${platform#*/} ; \
RELEASE_BINARY=$$bin-$${GOOS}-$${GOARCH} ; \
[ $${GOOS} = "windows" ] && RELEASE_BINARY=$${RELEASE_BINARY}.exe ; \
$(RM) -v $(DIST_DIR)/$${RELEASE_BINARY}; \
done ; \
$(RM) -v $(BIN_OUTPUT_DIR)/$$bin; \
done
@$(RM) -v $(DIST_DIR)/transformation.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