-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
71 lines (52 loc) · 1.56 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
SOURCEDIR=.
SOURCES := $(shell find $(SOURCEDIR) -name '*.go')
APP_NAME=restapi
BINARY=$(APP_NAME)
VERSION=1.0.0
BUILD_TIME=`date +%FT%T%z`
VERSION := $(shell sh -c 'git describe --always --tags')
BRANCH := $(shell sh -c 'git rev-parse --abbrev-ref HEAD')
COMMIT := $(shell sh -c 'git rev-parse --short HEAD')
LDFLAGS=-ldflags "-s -X main.name=$(APP_NAME) -X main.version=$(VERSION) -X main.commit=$(COMMIT) -X main.branch=$(BRANCH) -X main.buildDate=$(BUILD_TIME)"
GO_META_LINTER=../../../../bin/gometalinter
.DEFAULT_GOAL: $(BINARY)
$(BINARY): $(SOURCES)
go build ${LDFLAGS} -o ${BINARY} main.go
$(SOURCES): install-deps
.PHONY: all
all: $(BINARY)
env GOOS=linux GOARCH=amd64 go build $(LDFLAGS) -o $(BINARY)-linux-amd64 main.go
env GOOS=darwin GOARCH=amd64 go build $(LDFLAGS) -o $(BINARY)-darwin-amd64 main.go
.PHONY: install
install:
go install ${LDFLAGS} ./...
.PHONY: docker
docker:
docker build -t dealako/restapi:$(COMMIT) .
.PHONY: docker-push
docker-push: docker
docker push dealako/restapi:$(COMMIT)
.PHONY: clean
clean:
rm -f ${BINARY}*
.PHONY: clean-all
clean-all: clean
rm -Rf vendor/
.PHONY: install-deps
install-deps: $(GO_META_LINTER)
dep ensure -vendor-only
$(GO_META_LINTER):
@echo "Downloading gometalinter..."
go get -u github.com/alecthomas/gometalinter
gometalinter --install
.PHONY: test
test:
go test -v ./...
.PHONY: analyze
analyze: install-deps
@echo "Analyzing code..."
-gometalinter --disable=gotype --enable=gofmt --enable=goimports --enable=unused --deadline=2m --vendor ./...
imports:
goimports -w *.go
fmt:
gofmt -w -s *.go