-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
69 lines (63 loc) · 1.94 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
include .envrc
current_time := $(shell date --iso-8601=seconds)
apiVersion := $(shell git describe --always --dirty --tags --long)
## help: print hist help message
.PHONY: help
help:
@echo 'Usage'
@sed -n 's/^##//p' ${MAKEFILE_LIST} | column -t -s ':' | sed -e 's/^/ /'
.PHONY: confirm
confirm:
@echo -n 'Are you sure? [y/N] ' && read ans && [ $${ans:-N} = y ]
## api/version: display API version
api/version:
./bin/api -version
## api/build: build api cmd binaries
api/build:
@echo 'Building ./cmd/api'
GOOS=linux GOARCH=amd64 go build -ldflags='-s -X main.buildTime=${current_time} -X main.version=${apiVersion}' -o=./bin/api ./cmd/api
## api/run: run the cmd/api application
.PHONY: app/run
api/run:
go run ./cmd/api/
## db/start: start pg docker image
.PHONY: db/start
db/start:
docker stop postgres || true
docker rm postgres || true
docker run -d \
--name postgres \
-p 5432:5432 \
-v pg-data:/var/lib/postgresql/data \
-v "${PWD}/init.sql":/docker-entrypoint-initdb.d/init.sql \
-e POSTGRES_PASSWORD=satoru \
-e POSTGRES_USER=satoru \
-e POSTGRES_DATABASE=satoru \
postgres:14.1-alpine3.15
## db/migration/create name=$1: create a new database migration
.PHONY: db/migration/create
db/migration/create: confirm
echo ${name}
migrate create -seq -ext=.sql -dir=./migrations ${name}
## db/migration/up: apply all up database migrations
.PHONY: db/migration/run
db/migration/run:
migrate -path=./migrations -database="$(DSN)" up
## qc/audit: Quality control, execute code formtat, vetting and static check
.PHONY: qc/audit
qc/audit: qc/vendor
@echo 'Formatting code'
go fmt ./...
@echo 'Vetting code'
go vet ./...
staticcheck ./...
@echo 'Running tests...'
go test -race -vet=off ./...
## qc/vendor: vendoring third-party packages (storing locally) and normalizing packages
.PHONY: qc/vendor
qc/vendor:
@echo 'Tidying and verifying module dependencies'
go mod tidy
go mod verify
@echo 'Vendoring third-party packages'
go mod vendor