-
Notifications
You must be signed in to change notification settings - Fork 3
/
Makefile
152 lines (129 loc) · 4.52 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
OS := $(shell go env GOOS)
ARCH := $(shell go env GOARCH)
MIGRATE_VERSION := v4.15.2
GOLANGCI_LINT_VERSION := v1.46.2
KUBECTL_VERSION := v1.24.1
PROTOBUF_VERSION := 21.5
PROTOBUF_TAG := v$(PROTOBUF_VERSION)
BUILDS_DIR := builds
TOOLS_DIR := tools
MIGRATE?=
KUBECTL = ./$(TOOLS_DIR)/kubectl
PROTOC = ./$(TOOLS_DIR)/protoc
IMAGE_REPO ?= quay.io/compliance-service/compserv
TAG ?= latest
.PHONY: $(BUILDS_DIR)
$(BUILDS_DIR):
mkdir -p $(BUILDS_DIR)
.PHONY: $(TOOLS_DIR)
$(TOOLS_DIR):
mkdir -p $(TOOLS_DIR)
.PHONY: build
build: $(BUILDS_DIR)
go build -o $(BUILDS_DIR) cmd/server/compserv-server.go
go build -o $(BUILDS_DIR) cmd/migrate/compserv-migrate.go
.PHONY: build-image
build-image: $(BUILDS_DIR)
podman build -f Dockerfile -t $(IMAGE_REPO):$(TAG) .
.PHONY: push-image
push-image:
podman push $(IMAGE_REPO):$(TAG)
.PHONY: clean
clean:
rm -f $(BUILDS_DIR)/*
rm -f $(TOOLS_DIR)/*
.PHONY: grpc
grpc: $(TOOLS_DIR)/protoc
$(PROTOC) --go_out=. --go-grpc_out=. --go_opt=paths=source_relative --go-grpc_opt=paths=source_relative pkg/api/compserv.proto
.PHONY: test
test:
go test -v ./pkg/...
go test -v ./cmd/...
.PHONY: test-migrate
test-migrate: $(TOOLS_DIR)/migrate
MIGRATE=$(MIGRATE) migrations/test.sh
.PHONY: test-database-integration
test-database-integration:
./utils/run_integration_tests.sh
.PHONY: update-database-schema-docs
update-database-schema-docs:
./utils/update_schema_doc.sh
.PHONY: verify
verify: verify-go-lint
# Find all bash scripts by relying on the file extension and pass them to the
# linter, but ignore anything in vendor/.
.PHONY: bash-lint
bash-lint:
shellcheck -x $(shell find . -type f -name '*.sh' -not -path "./vendor/*")
.PHONY: verify-go-lint
verify-go-lint: $(TOOLS_DIR)/golangci-lint ## Verify the golang code by linting
# we use go 1.17 because golangci-lint still has issues with 1.18
GL_DEBUG=gocritic $(TOOLS_DIR)/golangci-lint --go 1.17 run
MIGRATE = ./$(TOOLS_DIR)/migrate
$(TOOLS_DIR)/migrate: $(TOOLS_DIR) ## Download migrate locally if necessary.
ifeq (,$(wildcard $(MIGRATE)))
ifeq (,$(shell which migrate 2>/dev/null))
@{ \
set -e ;\
curl -sSL https://github.com/golang-migrate/migrate/releases/download/$(MIGRATE_VERSION)/migrate.$(OS)-$(ARCH).tar.gz | tar xz migrate -O > $(MIGRATE) ;\
chmod u+x $(MIGRATE) ;\
}
else
MIGRATE = $(shell which migrate)
endif
endif
$(TOOLS_DIR)/golangci-lint:
export \
VERSION=$(GOLANGCI_LINT_VERSION) \
URL=https://raw.githubusercontent.com/golangci/golangci-lint \
BINDIR=$(TOOLS_DIR) && \
curl -sfL $$URL/$$VERSION/install.sh | sh -s $$VERSION
$(TOOLS_DIR)/golangci-lint version
$(TOOLS_DIR)/golangci-lint linters
.PHONY: deploy
deploy: $(TOOLS_DIR)/kubectl
sed -e 's%quay.io/compliance-service/compserv:latest%$(IMAGE_REPO):$(TAG)%' kustomize/deployment.yaml -i
$(KUBECTL) apply -k kustomize
sed -e 's%$(IMAGE_REPO):$(TAG)%quay.io/compliance-service/compserv:latest%' kustomize/deployment.yaml -i
.PHONY: undeploy
undeploy: $(TOOLS_DIR)/kubectl
$(KUBECTL) delete -k kustomize
$(TOOLS_DIR)/kubectl: $(TOOLS_DIR)
# Check if tools/kubectl exists - if it does then the default value provided
# above will work.
ifeq (,$(wildcard $(KUBECTL)))
# If tools/kubectl doesn't exist, check if the binary exists somewhere else in
# the path and use that. Otherwise, if we get back an empty string here we need
# to download a copy of kubectl and put it in the tools/ directory.
ifeq (,$(shell which kubectl 2>/dev/null))
@{ \
set -e ;\
curl -L --output $(KUBECTL) "https://dl.k8s.io/release/$(KUBECTL_VERSION)/bin/linux/amd64/kubectl" ;\
chmod u+x $(KUBECTL) ;\
}
else
KUBECTL = $(shell which kubectl)
endif
endif
$(TOOLS_DIR)/protoc: $(TOOLS_DIR)
# Check if tools/protoc exists - if it does then the default value provided
# above will work.
ifeq (,$(wildcard $(PROTOC)))
# If tools/protoc doesn't exist, check if the binary exists somewhere else in
# the path and use that. Otherwise, if we get back an empty string here we need
# to download a copy of protoc and put it in the tools/ directory.
ifeq (,$(shell which protoc 2>/dev/null))
@{ \
set -e ;\
curl -L -o tools/protoc-$(PROTOBUF_VERSION)-linux-x86_64.zip https://github.com/protocolbuffers/protobuf/releases/download/$(PROTOBUF_TAG)/protoc-$(PROTOBUF_VERSION)-linux-x86_64.zip ;\
unzip -j tools/protoc-$(PROTOBUF_VERSION)-linux-x86_64.zip "*protoc" -d tools ;\
chmod u+x $(PROTOC) ;\
rm tools/protoc-$(PROTOBUF_VERSION)-linux-x86_64.zip ;\
go install google.golang.org/protobuf/cmd/protoc-gen-go@latest ;\
go install google.golang.org/grpc/cmd/protoc-gen-go-grpc@latest ;\
reset ;\
}
else
PROTOC = $(shell which protoc)
endif
endif