-
Notifications
You must be signed in to change notification settings - Fork 1
/
Makefile
92 lines (67 loc) · 3.21 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
ifndef ${TAG}
TAG=$$(git rev-parse --short HEAD)
endif
packagesToTest=$$(go list ./... | grep -v generated)
setup:
go install github.com/go-swagger/go-swagger/cmd/[email protected]
go install entgo.io/ent/cmd/[email protected]
go install github.com/vektra/mockery/[email protected]
setup_alpine:
apk add --update --no-cache git build-base && rm -rf /var/cache/apk/*
run:
go run ./cmd/swagger/
clean/mocks:
find ./internal/generated/mocks/* -exec rm -rf {} \; || true
generate/mocks: clean/mocks
mockery --all --case snake --dir ./pkg/domain --output ./internal/generated/mocks
clean/swagger:
cd ./internal/generated/swagger && rm -rfv client models || true
rm -vf ./internal/generated/swagger/restapi/*.go
cd ./internal/generated/swagger/restapi/operations && find . ! -name 'gethandlers.go' -type f -exec rm -fv {} +
generate/swagger: clean/swagger
swagger generate server -P models.Principal -f ./swagger.yaml -s ./internal/generated/swagger/restapi -m ./internal/generated/swagger/models --exclude-main
swagger generate client -c ./internal/generated/swagger/client -f ./swagger.yaml -m ./internal/generated/swagger/models
clean/ent:
find ./internal/generated/ent/* ! -name "generate.go" -exec rm -rf {} \; || true
generate/ent: clean/ent
go run -mod=mod entgo.io/ent/cmd/ent generate --target ./internal/generated/ent ./internal/ent/schema
generate: generate/swagger generate/ent generate/mocks
clean: clean/swagger clean/ent
rm csr coverage.out report.txt
build:
CGO_ENABLED=0 go build -o csr ./cmd/swagger/...
lint:
golangci-lint run --out-format tab | tee ./report.txt
test:
go test ${packagesToTest} -race -coverprofile=coverage.out -short
coverage:
go tool cover -func=coverage.out
coverage_total:
go tool cover -func=coverage.out | tail -n1 | awk '{print $3}' | grep -Eo '[0-9]+(\.[0-9]+)?'
int-test:
DOCKER_BUILDKIT=1 docker build -f ./int-test-infra/Dockerfile.int-test --network host --no-cache -t csr:int-test --target run .
$(MAKE) int-infra-up
$(MAKE) int-test-without-infra
$(MAKE) int-infra-down
int-test-without-infra:
go test -v -p 1 -timeout 10m ./... -run Integration
build-int-image:
docker build -t csr:int-test -f ./int-test-infra/Dockerfile.int-test .
int-infra-up:
docker-compose -f ./int-test-infra/docker-compose.int-test.yml up -d --wait
int-infra-down:
docker-compose -f ./int-test-infra/docker-compose.int-test.yml down
db:
docker-compose -f ./docker-compose.yml up -d postgres
deploy_ssh:
ssh -o "StrictHostKeyChecking=no" -i ~/.ssh/ssh_deploy -p"${deploy_ssh_port}" "${deploy_ssh_user}@${deploy_ssh_host}" 'mkdir -p /var/www/csr/${env}/'
scp -o "StrictHostKeyChecking=no" -i ~/.ssh/ssh_deploy -P"${deploy_ssh_port}" -r ./csr "${deploy_ssh_user}@${deploy_ssh_host}:~/tmp_csr"
scp -o "StrictHostKeyChecking=no" -i ~/.ssh/ssh_deploy -P"${deploy_ssh_port}" -r ./config.json "${deploy_ssh_user}@${deploy_ssh_host}:/var/www/csr/${env}/"
ssh -o "StrictHostKeyChecking=no" -i ~/.ssh/ssh_deploy -p"${deploy_ssh_port}" "${deploy_ssh_user}@${deploy_ssh_host}" \
"sudo systemctl daemon-reload && sudo service ${env}.csr stop && cp ~/tmp_csr /var/www/csr/${env}/server && sudo service ${env}.csr start"
build_project:
docker-compose build csr
start_project:
docker-compose up -d
stop_project:
docker-compose down