-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathMakefile_old
executable file
·194 lines (150 loc) · 7.12 KB
/
Makefile_old
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
.PHONY: all clear generate-api-doc check launch build run-tests migrate-debug-up DB_URL
all: check build run-tests
LINTERS_CONFIG = ./configs/.golangci.yml
PKG = ./internal/... ./pkg/...
PKG_INTERNAL = ./internal/...
SERVICE_DEV = dev
пох
MICROSERVICE_DIR=$(PWD)/internal
# ENV
create-env-lint:
go get github.com/golangci/golangci-lint/cmd/golangci-lint@v1.49.0
go install github.com/golangci/golangci-lint/cmd/golangci-lint@v1.49.0
${GOPATH}/bin/golangci-lint
migrate-install:
curl -L https://github.com/golang-migrate/migrate/releases/download/v4.15.2/migrate.linux-amd64.tar.gz | tar xvz
sudo mv migrate /binЫ
rm README.md LICENSE
env:
export AWS_REGION=us-east-1 && export AWS_PROFILE=default && export AWS_ACCESS_KEY_ID=foo && export AWS_SECRET_ACCESS_KEY=bar &&
export POSTGRES_HOST=main_db && export POSTGRES_DB=mgdb &&
export POSTGRES_USER=mguser && export POSTGRES_PASSWORD=mgpass &&
export POSTGRES_USER_APP=user_app && export POSTGRES_PASSWORD_USER_APP=pass_microservice_2022_user &&
export POSTGRES_AUTH_APP=auth_app && export POSTGRES_PASSWORD_AUTH_APP=pass_microservice_2022_auth &&
export POSTGRES_WAREHOUSE_APP=warehouse_app && export POSTGRES_PASSWORD_WAREHOUSE_APP=pass_microservice_2022_warehouse &&
export POSTGRES_IMAGE_APP=image_app && export POSTGRES_PASSWORD_IMAGE_APP=pass_microservice_2022_image &&
export POSTGRES_PORT=5432 && export POSTGRES_SSLMODE=disable && export POSTGRES_HOST_DEV=localhost &&
export GF_SECURITY_ADMIN_USER=mguser && export GF_SECURITY_ADMIN_PASSWORD=mgpass &&
export GRAFANA_URL=grafana && export PROMETHEUS_URL=http://localhost:9999/prometheus/ && export TARGET_MONITOR=etwcwvloiuygotvk
# Development -------------------------------------
check:
${GOPATH}/bin/golangci-lint run ${PKG} --config=${LINTERS_CONFIG}
go fmt ${PKG}
image-service-launch:
go run ./cmd/image/main.go --config-path=./cmd/image/configs/debug.toml
build:
rm -f cmd/api/api_bin cmd/image/image_bin cmd/warehouse/warehouse_bin cmd/auth/auth_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
run-all-tests:
go test -race ${PKG_INTERNAL} -cover -coverpkg ${PKG_INTERNAL}
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-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
# Example: make fill-S3 IMAGES=/home/andeo/Загрузки/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}
dev-fill-db:
go run ./cmd/filldb/main.go --config-path=./cmd/filldb/configs/debug.toml --data-path=./test/newdata
# Migrations
MIGRATIONS_DIR = scripts/migrations
DB_URL := $(shell echo postgresql://$(POSTGRES_USER):$(POSTGRES_PASSWORD)@$(POSTGRES_HOST):$(POSTGRES_PORT)/$(POSTGRES_DB)?sslmode=$(POSTGRES_SSLMODE))
migrate-up:
migrate -source file://${MIGRATIONS_DIR} -database ${DB_URL} up ${COUNT}
migrate-down:
migrate -source file://${MIGRATIONS_DIR} -database ${DB_URL} down ${COUNT}
migrate-force:
migrate -source file://${MIGRATIONS_DIR} -database ${DB_URL} force ${COUNT}
reboot-db:
echo 'y' | migrate -source file://${MIGRATIONS_DIR}/down -database ${DB_URL} down
migrate -source file://${MIGRATIONS_DIR}/up -database ${DB_URL} up ${COUNT}
make dev-fill-db
# Development -------------------------------------
# Launch App System -------------------------------------
debug-mode:
go run ./cmd/api/main.go --config-path=./cmd/api/configs/debug.toml
prod-mode:
go run ./cmd/api/main.go --config-path=./cmd/api/configs/prod.toml
# Launch App System -------------------------------------
# infrastructure
# Example: make prod-deploy IMAGES=/home/andeo/Загрузки/images S3_ENDPOINT=http://localhost:4566
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/
# Example: make prod-deploy IMAGES=/home/webapps/images S3_ENDPOINT=http://localhost:4566
prod-deploy:
make clear
make prod-create-env
docker-compose -f docker-compose.yml -f docker-compose.production.yml up -d main_db admin_db localstack
sleep 2
make reboot-db-full
make infro-build
docker-compose -f docker-compose.yml -f docker-compose.production.yml up -d image warehouse auth api
docker-compose -f docker-compose.yml -f docker-compose.production.yml up -d monitor_db alertmanager prometheus node_exporter grafana
make fill-S3-slow ${IMAGES} ${S3_ENDPOINT}
debug-deploy:
make clear
docker-compose up -d main_db admin_db localstack
sleep 1
make reboot-db-full
make infro-build
docker-compose up -d image warehouse auth api
docker-compose up -d monitor_db alertmanager prometheus node_exporter grafana
make fill-S3-fast ${IMAGES} ${S3_ENDPOINT}
stop:
docker-compose kill
docker-compose down
reboot-db-debug:
docker-compose run --rm $(SERVICE_DEV) make -C project reboot-db COUNT=3
reboot-db-full:
docker-compose run --rm $(SERVICE_DEV) make -C project reboot-db
infro-build:
docker-compose run --rm $(SERVICE_DEV) make -C project build
debug-restart:
docker-compose restart arehouse
docker-compose restart image
docker-compose restart auth
docker-compose restart api
build-debug-restart:
make infro-build
make debug-restart
prod-restart:
make prod-create-env
docker-compose -f docker-compose.yml -f docker-compose.production.yml up -d --no-recreate warehouse
docker-compose -f docker-compose.yml -f docker-compose.production.yml up -d --no-recreate imagee
docker-compose -f docker-compose.yml -f docker-compose.production.yml up -d --no-recreate auth
docker-compose -f docker-compose.yml -f docker-compose.production.yml up -d --no-recreate api
build-prod-restart:
make infro-build
make prod-restart
# Example: make infro-command COMMAND=run-all-tests
infro-command:
docker-compose run --rm $(SERVICE_DEV) make -C project ${COMMAND}
# Utils
clear:
sudo rm -rf main coverage.html coverage.out c.out *.log logs/ c2.out fullchain.pem privkey.pem cmd/*/*_bin
open-last-log:
./scripts/print_last_log.sh
# Example: make set-format TARGET=/home/andeo/Загрузки/images FORMAT=jpeg
set-format:
./scripts/set_format.sh ${TARGET} ${FORMAT}