-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
158 lines (120 loc) · 3.73 KB
/
Makefile
File metadata and controls
158 lines (120 loc) · 3.73 KB
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
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
PACKAGE := github.com/modcloth/tory
SUBPACKAGES := $(PACKAGE)/tory
COVERPROFILES := \
main.coverprofile \
tory.coverprofile
VERSION_VAR := $(PACKAGE)/tory.VersionString
VERSION_VALUE := $(shell git describe --always --dirty --tags)
REV_VAR := $(PACKAGE)/tory.RevisionString
REV_VALUE := $(shell git rev-parse --sq HEAD)
BRANCH_VAR := $(PACKAGE)/tory.BranchString
BRANCH_VALUE := $(shell git rev-parse --abbrev-ref HEAD)
GENERATED_VAR := $(PACKAGE)/tory.GeneratedString
GENERATED_VALUE := $(shell date -u +%Y-%m-%dT%H:%M:%SZ)
DOCKER_TAG ?= quay.io/modcloth/tory:latest
DATABASE_URL ?= postgres://$(shell whoami)@localhost/tory?sslmode=disable
PORT ?= 9462
DOCKER ?= docker
GO ?= go
GOX ?= gox
DEPPY ?= deppy
GO_BINDATA ?= go-bindata
GOPATH := $(shell echo "$${GOPATH%%:*}")
ifeq ($(shell uname),Darwin)
SHA256SUM ?= gsha256sum
else
SHA256SUM ?= sha256sum
endif
GOBUILD_LDFLAGS := -ldflags "\
-X $(VERSION_VAR) $(VERSION_VALUE) \
-X $(REV_VAR) $(REV_VALUE) \
-X $(BRANCH_VAR) $(BRANCH_VALUE) \
-X $(GENERATED_VAR) $(GENERATED_VALUE) \
-w -s"
GOBUILD_FLAGS ?= -tags 'netgo'
GOTEST_FLAGS ?=
GOX_OSARCH ?= linux/amd64 darwin/amd64 windows/amd64
GOX_FLAGS ?= \
-output="tory-{{.OS}}-{{.Arch}}/bin/{{.Dir}}" \
-osarch="$(GOX_OSARCH)"
CROSS_TARBALLS := \
tory-linux-amd64.tar.bz2 \
tory-darwin-amd64.tar.bz2 \
tory-windows-amd64.tar.bz2
ALLFILES := $(shell git ls-files)
CGO_ENABLED ?= 0
QUIET ?=
VERBOSE ?=
export CGO_ENABLED
export QUIET
export VERBOSE
export GOPATH
export DATABASE_URL
.PHONY: all
all: clean build migrate test save
.PHONY: build
build: deps .build
.PHONY: .build
.build:
$(DEPPY) $(GO) install -a $(GOBUILD_FLAGS) $(GOBUILD_LDFLAGS) $(PACKAGE) $(SUBPACKAGES)
.PHONY: deps
deps: tory/bindata.go
tory/bindata.go: .go-bindata-bootstrap $(wildcard public/*)
$(GO_BINDATA) -prefix=public -o=$@ -pkg=tory ./public
.go-bindata-bootstrap:
$(GO) get -x $(GOBUILD_FLAGS) github.com/jteeuwen/go-bindata/go-bindata > $@
.PHONY: crossbuild
crossbuild: deps .gox-bootstrap
$(GOX) $(GOX_FLAGS) $(GOBUILD_LDFLAGS) $(PACKAGE) $(SUBPACKAGES)
.PHONY: crosstars
crosstars: $(CROSS_TARBALLS) SHA256SUMS
SHA256SUMS: $(CROSS_TARBALLS)
$(SHA256SUM) $(CROSS_TARBALLS) > $@
tory-linux-amd64.tar.bz2: crossbuild
tar -cjvf $@ tory-linux-amd64
tory-darwin-amd64.tar.bz2: crossbuild
tar -cjvf $@ tory-darwin-amd64
tory-windows-amd64.tar.bz2: crossbuild
tar -cjvf $@ tory-windows-amd64
.gox-bootstrap:
$(GOX) -build-toolchain -osarch="$(GOX_OSARCH)" -verbose 2>&1 | tee $@
.PHONY: test
test: build test-deps .test
.PHONY: .test
.test: coverage.html
coverage.html: all.coverprofile
$(DEPPY) $(GO) tool cover -func=$<
$(DEPPY) $(GO) tool cover -html=$< -o $@
all.coverprofile: $(COVERPROFILES)
echo 'mode: count' > $@
grep -h -v 'mode: count' $^ >> $@
main.coverprofile:
$(DEPPY) $(GO) test $(GOTEST_FLAGS) $(GOBUILD_LDFLAGS) \
-coverprofile=$@ -covermode=count $(PACKAGE)
tory.coverprofile:
$(DEPPY) $(GO) test $(GOTEST_FLAGS) $(GOBUILD_LDFLAGS) \
-coverprofile=$@ -covermode=count github.com/modcloth/tory/tory
.PHONY: migrate
migrate: build
$(GOPATH)/bin/tory migrate -d $(DATABASE_URL)
.PHONY: test-deps
test-deps:
$(DEPPY) $(GO) test -i $(GOTEST_FLAGS) $(GOBUILD_LDFLAGS) $(PACKAGE) $(SUBPACKAGES)
.PHONY: clean
clean:
$(RM) -r .coverage .*-bootstrap .cache/ $(shell find . -name '*.pyc')
$(RM) $(GOPATH)/bin/tory *.coverprofile coverage.html
$(RM) -r tory-*-amd64*
$(DEPPY) $(GO) clean -x $(PACKAGE) $(SUBPACKAGES)
.PHONY: distclean
distclean: clean
$(RM) .gox-bootstrap .go-bindata-bootstrap
.PHONY: save
save:
$(DEPPY) save $(PACKAGE) $(SUBPACKAGES)
.PHONY: build-container
build-container:
$(DOCKER) build -t $(DOCKER_TAG) .
.PHONY: run-container
run-container:
$(DOCKER) run -p $(PORT):$(PORT) -e DATABASE_URL=$(DATABASE_URL) $(DOCKER_TAG)