-
-
Notifications
You must be signed in to change notification settings - Fork 37
/
Copy pathMakefile
223 lines (197 loc) · 7.78 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
217
218
219
220
221
222
223
AUDIT_DIR := ./components/audit
AUTH_DIR := ./components/auth
INFRA_DIR := ./components/infra
MDZ_DIR := ./components/mdz
LEDGER_DIR := ./components/ledger
TRANSACTION_DIR := ./components/transaction
BLUE := \033[36m
NC := \033[0m
BOLD := \033[1m
RED := \033[31m
MAGENTA := \033[35m
DOCKER_VERSION := $(shell docker version --format '{{.Server.Version}}')
DOCKER_MIN_VERSION := 20.10.13
DOCKER_CMD := $(shell \
if [ "$(shell printf '%s\n' "$(DOCKER_MIN_VERSION)" "$(DOCKER_VERSION)" | sort -V | head -n1)" = "$(DOCKER_MIN_VERSION)" ]; then \
echo "docker compose"; \
else \
echo "docker-compose"; \
fi \
)
.PHONY: help
help:
@echo ""
@echo ""
@echo "$(BOLD)Midaz Project Management Commands$(NC)"
@echo ""
@echo ""
@echo "$(BOLD)Core Commands:$(NC)"
@echo " make test - Run tests on all projects"
@echo " make cover - Run test coverage"
@echo ""
@echo ""
@echo "$(BOLD)Code Quality Commands:$(NC)"
@echo " make lint - Run golangci-lint and performance checks"
@echo " make format - Format Go code using gofmt"
@echo " make check-logs - Verify error logging in usecases"
@echo " make check-tests - Verify test coverage for components"
@echo " make sec - Run security checks using gosec"
@echo ""
@echo ""
@echo "$(BOLD)Git Hook Commands:$(NC)"
@echo " make setup-git-hooks - Install and configure git hooks"
@echo " make check-hooks - Verify git hooks installation status"
@echo ""
@echo ""
@echo "$(BOLD)Setup Commands:$(NC)"
@echo " make set-env - Copy .env.example to .env for all components"
@echo "Usage:"
@echo " ## Root Commands"
@echo " make build Build all project services."
@echo " make test Run tests on all projects."
@echo " make clean Clean the directory tree of produced artifacts."
@echo " make lint Run static code analysis (lint)."
@echo " make format Run code formatter."
@echo " make checkEnvs Check if github hooks are installed and secret env on files are not exposed."
@echo " make auth Run a command inside the auth app in the components directory to see available commands."
@echo " make infra Run a command inside the infra app in the components directory to see available commands."
@echo " make ledger Run a command inside the ledger app in the components directory to see available commands."
@echo " make transaction Run a command inside the transaction app in the components directory to see available commands."
@echo " make audit Run a command inside the audit app in the components directory to see available commands."
@echo " make set-env Run a command to copy all .env.example to .env into respective folders."
@echo " make all-services Run a command to all services passing any individual container command."
@echo " make generate-docs-all Run a command to inside the ledger and transaction app to generate swagger docs."
@echo ""
@echo ""
@echo "$(BOLD)Service Commands:$(NC)"
@echo " make up - Start all services with Docker Compose"
@echo " make auth COMMAND=<cmd> - Run command in auth service"
@echo " make infra COMMAND=<cmd> - Run command in infra service"
@echo " make ledger COMMAND=<cmd> - Run command in ledger service"
@echo " make transaction COMMAND=<cmd> - Run command in transaction service"
@echo " make audit COMMAND=<cmd> - Run command in audit service"
@echo " make all-services COMMAND=<cmd> - Run command across all services"
@echo " make clean-docker - Run command to clean docker"
@echo ""
@echo ""
@echo "$(BOLD)Development Commands:$(NC)"
@echo " make tidy - Run go mod tidy"
@echo " make goreleaser - Create a release snapshot"
@echo ""
@echo ""
.PHONY: test
test:
@echo "$(BLUE)Running tests...$(NC)"
@if ! command -v go >/dev/null 2>&1; then \
echo "$(RED)Error: go is not installed$(NC)"; \
exit 1; \
fi
go test -v ./... ./...
.PHONY: cover
cover:
@echo -e "$(BLUE)Generating test coverage...$(NC)"
@if ! command -v go >/dev/null 2>&1; then \
echo "$(RED)Error: go is not installed$(NC)"; \
exit 1; \
fi
@sh ./scripts/coverage.sh
@go tool cover -html=coverage.out -o coverage.html
.PHONY: lint
lint:
@echo "$(BLUE)Running linter and performance checks...$(NC)"
./make.sh "lint"
.PHONY: format
format:
@echo "$(BLUE)Formatting Go code...$(NC)"
./make.sh "format"
.PHONY: check-logs
check-logs:
@echo "$(BLUE)Checking error logging in usecases...$(NC)"
./make.sh "checkLogs"
.PHONY: check-tests
check-tests:
@echo "$(BLUE)Verifying test coverage...$(NC)"
./make.sh "checkTests"
.PHONY: sec
sec:
@echo "$(BLUE)Running security checks...$(NC)"
@if ! command -v gosec >/dev/null 2>&1; then \
echo "$(RED)Error: gosec is not installed$(NC)"; \
echo "$(MAGENTA)To install: go install github.com/securego/gosec/v2/cmd/gosec@latest$(NC)"; \
exit 1; \
fi
gosec ./...
.PHONY: setup-git-hooks
setup-git-hooks:
@echo "$(BLUE)Setting up git hooks...$(NC)"
./make.sh "setupGitHooks"
.PHONY: check-hooks
check-hooks:
@echo "$(BLUE)Checking git hooks status...$(NC)"
./make.sh "checkHooks"
.PHONY: set-env
set-env:
@echo "$(BLUE)Setting up environment files...$(NC)"
cp -r $(AUTH_DIR)/.env.example $(AUTH_DIR)/.env
cp -r $(INFRA_DIR)/.env.example $(INFRA_DIR)/.env
cp -r $(LEDGER_DIR)/.env.example $(LEDGER_DIR)/.env
cp -r $(TRANSACTION_DIR)/.env.example $(TRANSACTION_DIR)/.env
cp -r $(MDZ_DIR)/.env.example $(MDZ_DIR)/.env
cp -r $(AUDIT_DIR)/.env.example $(AUDIT_DIR)/.env
@echo "$(BLUE)Environment files created successfully$(NC)"
.PHONY: up
up:
@echo "$(BLUE)Starting all services...$(NC)"
@$(DOCKER_CMD) -f $(AUTH_DIR)/docker-compose.yml up --build -d
@$(DOCKER_CMD) -f $(INFRA_DIR)/docker-compose.yml up --build -d
@$(DOCKER_CMD) -f $(LEDGER_DIR)/docker-compose.yml up --build -d
@$(DOCKER_CMD) -f $(TRANSACTION_DIR)/docker-compose.yml up --build -d
@echo "$(BLUE)All services started successfully$(NC)"
.PHONY: auth
auth:
@echo "$(BLUE)Executing command in auth service...$(NC)"
$(MAKE) -C $(AUTH_DIR) $(COMMAND)
.PHONY: infra
infra:
@echo "$(BLUE)Executing command in infra service...$(NC)"
$(MAKE) -C $(INFRA_DIR) $(COMMAND)
.PHONY: ledger
ledger:
@echo "$(BLUE)Executing command in ledger service...$(NC)"
$(MAKE) -C $(LEDGER_DIR) $(COMMAND)
.PHONY: transaction
transaction:
@echo "$(BLUE)Executing command in transaction service...$(NC)"
$(MAKE) -C $(TRANSACTION_DIR) $(COMMAND)
.PHONY: audit
audit:
@echo "$(BLUE)Executing command in audit service...$(NC)"
$(MAKE) -C $(AUDIT_DIR) $(COMMAND)
.PHONY: all-services
all-services:
@echo "$(BLUE)Executing command across all services...$(NC)"
$(MAKE) -C $(AUTH_DIR) $(COMMAND) && \
$(MAKE) -C $(INFRA_DIR) $(COMMAND) && \
$(MAKE) -C $(LEDGER_DIR) $(COMMAND) && \
$(MAKE) -C $(TRANSACTION_DIR) $(COMMAND) && \
$(MAKE) -C $(AUDIT_DIR) $(COMMAND)
.PHONY: clean-docker
clean-docker:
docker system prune -a -f && docker volume prune -a -f
.PHONY: test_integration_cli
test_integration_cli:
go test -v -tags=integration ./components/mdz/test/integration/...
.PHONY: goreleaser
goreleaser:
@echo "$(BLUE)Creating release snapshot...$(NC)"
goreleaser release --snapshot --skip-publish --rm-dist
.PHONY: tidy
tidy:
@echo "$(BLUE)Running go mod tidy...$(NC)"
go mod tidy
.PHONY: generate-docs-all
generate-docs-all:
@echo "$(BLUE)Executing command to generate swagger...$(NC)"
$(MAKE) -C $(LEDGER_DIR) generate-docs && \
$(MAKE) -C $(TRANSACTION_DIR) generate-docs && \
$(MAKE) -C $(AUDIT_DIR) generate-docs