-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathMakefile
More file actions
153 lines (127 loc) · 5.54 KB
/
Makefile
File metadata and controls
153 lines (127 loc) · 5.54 KB
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
# 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 commands 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 catalog 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
## HELP
help: ## Display this concise help, ie only the porcelain target.
@awk 'BEGIN {FS = ":.*##"; printf "\nUsage:\n make \033[36m<target>\033[0m\n"} /^[a-zA-Z_0-9-]+:.*?##/ { printf " \033[36m%-25s\033[0m %s\n", $$1, $$2 } /^##@/ { printf "\n\033[1m%s\033[0m\n", substr($$0, 5) } ' $(MAKEFILE_LIST)
help-all: ## Display all help items, ie including plumbing targets.
@awk 'BEGIN {FS = ":.*#"; printf "\nUsage:\n make \033[36m<target>\033[0m\n"} /^[a-zA-Z_0-9-]+:.*?#/ { printf " \033[36m%-25s\033[0m %s\n", $$1, $$2 } /^##@/ { printf "\n\033[1m%s\033[0m\n", substr($$0, 5) } ' $(MAKEFILE_LIST)
# Image URL to use all building/pushing image targets
IMG ?= controller:latest
# ENVTEST_K8S_VERSION refers to the version of kubebuilder assets to be downloaded by envtest binary.
ENVTEST_K8S_VERSION = 1.26.1
# Default Test Path for a single integration test. Defaults to root
TEST_PATH ?= ./...
# Number of times to run integration tests (set >1 to hunt flakes)
INTEGRATION_RUNS ?= 1
BLUE := $(shell printf "\033[34m")
YELLOW := $(shell printf "\033[33m")
RED := $(shell printf "\033[31m")
GREEN := $(shell printf "\033[32m")
CNone := $(shell printf "\033[0m")
INFO = echo ${TIME} ${BLUE}[ .. ]${CNone}
WARN = echo ${TIME} ${YELLOW}[WARN]${CNone}
ERR = echo ${TIME} ${RED}[FAIL]${CNone}
OK = echo ${TIME} ${GREEN}[ OK ]${CNone}
FAIL = (echo ${TIME} ${RED}[FAIL]${CNone} && false)
# 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
# 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
.PHONY: help
.PHONY: all
all: build
##@ Test
.PHONY: test
test: swag ## Run tests
@if ! go test ./... -coverprofile cover.out -v; then \
$(WARN) "Tests failed"; \
exit 1; \
fi ; \
$(OK) Tests passed
.PHONY: test-integration
test-integration: swag ## Run integration tests (set INTEGRATION_RUNS>1 for flakiness detection)
@for run in $$(seq 1 $(INTEGRATION_RUNS)); do \
$(INFO) "Integration run $$run/$(INTEGRATION_RUNS)"; \
coverprofile_flag=""; \
if [ "$$run" -eq "$(INTEGRATION_RUNS)" ]; then \
coverprofile_flag="-coverprofile cover.out"; \
fi; \
if ! go test ./... -count=1 $$coverprofile_flag -v --tags integration; then \
$(WARN) "Tests failed on run $$run"; \
exit 1; \
fi ; \
done ; \
$(OK) Tests passed
.PHONY: test-integration-single
test-integration-single: ## Run a single integration test. Requires TEST_PATH and TEST_NAME to be set.
ifndef TEST_NAME
@$(ERR) "TEST_NAME is not set. Please set it to the name of the test function."
@exit 1
endif
@$(INFO) "Running integration test: $(TEST_NAME) in path: $(TEST_PATH)"
@if ! go test $(TEST_PATH) -coverprofile cover.out -v --tags integration --run $(TEST_NAME); then \
$(WARN) "Tests failed"; \
exit 1; \
fi ; \
$(OK) Tests passed
.PHONY: lint.check
lint.check: ## Check install of golanci-lint
@if ! golangci-lint --version 2>&1 >> /dev/null; then \
echo -e "\033[0;33mgolangci-lint is not installed: run \`\033[0;32mmake lint.install\033[0m\033[0;33m\` or install it from https://golangci-lint.run\033[0m"; \
exit 1; \
fi
.PHONY: lint.install
lint.install: ## Install golangci-lint to the go bin dir
@if ! golangci-lint --version 2>&1 >> /dev/null; then \
$(INFO) "Installing golangci-lint"; \
curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/main/install.sh | sh -s -- -b $(GOBIN) v2.7.2; \
fi
.PHONY: lint
lint: lint.check ## Run golangci-lint
@if ! golangci-lint run; then \
$(WARN) "golangci-lint found issues with your code. Please check and fix them before committing."; \
exit 1; \
fi ; \
$(OK) No linting issues found
##@ Run
.PHONY: reviewable
reviewable: lint test-integration # Ensure a PR is ready for review.
@go mod tidy
.PHONY: check-diff
check-diff: swag # Ensure branch is clean.
@test -z "$$(git status --porcelain)" || (echo "$$(git status --porcelain)" && $(FAIL))
@$(OK) branch is clean
.PHONY: build
build: ## Build the service in Docker Compose
@docker compose -f docker-compose.yml build api
.PHONY: dev
up: ## Run the service in Docker Compose
@docker compose -f docker-compose.yml up -d
.PHONY: dev.stop
down: ## Stop the service running in Docker Compose
@docker compose -f docker-compose.yml down
swag: ## swag setup and lint
@go tool swag init --parseDependency --parseInternal
@go tool swag fmt
.PHONY: generate-keys
generate-keys:
@$(INFO) "Generating keys for the service"
@openssl genrsa -out private_key.pem 2048
@openssl rsa -in private_key.pem -pubout -out public_key.pem
@$(OK) keys generated
tag: ## Build and tag a production-based image of the service
@docker build -t ghcr.io/compliance-framework/api:latest_local .