-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathMakefile
153 lines (113 loc) · 5.23 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
.PHONY: all clear run-linter run-tests build
all: run-linter run-tests build
LINTER_CFG = ./configs/.golangci.yml
PKG = ./internal/... ./pkg/...
PKG_INTERNAL = ./internal/...
PKG_LINTERS = ./...
MICROSERVICE_DIR=$(PWD)/internal
create-env:
go mod download
run-linter:
$(GOPATH)/bin/golangci-lint run $(PKG_LINTERS) --config=$(LINTER_CFG)
go fmt $(PKG)
build:
rm -f cmd/api/api_bin cmd/image/image_bin cmd/warehouse/warehouse_bin cmd/auth/auth_bin cmd/filldb/filldb_bin
go build cmd/api/main.go
mv main cmd/api/api_bin
go build cmd/image/main.go
mv main cmd/image/image_bin
go build cmd/warehouse/main.go
mv main cmd/warehouse/warehouse_bin
go build cmd/auth/main.go
mv main cmd/auth/auth_bin
go build cmd/filldb/main.go
mv main cmd/filldb/filldb_bin
run-tests:
go test -race $(PKG_INTERNAL) -cover -coverpkg $(PKG_INTERNAL)
get-stat-coverage:
go test -race -coverpkg=${PKG_INTERNAL} -coverprofile=c.out ${PKG_INTERNAL}
cat c.out | fgrep -v "easyjson" | fgrep -v "mock" | fgrep -v "dev" | fgrep -v "test.go" | fgrep -v "docs" | fgrep -v "testing.go" | fgrep -v ".pb.go" | fgrep -v "config" > c2.out
go tool cover -func=c2.out
go tool cover -html c2.out -o coverage.html
api-doc-generate:
swag init --parseDependency --parseInternal --parseDepth 1 -g ./cmd/api/main.go -o docs
# mocks, easyjson
generate:
go generate ${PKG}
proto-generate:
protoc --proto_path=${MICROSERVICE_DIR}/image/delivery/grpc/protobuf image.proto --go_out=plugins=grpc:${MICROSERVICE_DIR}/image/delivery/grpc/protobuf
protoc --proto_path=${MICROSERVICE_DIR}/warehouse/delivery/grpc/protobuf warehouse.proto --go_out=plugins=grpc:${MICROSERVICE_DIR}/warehouse/delivery/grpc/protobuf
protoc --proto_path=${MICROSERVICE_DIR}/auth/delivery/grpc/protobuf auth.proto --go_out=plugins=grpc:${MICROSERVICE_DIR}/auth/delivery/grpc/protobuf
# S3
IMAGES = /home/webapps/images
S3_ENDPOINT = http://localhost:4566
# Example: make fill-S3-slow IMAGES=/home/webapps/images S3_ENDPOINT=http://localhost:4566
fill-S3-slow:
./scripts/fill_data_S3.sh ${IMAGES} ${S3_ENDPOINT}
fill-S3-fast:
./scripts/fill_data_S3_fast.sh ${IMAGES} ${S3_ENDPOINT}
# Migrations
MIGRATIONS_DIR = scripts/migrations
DB_URL := $(shell echo postgresql://${POSTGRES_USER}:${POSTGRES_PASSWORD}@${POSTGRES_HOST}:${POSTGRES_PORT}/${POSTGRES_DB}?sslmode=${POSTGRES_SSLMODE})
fill-db: export POSTGRES_HOST=localhost
fill-db:
./cmd/filldb/filldb_bin --config-path=./cmd/filldb/configs/prod.toml --data-path=./test/newdata
# Production BEGIN ----------------------------------------------------
prod-create-env:
sudo cp /etc/letsencrypt/live/movie-gate.ru/fullchain.pem ./cmd/api/
sudo cp /etc/letsencrypt/live/movie-gate.ru/privkey.pem ./cmd/api/
prod-restart:
docker-compose -f docker-compose.production.yml restart warehouse
docker-compose -f docker-compose.production.yml restart image
docker-compose -f docker-compose.production.yml restart auth
docker-compose -f docker-compose.production.yml restart api
prod-deploy:
mkdir -p --mode=777 logs/database/main
make prod-create-env
docker-compose -f docker-compose.production.yml up -d main_db admin_db localstack
sleep 5
make fill-db
docker-compose -f docker-compose.production.yml up -d image warehouse auth api
docker-compose -f docker-compose.production.yml up -d monitor_db prometheus node_exporter grafana
sleep 5
make fill-S3-slow IMAGES=/home/webapps/images S3_ENDPOINT=http://localhost:4566
# Production END ------------------------------------------------------
stop:
docker-compose kill
docker-compose down
# Debug BEGIN ---------------------------------------------------------
#IMAGES=/home/andeo/Загрузки/images S3_ENDPOINT=http://localhost:4566
debug-fill-db: export POSTGRES_HOST=localhost
debug-fill-db:
./cmd/filldb/filldb_bin --config-path=./cmd/filldb/configs/debug.toml --data-path=./test/newdata
debug-base-deploy:
docker-compose up -d main_db admin_db localstack
debug-app-deploy:
docker-compose up -d image warehouse auth api
debug-monitoring-deploy:
docker-compose up -d monitor_db prometheus node_exporter grafana
debug-deploy:
make clear
mkdir -p --mode=777 logs/database/main
make debug-base-deploy
sleep 1
make build
make debug-app-deploy
make debug-monitoring-deploy
debug-app-restart:
docker-compose restart warehouse
docker-compose restart image
docker-compose restart auth
docker-compose restart api
run-perf-tests:
go run ./perf_test/perftest.go
# Debug END -----------------------------------------------------------
send-bin:
scp ./cmd/filldb/filldb_bin root@95.163.242.214:/home/webapps/movie-gate.ru/backend/2022_2_BugOverload/cmd/filldb/filldb_bin
scp ./cmd/api/api_bin root@95.163.242.214:/home/webapps/movie-gate.ru/backend/2022_2_BugOverload/cmd/api/api_bin
scp ./cmd/image/image_bin root@95.163.242.214:/home/webapps/movie-gate.ru/backend/2022_2_BugOverload/cmd/image/image_bin
scp ./cmd/warehouse/warehouse_bin root@95.163.242.214:/home/webapps/movie-gate.ru/backend/2022_2_BugOverload/cmd/warehouse/warehouse_bin
scp ./cmd/auth/auth_bin root@95.163.242.214:/home/webapps/movie-gate.ru/backend/2022_2_BugOverload/cmd/auth/auth_bin
# Debug END -----------------------------------------------------------
clear:
sudo rm -rf main coverage.html coverage.out c.out *.log logs/ c2.out fullchain.pem privkey.pem cmd/*/*_bin