-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
102 lines (80 loc) · 3.89 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
GIT_COMMIT:=$(shell git rev-parse HEAD || echo '?')
GIT_TREE:=$(shell git diff-index --quiet HEAD -- && echo clean || echo dirty)
GIT_VERSION:=$(shell git describe --tags --dirty --match 'v*' 2> /dev/null || echo dev-$(shell date -u +"%Y%m%d%H%M%S"))
DB_VERSION:=$(shell ls -1 db/migrations | tail -n 1 | cut -b 1-14)
BUILD_DATE:=$(shell date -u +"%Y-%m-%dT%H:%M:%SZ")
LD_FLAGS = -X github.com/andrewbenington/queue-share-api/version.Commit=${GIT_COMMIT} \
-X github.com/andrewbenington/queue-share-api/version.Date=${BUILD_DATE} \
-X github.com/andrewbenington/queue-share-api/version.Tag=${GIT_VERSION} \
-X github.com/andrewbenington/queue-share-api/version.Tree=${GIT_TREE} \
-X github.com/andrewbenington/queue-share-api/version.Database=${DB_VERSION}
.PHONY: reset-db
reset-db:
@psql -d postgres -f db/init.sql -v "ON_ERROR_STOP=1"
@psql -d queue_share -f db/schema.sql
@psql -d queue_share -f db/post-create.sql
@psql -d queue_share -c 'INSERT INTO schema_migrations(version, dirty) VALUES (${DB_VERSION}, false)'
.PHONY: start
start:
@go run ./cmd/main.go
.PHONY: build
build:
go build -ldflags '-s -w -extldflags "-static" ${LD_FLAGS}' -o bin/queue-share ./cmd/main.go
.PHONY: build-linux
build-linux:
GOOS=linux GOARCH=amd64 go build -ldflags '${LD_FLAGS}' -o bin/queue-share ./cmd/main.go
.PHONY: build-pi
build-pi:
GOOS=linux GOARCH=arm64 go build -ldflags '${LD_FLAGS}' -o bin/queue-share ./cmd/main.go
.PHONY: docker-build
docker-build: build-pi
@docker build -t andrewb57/queue-share-api:latest .
@docker build -t andrewb57/queue-share-api:${GIT_VERSION} .
.PHONY: docker-push
docker-push:
@docker push andrewb57/queue-share-api:latest
@docker push andrewb57/queue-share-api:${GIT_VERSION}
.PHONY: migrate-up
migrate-up:
@migrate -path db/migrations -database 'postgres://postgres:postgres@localhost:5432/queue_share?sslmode=disable' up 1
.PHONY: migrate-down
migrate-down:
@migrate -path db/migrations -database 'postgres://queue_share:$(shell printf '%s' "$(POSTGRES_PASS)" | jq -sRr @uri)@${POSTGRES_HOST}:5432/queue_share?sslmode=disable' down 1
.PHONY: migrate-force
migrate-force:
@migrate -path db/migrations -database 'postgres://postgres:postgres@localhost:5432/queue_share?sslmode=disable' force ${VERSION}
.PHONY: migrate-force-latest
migrate-force-latest:
@migrate -path db/migrations -database 'postgres://postgres:postgres@localhost:5432/queue_share?sslmode=disable' force ${DB_VERSION}
.PHONY: migrate-version
migrate-version:
@migrate -path db/migrations -database 'postgres://postgres:postgres@localhost:5432/queue_share?sslmode=disable' version
.PHONY: migrate-down-prod
migrate-down-prod:
@migrate -path db/migrations -database 'postgres://queue_share:$(shell printf '%s' "$(POSTGRES_PASS)" | jq -sRr @uri)@${POSTGRES_HOST}:5432/queue_share?sslmode=disable' down 1
.PHONY: migrate-up-prod
migrate-up-prod:
@migrate -path db/migrations -database 'postgres://queue_share:$(shell printf '%s' "$(POSTGRES_PASS)" | jq -sRr @uri)@${POSTGRES_HOST}:5432/queue_share?sslmode=disable' up 1
.PHONY: migrate-force-prod
migrate-force-prod:
@migrate -path db/migrations -database 'postgres://queue_share:$(shell printf '%s' "$(POSTGRES_PASS)" | jq -sRr @uri)@${POSTGRES_HOST}:5432/queue_share?sslmode=disable' force ${DB_VERSION}
.PHONY: schema
schema:
@echo "-- Generated by make schema." > db/schema.sql
@PGPASSWORD=${POSTGRES_PASS} pg_dump -d queue_share -U queue_share -h ${POSTGRES_HOST} --schema-only >> db/schema.sql
@sqlc generate
.PHONY: sqlc
sqlc:
@sqlc generate
.PHONY: docker-build-db
docker-build-db:
@docker build -t andrewb57/queue-share-api:latest ./db
.PHONY: docker-run-db
docker-run-db:
@docker run --name qsd -e POSTGRES_PASSWORD=password -d -p 5431:5432 andrewb57/queue-share-api:latest
.PHONY: docker-save
docker-save:
@docker save -o api-image.tar andrewb57/queue-share-api:latest
.PHONY: docker-save-db
docker-save-db:
@docker save -o db-image.tar andrewb57/queue-share-api:latest