-
Notifications
You must be signed in to change notification settings - Fork 94
/
Makefile
119 lines (93 loc) · 3.61 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
.PHONY: build image docker docker-centos clean
PACKAGES = $(shell go list ./... | grep -v vendor | grep -v integration-test)
PRJNAME := "swan"
Compose := "https://github.com/docker/compose/releases/download/1.14.0/docker-compose"
TmpDataDir := "/tmp/swan-tmp-data"
# Used to populate version variable in main package.
VERSION=$(shell git describe --always --tags --abbre=0)
BUILD_TIME=$(shell date -u +%Y-%m-%d:%H-%M-%S)
PKG := "github.com/Dataman-Cloud/swan"
gitCommit=$(shell git describe --tags --long)
gitDirty=$(shell git status --porcelain --untracked-files=no)
GIT_COMMIT=$(gitCommit)
ifneq ($(gitDirty),"")
GIT_COMMIT=$(gitCommit)-dirty
endif
GO_LDFLAGS=-X $(PKG)/version.version=$(VERSION) -X $(PKG)/version.gitCommit=$(GIT_COMMIT) -X $(PKG)/version.buildTime=$(BUILD_TIME) -w -s
UNAME=$(shell uname -s)
CGO_ENABLED=0
ifeq ($(UNAME),Darwin)
CGO_ENABLED=1
endif
default: build
build: clean
CGO_ENABLED=${CGO_ENABLED} go build -v -a -ldflags "${GO_LDFLAGS}" -o bin/swan main.go
# multi-stage builds, require docker >= 17.05
docker:
docker build --tag swan:$(shell git rev-parse --short HEAD) --rm .
# multi-stage builds, require docker >= 17.05
docker-centos:
docker build --tag swan:$(shell git rev-parse --short HEAD) --rm -f ./Dockerfile.centos .
# compitable for legacy docker version
docker-build:
docker run --name=buildswan --rm \
-w /go/src/github.com/Dataman-Cloud/swan \
-e CGO_ENABLED=0 -e GOOS=linux -e GOARCH=amd64 \
-v $(shell pwd):/go/src/github.com/Dataman-Cloud/swan \
golang:1.8.1-alpine \
sh -c 'go build -ldflags "${GO_LDFLAGS}" -v -o bin/swan main.go'
# compitable for legacy docker version
docker-image:
docker build --tag swan:$(shell git rev-parse --short HEAD) --rm -f ./Dockerfile.legacy .
docker tag swan:$(shell git rev-parse --short HEAD) swan:latest
prepare-docker-compose:
@if ! command -v docker-compose > /dev/null 2>&1; then \
echo "docker-compose downloading ..."; \
curl --progress-bar -L $(Compose)-$(shell uname -s)-$(shell uname -m) -o \
/usr/local/bin/docker-compose; \
chmod +x /usr/local/bin/docker-compose; \
echo "docker-compose downloaded!"; \
fi
build-binary:
@if env | grep -q -w "JENKINS_HOME" >/dev/null 2>&1; then \
$(MAKE) build; \
else \
$(MAKE) docker-build; \
fi
tmpdir:
mkdir -p $(TmpDataDir)
local-cluster: prepare-docker-compose build-binary docker-image tmpdir
docker-compose -p ${PRJNAME} up -d
docker-compose -p ${PRJNAME} ps
rm-local-cluster: prepare-docker-compose
docker-compose -p ${PRJNAME} stop
docker-compose -p ${PRJNAME} rm -f
rm -rf $(TmpDataDir)
check-local-cluster:
@./contrib/check-local-cluster.sh
integration-prepare: rm-local-cluster local-cluster check-local-cluster
integration-test: integration-prepare run-integration-test rm-local-cluster
run-integration-test:
docker run --name=testswan --rm \
-w /go/src/github.com/Dataman-Cloud/swan/integration-test \
-e SWAN_HOST=$(shell docker inspect -f "{{.NetworkSettings.IPAddress}}" ${PRJNAME}_swan-master_1):9999 \
-e "TESTON=" \
-v $(shell pwd):/go/src/github.com/Dataman-Cloud/swan \
golang:1.8.1-alpine \
sh -c 'go test -check.v -test.timeout=10m github.com/Dataman-Cloud/swan/integration-test'
clean:
rm -rfv bin/*
test:
go test -cover=true ${PACKAGES}
collect-cover-data:
@echo "mode: count" > coverage-all.out
$(foreach pkg,$(PACKAGES),\
go test -v -coverprofile=coverage.out -covermode=count $(pkg) || exit $?;\
if [ -f coverage.out ]; then\
tail -n +2 coverage.out >> coverage-all.out;\
fi\
;)
test-cover-html:
go tool cover -html=coverage-all.out -o coverage.html
test-cover-func:
go tool cover -func=coverage-all.out