forked from appleboy/gorush
/
Makefile
146 lines (111 loc) · 3.45 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
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
.PHONY: all test build fmt vet errcheck lint install update release-dirs release-build release-copy release-check release
export PROJECT_PATH = /go/src/github.com/appleboy/gorush
DIST := dist
EXECUTABLE := gorush
BUILD_IMAGE := "gorush-build"
DEPLOY_ACCOUNT := appleboy
DEPLOY_IMAGE := $(EXECUTABLE)
TARGETS ?= linux/*,darwin/*
PACKAGES ?= $(shell go list ./... | grep -v /vendor/)
SOURCES ?= $(shell find . -name "*.go" -type f)
TAGS ?=
LDFLAGS += -X 'main.Version=$(VERSION)'
ifneq ($(shell uname), Darwin)
EXTLDFLAGS = -extldflags "-static" $(null)
else
EXTLDFLAGS =
endif
ifneq ($(DRONE_TAG),)
VERSION ?= $(DRONE_TAG)
else
ifneq ($(DRONE_BRANCH),)
VERSION ?= $(DRONE_BRANCH)
else
VERSION ?= $(shell git describe --tags --always || git rev-parse --short HEAD)
endif
endif
all: build
init:
ifeq ($(ANDROID_API_KEY),)
@echo "Missing ANDROID_API_KEY Parameter"
@exit 1
endif
ifeq ($(ANDROID_TEST_TOKEN),)
@echo "Missing ANDROID_TEST_TOKEN Parameter"
@exit 1
endif
@echo "Already set ANDROID_API_KEY and ANDROID_TEST_TOKEN globale variable."
fmt:
go fmt $(PACKAGES)
vet:
go vet $(PACKAGES)
errcheck:
@which errcheck > /dev/null; if [ $$? -ne 0 ]; then \
go get -u github.com/kisielk/errcheck; \
fi
errcheck $(PACKAGES)
lint:
@which golint > /dev/null; if [ $$? -ne 0 ]; then \
go get -u github.com/golang/lint/golint; \
fi
for PKG in $(PACKAGES); do golint -set_exit_status $$PKG || exit 1; done;
dep_install:
glide install
dep_update:
glide up
install: $(wildcard *.go)
go install -v -tags '$(TAGS)' -ldflags '$(EXTLDFLAGS)-s -w $(LDFLAGS)'
build: $(EXECUTABLE)
$(EXECUTABLE): $(SOURCES)
go build -v -tags '$(TAGS)' -ldflags '$(EXTLDFLAGS)-s -w $(LDFLAGS)' -o bin/$@
corss_build: clean
sh script/build.sh $(VERSION)
test:
for PKG in $(PACKAGES); do go test -v -cover -coverprofile $$GOPATH/src/$$PKG/coverage.txt $$PKG || exit 1; done;
redis_test: init
go test -v -cover ./storage/redis/...
boltdb_test: init
go test -v -cover ./storage/boltdb/...
memory_test: init
go test -v -cover ./storage/memory/...
buntdb_test: init
go test -v -cover ./storage/buntdb/...
leveldb_test: init
go test -v -cover ./storage/leveldb/...
config_test: init
go test -v -cover ./config/...
html:
go tool cover -html=.cover/coverage.txt
docker_binary_build:
CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -a -tags '$(TAGS)' -ldflags '$(EXTLDFLAGS)-s -w $(LDFLAGS)' -o bin/$@
docker_image:
docker build -t $(DEPLOY_ACCOUNT)/$(DEPLOY_IMAGE) -f Dockerfile .
docker_release: docker_binary_build docker_image
docker_build:
tar -zcvf build.tar.gz gorush.go gorush config storage Makefile glide.lock glide.yaml
sed -e "s/#VERSION#/$(VERSION)/g" docker/Dockerfile.build > docker/Dockerfile.tmp
docker build -t $(BUILD_IMAGE) -f docker/Dockerfile.tmp .
docker run --rm $(BUILD_IMAGE) > gorush.tar.gz
docker_production:
docker build -t $(EXECUTABLE) -f docker/Dockerfile.dist .
docker_deploy:
ifeq ($(tag),)
@echo "Usage: make $@ tag=<tag>"
@exit 1
endif
docker tag $(EXECUTABLE):latest $(DEPLOY_ACCOUNT)/$(EXECUTABLE):$(tag)
docker push $(DEPLOY_ACCOUNT)/$(EXECUTABLE):$(tag)
docker_test: init clean
docker-compose -p ${EXECUTABLE} -f docker/docker-compose.testing.yml run gorush
docker-compose -p ${EXECUTABLE} -f docker/docker-compose.testing.yml down
clean:
go clean -x -i ./...
find . -name coverage.txt -delete
-rm -rf build.tar.gz \
gorush.tar.gz bin/* \
gorush.tar.gz \
gorush/gorush.db \
storage/boltdb/gorush.db \
.cover
version:
@echo $(VERSION)