-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
180 lines (144 loc) · 5.04 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
# 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
# CONTAINER_TOOL defines the container tool to be used for building images.
# Be aware that the target commands are only tested with Docker which is
# scaffolded by default. However, you might want to replace it to use other
# tools. (i.e. podman)
CONTAINER_TOOL ?= docker
# Setting SHELL to bash allows bash commands to be executed by recipes.
# Options are set to exit when a recipe line exits non-zero or a piped command fails.
SHELL = /usr/bin/env bash -o pipefail
.SHELLFLAGS = -ec
##@ General
# The help target prints out all targets with their descriptions organized
# beneath their categories. The categories are represented by '##@' and the
# target descriptions by '##'. The awk command is responsible for reading the
# entire set of makefiles included in this invocation, looking for lines of the
# file as xyz: ## something, and then pretty-format the target and help. Then,
# if there's a line with ##@ something, that gets pretty-printed as a category.
# More info on the usage of ANSI control characters for terminal formatting:
# https://en.wikipedia.org/wiki/ANSI_escape_code#SGR_parameters
# More info on the awk command:
# http://linuxcommand.org/lc3_adv_awk.php
##@ Development
.PHONY: fmt
fmt: ## Run go fmt against code.
go fmt ./...
.PHONY: vet
vet: ## Run go vet against code.
go vet ./...
.PHONY: test
test: ## Run tests.
bash scripts/test.sh
.PHONY: lint
lint: golangci-lint ## Run golangci-lint linter
$(GOLANGCI_LINT) run
.PHONY: lint-fix
lint-fix: golangci-lint ## Run golangci-lint linter and perform fixes
$(GOLANGCI_LINT) run --fix
##@ CLI
.PHONY: install-cli
build-cli: build ## Build CLI binary.
ln -sf $(LOCALBIN)/quoxy-cli quoxy
.PHONY: uninstall-cli
uninstall-cli: ## Uninstall CLI binary.
rm quoxy
##@ Build
.PHONY: clean-build
clean-build: install fmt vet ## Build manager binary.
# Build all binaries
@for d in cmd/*; do \
if [ -d $$d ]; then \
if [ ! -f $(LOCALBIN)/quoxy-$$(basename $$d) ]; then \
go build -o $(LOCALBIN)/quoxy-$$(basename $$d) $$d/main.go; \
fi; \
fi; \
done
.PHONY: build
build: clean ## Remove build artifacts.
@for d in cmd/*; do \
go build -o $(LOCALBIN)/quoxy-$$(basename $$d) $$d/main.go; \
done
.PHONY: clean
clean: fmt vet test lint ## Remove build artifacts.
rm -rf $(LOCALBIN)/quoxy-*
.PHONY: run
run: clean-build ## Run controllers from your host.
@if [ ! -f /tmp/quoxy-logs ]; then \
mkfifo /tmp/quoxy-logs; \
fi
@export LOG_LEVEL=INFO; \
cat /tmp/quoxy-logs & \
for d in $(LOCALBIN)/quoxy-*; do \
if [ $$(basename $$d) = "quoxy-cli" ]; then \
continue; \
fi; \
( $$d 2>&1 | sed "s/^/[$$(basename $$d)] /" ) >> /tmp/quoxy-logs & \
done
##@ Build Docker
IMG_BASE ?= quoxy
POSSIBLE_SERVICES = "proxy rest-api token-handler"
.PHONY: check-service
check-service:
@if [ -z "$(service)" ]; then \
echo "service is not defined"; \
exit 1; \
fi
@if ! echo "$(POSSIBLE_SERVICES)" | grep -q "\b$$service\b"; then \
echo "$(service) is not in the list of possible services"; \
exit 1; \
fi
.PHONY: docker-build
docker-build: check-service ## Build docker image with the manager.
@echo "Building docker image for $(service)"
$(CONTAINER_TOOL) build --no-cache -t ${IMG_BASE}-$(service) --target $(service) .
.PHONY: docker-build-cache
docker-build-cache: check-service ## Build docker image with the manager.
@echo "Building docker image for $(service)"
$(CONTAINER_TOOL) build -t ${IMG_BASE}-$(service) --target $(service) .
.PHONY: docker-push
docker-push: docker-build ## Push docker image with the manager.
$(CONTAINER_TOOL) push ${IMG_BASE}-$(service)
.PHONY: docker-run
docker-run: docker-build-cache
docker rm ${IMG_BASE}-$(service) || true
$(CONTAINER_TOOL) run --name ${IMG_BASE}-$(service) ${IMG_BASE}-$(service):latest
##@ Deployment
ifndef ignore-not-found
ignore-not-found = false
endif
##@ Dependencies
.PHONY: install
install: ## Install dependencies
go mod vendor
## Location to install dependencies to
LOCALBIN ?= $(shell pwd)/bin
$(LOCALBIN):
mkdir -p $(LOCALBIN)
## Tool Binaries
ENVTEST ?= $(LOCALBIN)/setup-envtest-$(ENVTEST_VERSION)
GOLANGCI_LINT = $(LOCALBIN)/golangci-lint-$(GOLANGCI_LINT_VERSION)
## Tool Versions
ENVTEST_VERSION ?= release-0.18
GOLANGCI_LINT_VERSION ?= v1.57.2
.PHONY: golangci-lint
golangci-lint: $(GOLANGCI_LINT) ## Download golangci-lint locally if necessary.
$(GOLANGCI_LINT): $(LOCALBIN)
$(call go-install-tool,$(GOLANGCI_LINT),github.com/golangci/golangci-lint/cmd/golangci-lint,${GOLANGCI_LINT_VERSION})
# go-install-tool will 'go install' any package with custom target and name of binary, if it doesn't exist
# $1 - target path with name of binary (ideally with version)
# $2 - package url which can be installed
# $3 - specific version of package
define go-install-tool
@[ -f $(1) ] || { \
set -e; \
package=$(2)@$(3) ;\
echo "Downloading $${package}" ;\
GOBIN=$(LOCALBIN) go install $${package} ;\
mv "$$(echo "$(1)" | sed "s/-$(3)$$//")" $(1) ;\
}
endef