-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
93 lines (71 loc) · 2.72 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
-include .env
LAST_MIGRATION = $(shell ls -tr migrations/sql/ | tail -n 1 | cut -d'_' -f1)
ifeq ($(LAST_MIGRATION),)
LAST_MIGRATION := 0
endif
.PHONY: default
BIN_NAME=dispute
VERSION ?= dev
GIT_COMMIT ?=$(shell git rev-parse HEAD)
SHORT_COMMIT ?=$(shell git rev-parse --short HEAD)
BUILD_DATE ?= $(shell date +%FT%T%z)
TIMESTAMP ?= $(shell date +%Y%m%d%H%M)
default: help
help:
@echo 'Management commands for dispute:'
@echo
@echo 'Usage:'
@echo ' make build Builds the binary locally.'
@echo ' make update-deps Runs dep ensure.'
@echo ' make package Build final docker image with just the go binary inside.'
@echo ' make add-migration Create a new migration file.'
@echo ' make build-migration Create a new migration file.'
@echo ' make run-migrations Run specific migration version and action.'
@echo ' make migrate-latest Runs latest migration.'
@echo ' make test Run tests on a compiled project.'
@echo ' make run Build and run'
@echo ' make up Start containers'
@echo ' make down Stop and delete containers'
@echo ' make clean Clean the directory tree.'
@echo
build: build-service
run: build
bin/dispute
build-service:
@echo "Building service"
mkdir -p ./bin
go build -ldflags "-w -X main.GitCommit=${GIT_COMMIT} -X main.Version=${VERSION} -X main.BuildDate=${BUILD_DATE}" -o ./bin/dispute ./cmd/dispute/
up:
docker-compose up --build
update-deps:
dep ensure -update
package: build-migrations
@echo "Building image ${BIN_NAME} ${VERSION} $(GIT_COMMIT)"
docker build --build-arg VERSION=${VERSION} --build-arg GIT_COMMIT=$(GIT_COMMIT) -t $(IMAGE_NAME):${VERSION} .
clean:
@test ! -e bin/${BIN_NAME} || rm bin/${BIN_NAME}
run-tests:
go test ./... -v -count=1
down:
docker-compose down
add-migration:
touch migrations/sql/$(shell expr $(LAST_MIGRATION) + 1 )_$(name).up.sql
touch migrations/sql/$(shell expr $(LAST_MIGRATION) + 1 )_$(name).down.sql
echo $(shell expr $(LAST_MIGRATION) + 1 ) > migrations/version
build-migrations:
docker build -t dispute-migration migrations
run-migrations: build-migrations
docker run --network host dispute-migration \
$(action) $(version) \
"mysql://$(DISPUTE_DB_USER):$(DISPUTE_DB_PASSWORD)@tcp($(DISPUTE_DB_HOST):$(DISPUTE_DB_PORT))/$(DISPUTE_DB)"
migrate-latest: build-migrations
docker run --network host dispute-migration \
goto $(LAST_MIGRATION) \
"mysql://$(DISPUTE_DB_USER):$(DISPUTE_DB_PASSWORD)@tcp($(DISPUTE_DB_HOST):$(DISPUTE_DB_PORT))/$(DISPUTE_DB)"
db-seed:
@echo "Seeding db"
mkdir -p ./bin
go build -o ./bin/dbseed ./pkg/database/dbseed
./bin/dbseed
tag-staging:
git tag -a staging-${SHORT_COMMIT} -m"staging release version ${SHORT_COMMIT}"