-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
executable file
·126 lines (95 loc) · 3.87 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
124
125
126
GO = go
GO_BUILD = $(GO) build
GO_CLEAN = $(GO) clean
GO_TEST = $(GO) clean -testcache; $(GO) test
GO_GET = $(GO) get
SRC := $(shell find . -path "./\.*" -prune -type f -name '*.go')
TARGET = main
BUILDS = ./build
TESTS = ./pkg/...
BUILD := `git rev-parse HEAD`
MAJOR := $(shell cat .version | cut -d. -f1)
MINOR := $(shell cat .version | cut -d. -f2)
PATCH := $(shell cat .version | cut -d. -f3)
GOFLAGS = -v
GOTAGS = viper_bind_struct
LDFLAGS = -X=$(TARGET)/pkg/version.Build=$(BUILD) \
-X=$(TARGET)/pkg/version.Major=$(MAJOR) \
-X=$(TARGET)/pkg/version.Minor=$(MINOR) \
-X=$(TARGET)/pkg/version.Patch=$(PATCH) \
-X=$(TARGET)/pkg/version.String=${MAJOR}.${MINOR}.${PATCH}
RELEASEFLAGS := GOOS=linux GOARCH=amd64 CGO_ENABLED=0
CURRENT_UID := $(id -u)
.DEFAULT_GOAL := help
ifneq (,$(wildcard ./.env))
include .env
endif
ifdef ENV
ifneq (,$(wildcard ./.env-${ENV}))
include .env-${ENV}
endif
endif
ifndef CASSANDRA_CONNECTION_STRING
CASSANDRA_CONNECTION_STRING="cassandra://${CASSANDRA_HOSTS}:${CASSANDRA_CQL_PORT}/${CASSANDRA_KEYSPACE}"
endif
ifndef POSTGRES_CONNECTION_STRING
POSTGRES_CONNECTION_STRING="postgres://${POSTGRES_USER}:${POSTGRES_PASSWORD}@${POSTGRES_HOST}:${POSTGRES_PORT}/${POSTGRES_DB}?sslmode=disable"
endif
export
$(BUILDS)/$(TARGET): $(SRC)
@$(GO_BUILD) $(GOFLAGS) -ldflags="$(LDFLAGS)" -tags="$(GOTAGS)" -o $(BUILDS)/$(TARGET) .
@echo Binary "(v${MAJOR}.${MINOR}.${PATCH})" built to $(BUILDS)/$(TARGET)!
.PHONY: benchmark
benchmark: ## run benchmarks
@$(GO_TEST) -ldflags="$(LDFLAGS)" -tags="${GOTAGS}" -v -bench=. $(TESTS)
.PHONY: build
build: $(BUILDS)/$(TARGET) ## build for development
.PHONY: clean
clean: ## remove the build directory
@$(RM) -r $(BUILDS)
.PHONY: compose-up
compose-up: release
@docker-compose up --build --remove-orphans
.PHONY: compose-down
compose-down:
@docker-compose down
.PHONY: migrate-install
migrate-install:
@go install -tags 'cassandra postgres file' github.com/golang-migrate/migrate/v4/cmd/migrate@latest
.PHONY: cass-migrate-create
cass-migrate-create: migrate-install
@migrate create -ext cql -dir ./migrations/cassandra -seq $(n)
.PHONY: cass-migrate-down
cass-migrate-down: migrate-install
@migrate -database="${CASSANDRA_CONNECTION_STRING}" -path=./migrations/cassandra -lock-timeout=30 -verbose down 1
.PHONY: cass-migrate-force
cass-migrate-force: migrate-install
@migrate -database="${CASSANDRA_CONNECTION_STRING}" -path=./migrations/cassandra -lock-timeout=30 -verbose force ${v}
.PHONY: cass-migrate-up
cass-migrate-up: migrate-install
@migrate -database="${CASSANDRA_CONNECTION_STRING}" -path=./migrations/cassandra -lock-timeout=30 -verbose up
.PHONY: pg-migrate-create
pg-migrate-create: migrate-install
@migrate create -ext sql -dir ./migrations/postgres -seq $(n)
.PHONY: pg-migrate-down
pg-migrate-down: migrate-install
@migrate -database="${POSTGRES_CONNECTION_STRING}" -path=./migrations/postgres -lock-timeout=30 -verbose down 1
.PHONY: pg-migrate-force
pg-migrate-force: migrate-install
@migrate -database="${POSTGRES_CONNECTION_STRING}" -path=./migrations/postgres -lock-timeout=30 -verbose force ${v}
.PHONY: pg-migrate-up
pg-migrate-up: migrate-install
@migrate -database="${POSTGRES_CONNECTION_STRING}" -path=./migrations/postgres -lock-timeout=30 -verbose up
release:
@$(RELEASEFLAGS) $(GO_BUILD) $(GOFLAGS) -ldflags="$(LDFLAGS)" -o $(BUILDS)/release .
.PHONY: run
run: clean build ## run with .env
@$(BUILDS)/$(TARGET)
.PHONY: test
test: ## run tests
# @$(GO_TEST) -ldflags="$(LDFLAGS)" -tags="${GOTAGS}" -v $(TESTS)
# @$(GO_TEST) -ldflags="$(LDFLAGS)" -tags="${GOTAGS}" -v --run TestEventsRepo ./pkg/repos/events
# @$(GO_TEST) -ldflags="$(LDFLAGS)" -tags="${GOTAGS}" -v --run TestLoad ./pkg/env
.PHONY: help
help:
@grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | sort | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}'