forked from thorjealousy/midgard
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
123 lines (83 loc) · 2.96 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
include Makefile.cicd
all: lint install
GOBIN?=${GOPATH}/bin
API_REST_SPEC=./pkg/delivery/http/openapi-v1.0.0.yml
API_REST_CODE_GEN_LOCATION=./pkg/delivery/http/openapi-v1.0.0.go
API_REST_DOCO_GEN_LOCATION=./public/delivery/http/doc.html
bootstrap: node_modules ${GOPATH}/bin/oapi-codegen
.PHONY: config, tools, test
# cli tool for openapi
${GOPATH}/bin/oapi-codegen:
go install github.com/deepmap/oapi-codegen/cmd/oapi-codegen
# node_modules for API dev tools
node_modules:
yarn
install: bootstrap go.sum
GO111MODULE=on go install -v ./cmd/midgard
go.sum: go.mod
@echo "--> Ensure dependencies have not been modified"
GO111MODULE=on go mod verify
lint-pre:
@gofumpt -l $(shell find . -type f \( -iname "*.go" ! -iname "openapi-v1.0.0.go" \)) # for display
@test -z "$(shell gofumpt -l $(shell find . -type f \( -iname "*.go" ! -iname "openapi-v1.0.0.go" \)))" # cause error
@go mod verify
lint: lint-pre
@golangci-lint run
lint-verbose: lint-pre
@golangci-lint run -v
build: oapi-codegen-server doco
test-coverage:
@go test -mod=readonly -v -coverprofile .testCoverage.txt ./...
coverage-report: test-coverage
@tool cover -html=.testCoverage.txt
test-short:
@go test -short ./...
# require make pg
test-internal:
@go test -cover ./...
test:
@docker-compose run --rm testcode
test-watch: clear
@./scripts/watch.bash
sh:
@docker-compose run --rm midgard /bin/sh
thormock:
@docker-compose up -d thormock
pg:
@docker-compose up -d pg
stop:
@docker-compose stop
down:
@docker-compose down
# -------------------------------------------- API Targets ------------------------------------
# Open API Makefile targets
openapi3validate:
./node_modules/.bin/oas-validate -v ${API_REST_SPEC}
oapi-codegen-server: openapi3validate
@${GOBIN}/oapi-codegen --package=http --generate types,server,spec ${API_REST_SPEC} > ${API_REST_CODE_GEN_LOCATION}
doco:
./node_modules/.bin/redoc-cli bundle ${API_REST_SPEC} -o ${API_REST_DOCO_GEN_LOCATION}
# -----------------------------------------------------------------------------------------
dev:
go run cmd/midgard/main.go -c cmd/midgard/config.json
run-in-docker:
@${GOBIN}/midgard -c /etc/midgard/config.json
run:
@${GOBIN}/midgard -c cmd/midgard/config.json
run-thormock:
cd ./tools/mockServer && go run mockServer.go
run-thormock-with-smoke:
cd ./tools/mockServer && go run mockServer.go -s
up:
@docker-compose up --build
# ------------------------------------------- sql migrations ----------------------------------------------
${GOBIN}/sql-migrate:
go get -v github.com/rubenv/sql-migrate/...
create-user:
PGPASSWORD=password psql -h localhost -U postgres -c "CREATE USER midgard WITH CREATEDB CREATEROLE PASSWORD 'password';"
create-database:
PGPASSWORD=password psql -h localhost -U postgres -c "CREATE DATABASE midgard OWNER midgard;"
drop-database:
PGPASSWORD=password psql -h localhost -U postgres -c "drop database midgard;"
drop-user:
PGPASSWORD=password psql -h localhost -U postgres -c "DROP USER midgard"