-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
101 lines (77 loc) · 3.26 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
-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=verification
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 verification:'
@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 deploy-dev Deploy tagged image to staging'
@echo ' make deploy-prod Deploy tagged image to production'
@echo ' make clean Clean the directory tree.'
@echo
build: build-service
run: build
bin/verification
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/verification ./cmd/verification/
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}
deploy-dev: get-credentials-dev docker-build-dev push-dev
kubectl set image deployment/verification verification=gcr.io/gems-org/verification-dev:$(VERSION)
deploy-prod: get-credentials-prod docker-build-prod push-prod
kubectl set image deployment/verification verification=gcr.io/gems-org/verification:$(VERSION)
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 verification-migration migrations
run-migrations: build-migrations
docker run --network host verification-migration \
$(action) $(version) \
"mysql://$(VERIFICATION_DB_USER):$(VERIFICATION_DB_PASSWORD)@tcp($(VERIFICATION_DB_HOST):$(VERIFICATION_DB_PORT))/$(VERIFICATION_DB_NAME)"
migrate-latest: build-migrations
docker run --network host verification-migration \
goto $(LAST_MIGRATION) \
"mysql://$(VERIFICATION_DB_USER):$(VERIFICATION_DB_PASSWORD)@tcp($(VERIFICATION_DB_HOST):$(VERIFICATION_DB_PORT))/$(VERIFICATION_DB_NAME)"
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}"