forked from RedHatInsights/edge-api
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
216 lines (174 loc) · 7.53 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
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
OS := $(shell uname)
UNAME_S := $(shell uname -s)
OS_SED :=
ifeq ($(UNAME_S),Darwin)
OS_SED += ""
endif
OCI_TOOL=$(shell command -v podman || command -v docker)
# Match logic in build_deploy.sh
IMAGE_TAG=$(shell git rev-parse --short=7 HEAD)
EDGE_API_CONTAINER_TAG="quay.io/cloudservices/edge-api:$(IMAGE_TAG)"
TEST_CONTAINER_TAG="quay.io/fleet-management/libfdo-data:$(IMAGE_TAG)"
KUBECTL=kubectl
NAMESPACE=default
TEST_OPTIONS=-race
BUILD_TAGS=-tags=fdo
GOLANGCI_LINT_COMMON_OPTIONS=\
--enable=errcheck,gocritic,gofmt,goimports,gosec,gosimple,govet,ineffassign,revive,staticcheck,typecheck,unused,bodyclose \
--fix=false \
--go=1.18 \
--max-same-issues=20 \
--print-issued-lines=true \
--print-linter-name=true \
--sort-results=true \
--timeout=5m0s \
--uniq-by-line=false
EXCLUDE_DIRS=-e /test/ -e /cmd/db -e /cmd/kafka \
-e /pkg/clients/imagebuilder/mock_imagebuilder \
-e /pkg/imagebuilder/mock_imagebuilder \
-e /pkg/clients/inventory/mock_inventory \
-e /pkg/errors -e /pkg/services/mock_services -e /unleash \
-e /api
CONTAINERFILE_NAME=Dockerfile
.PHONY: all bonfire-config-local bonfire-config-github build-containers \
build-edge-api-container clean coverage coverage-html coverage-no-fdo \
create-ns deploy-app deploy-env fmt generate-docs help lint pre-commit \
restart-app scale-down scale-up scan_project test test-clean-no-fdo \
test-no-fdo vet vet-no-fdo
bonfire-config-local:
@cp default_config.yaml.local.example config.yaml
@sed -i $(OS_SED) 's|REPO|$(PWD)|g' config.yaml
bonfire-config-github:
@cp default_config.yaml.github.example config.yaml
build-containers: build-edge-api-container build-test-container
build-edge-api-container:
$(OCI_TOOL) build \
--file "$(CONTAINERFILE_NAME)" \
--no-cache \
--tag "$(EDGE_API_CONTAINER_TAG)" \
.
build-test-container:
cd test-container; \
$(OCI_TOOL) build \
--file "$(CONTAINERFILE_NAME)" \
--no-cache \
--tag "$(TEST_CONTAINER_TAG)" \
.
clean:
golangci-lint cache clean
coverage:
go test $(BUILD_TAGS) $$(go list $(BUILD_TAGS) ./... | grep -v $(EXCLUDE_DIRS)) $(TEST_OPTIONS) -coverprofile=coverage.txt -covermode=atomic
coverage-output-no-fdo:
go test $$(go list ./... | grep -v $(EXCLUDE_DIRS)) $(TEST_OPTIONS) -coverprofile=coverage.txt -covermode=atomic
coverage-html:
go tool cover -html=coverage.txt -o coverage.html
coverage-no-fdo:
go test $$(go list ./... | grep -v $(EXCLUDE_DIRS)) $(TEST_OPTIONS) -coverprofile=coverage.txt -covermode=atomic -json > coverage.json
create-ns:
$(KUBECTL) create ns $(NAMESPACE)
deploy-app:
bonfire deploy edge -n $(NAMESPACE)
deploy-env:
bonfire deploy-env -n $(NAMESPACE)
fmt:
go fmt $$(go list ./... | grep -v /vendor/)
generate-docs:
go run cmd/spec/main.go
help:
@echo "Please use \`make <target>' where <target> is one of:"
@echo ""
@echo "--- General Commands ---"
@echo "bonfire-config-local Create bonfire config for deploying from your local repository"
@echo "bonfire-config-github Create bonfire config for deploying from the github repository"
@echo "build-containers Builds all the container images"
@echo "build-edge-api-container Builds the edge-api container"
@echo "build-test-container Builds the test container"
@echo "clean Removes cached golangci files"
@echo "coverage Runs 'go test' coverage on the project"
@echo "coverage-html Create HTML version of coverage report"
@echo "coverage-no-fdo Runs 'go test' coverage on the project without FDO"
@echo "create-ns Creates a namespace in kubernetes"
@echo " @param NAMESPACE - (optional) the namespace to use"
@echo "deploy-app Deploys the edge app in the given namespace"
@echo " @param NAMESPACE - (optional) the namespace to use"
@echo "deploy-env Creates a ClowdEnvironment in the given namespace"
@echo " @param NAMESPACE - (optional) the namespace to use"
@echo "fmt Runs 'go fmt' on the project"
@echo "generate-docs Creates OpenAPI specification for the project"
@echo "help Show this message"
@echo "lint Runs 'golint' on the project"
@echo "golangci-lint Runs 'golangci-lint' on the project"
@echo "openapi Generates an openapi.{json,yaml} file in /cmd/spec/"
@echo "pre-commit Runs fmt, vet, lint, and clean on the project"
@echo "restart-app Scales the edge-api-service deployment down to 0 then up to 1 in the given namespace"
@echo " @param NAMESPACE - (optional) the namespace to use"
@echo "scale-down Scales the edge-api-service deployment down to 0 in the given namespace"
@echo " @param NAMESPACE - (optional) the namespace to use"
@echo "scale-up Scales the edge-api-service deployment up to 1 in the given namespace"
@echo " @param NAMESPACE - (optional) the namespace to use"
@echo "scan_project Run security scan"
@echo "swaggo Runs swaggo/swag and converts to openapi.json in /api"
@echo "swaggo_setup" Installs necessary packages to use swaggo
@echo "test Runs 'go test' on the project"
@echo "test-clean-no-fdo Runs 'go test' on the project without FDO"
@echo "test-no-fdo Runs 'go test' on the project without FDO"
@echo "vet Runs 'go vet' on the project"
@echo "vet-no-fdo Runs 'go vet' on the project without FDO"
@echo ""
golangci-lint:
if [ "$(GITHUB_ACTION)" != '' ];\
then\
OUT_FORMAT="--out-format=line-number";\
TARGET_FILES=$$(go list $(BUILD_TAGS) ./... | grep -v /vendor/);\
else\
OUT_FORMAT="--out-format=colored-line-number";\
TARGET_FILES=$$(go list -f '{{.Dir}}' ${BUILD_TAGS} ./... | grep -v '/vendor/');\
fi;\
golangci-lint run $(GOLANGCI_LINT_COMMON_OPTIONS) $(OUT_FORMAT) \
$(TARGET_FILES)
golangci-lint-no-fdo:
if [ "$(GITHUB_ACTION)" != '' ]; \
then \
OUT_FORMAT="--out-format=line-number"; \
TARGET_FILES=$$(go list ./... | grep -v /vendor/);\
else \
OUT_FORMAT="--out-format=colored-line-number"; \
TARGET_FILES=$$(go list -f '{{.Dir}}' ./... | grep -v '/vendor/');\
fi;\
golangci-lint run $(GOLANGCI_LINT_COMMON_OPTIONS) $(OUT_FORMAT) \
$(TARGET_FILES)
lint:
golint $$(go list $(BUILD_TAGS) ./... | grep -v /vendor/)
openapi:
go run cmd/spec/main.go
pre-commit:
$(MAKE) golangci-lint-no-fdo
$(MAKE) test-clean-no-fdo
restart-app:
$(MAKE) scale-down NAMESPACE=$(NAMESPACE)
sleep 5
$(MAKE) scale-up NAMESPACE=$(NAMESPACE)
scale-down:
$(KUBECTL) scale --replicas=0 deployment/edge-api-service -n $(NAMESPACE)
scale-up:
$(KUBECTL) scale --replicas=1 deployment/edge-api-service -n $(NAMESPACE)
scan_project:
./sonarqube.sh
swaggo_setup:
go install github.com/swaggo/swag/cmd/swag@latest
mkdir -p api
swaggo:
swag init --generalInfo api.go --o ./api --dir pkg/models,pkg/routes --parseDependency
go run ./cmd/swagger2openapi/main.go api/swagger.json api/openapi.json
test:
go test $(BUILD_TAGS) $$(go list $(BUILD_TAGS) ./... | grep -v /test/) $(TEST_OPTIONS)
test-clean-no-fdo:
go test -count=1 $$(go list ./... | grep -v /test/) $(TEST_OPTIONS)
test-no-fdo:
go test $$(go list ./... | grep -v /test/) $(TEST_OPTIONS)
vet:
go mod tidy
go install -a
go vet $(BUILD_TAGS) $$(go list $(BUILD_TAGS) ./... | grep -v /vendor/)
vet-no-fdo:
go vet $$(go list ./... | grep -v /vendor/)