This repository has been archived by the owner on Jun 7, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Makefile
61 lines (50 loc) · 1.7 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
TAG_COMMIT := $(shell git rev-list --abbrev-commit --tags --max-count=1)
TAG := $(shell git describe --abbrev=0 --tags ${TAG_COMMIT} 2>/dev/null || true)
COMMIT := $(shell git rev-parse --short HEAD)
DATE := $(shell git log -1 --format=%cd --date=format:"%Y%m%d")
VERSION := $(TAG:v%=%)
ifneq ($(COMMIT), $(TAG_COMMIT))
VERSION := $(VERSION)-next-$(COMMIT)-$(DATE)
endif
ifeq ($(VERSION), )
VERSION := $(COMMIT)-$(DATA)
endif
ifneq ($(shell git status --porcelain),)
VERSION := $(VERSION)-dirty
endif
LDFLAGS := -ldflags "-X 'github.com/vulcanize/tracing-api/cmd.version=$(VERSION)'"
#Database
HOST_NAME = localhost
PORT = 5432
NAME = tracing_api
USER = postgres
CONNECT_STRING=postgresql://$(USER)@$(HOST_NAME):$(PORT)/$(NAME)?sslmode=disable
BIN = $(GOPATH)/bin
## Migration tool
GOOSE = $(BIN)/goose
$(BIN)/goose:
go get -u -d github.com/pressly/goose/cmd/goose
go build -tags='no_mysql no_sqlite' -o $(BIN)/goose github.com/pressly/goose/cmd/goose
## Apply all migrations not already run
migrate: $(GOOSE)
$(GOOSE) -table goose_db_version_trace -dir db/migrations postgres "$(CONNECT_STRING)" up
all: clean test linux darwin windows
clean:
if [ -d "build" ]; then rm -rf "build"; fi
test:
go vet ./...
go fmt ./...
go test ./pkg/...
linux:
if [ ! -d "build" ]; then mkdir "build"; fi
GOOS=linux GOARCH=amd64 go build ${LDFLAGS} -o build/tracer-linux
darwin:
if [ ! -d "build" ]; then mkdir "build"; fi
GOOS=darwin GOARCH=amd64 go build ${LDFLAGS} -o build/tracer-darwin
windows:
if [ ! -d "build" ]; then mkdir "build"; fi
GOOS=windows GOARCH=amd64 go build ${LDFLAGS} -o build/tracer-windows
## Build docker image
.PHONY: docker-build
docker-build:
docker build -t vulcanize/tracing-api -f Dockerfile .