-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathMakefile
107 lines (90 loc) · 2.55 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
.PHONY: default all prepare build product clean
PWD=$(shell pwd)
PRJNAME := "puller"
ImgName := "bbklab/puller"
# Used to populate version variable in main package.
VERSION=$(shell cat VERSION.txt)
BUILD_TIME=$(shell date -u +%Y-%m-%d_%H:%M:%S_%Z)
PKG := "github.com/Dataman-Cloud/puller"
gopkgs=$(shell go list ./... | grep -v "integration-test")
gitCommit=$(shell git rev-parse --short HEAD)
gitDirty=$(shell git status --porcelain --untracked-files=no)
GIT_COMMIT=$(gitCommit)
ifneq ($(gitDirty),) # ---> gitDirty != ""
GIT_COMMIT=$(gitCommit)-dirty
endif
# FIXME deprecated
# BUILD_FLAGS=-X $(PKG)/version.version=$(VERSION) -X $(PKG)/version.gitCommit=$(GIT_COMMIT) -X $(PKG)/version.buildAt=$(BUILD_TIME) -w -s
default: binary
all: integration-test push
product: clean binary
prod: product
prepare:
mkdir -p bin/
mkdir -p product/
gocheck: gometalinter
# use gometalinter to replace all of above go linters
gometalinter:
docker run --name gocheck-puller --rm \
-v $(PWD):/go/src/${PKG}:ro \
bbklab/gometalinter:latest \
gometalinter --skip=integration-test --skip=vendor --skip=assets \
--deadline=120s \
--disable-all \
--enable=gofmt --enable=golint \
--enable=vet --enable=goconst \
/go/src/${PKG}/...
echo " --- Gometalinter Passed!"
binary: prepare
ifeq (${NOLINT},) # NOLINT == ""
@make gocheck
endif
ifeq (${ENV_CIRCLECI}, true)
@make host-build
else
@make docker-build
endif
product: image
image: binary
docker build --force-rm -t $(ImgName):$(gitCommit) -f Dockerfile .
docker tag $(ImgName):$(gitCommit) $(ImgName):latest
echo "Puller Image Built!"
push: product
docker push $(ImgName):$(gitCommit)
docker push $(ImgName):latest
echo "Product Pushed!"
#
# docker-build (build binary via docker container)
#
docker-build:
docker run --rm \
--name buildpuller \
-w /go/src/${PKG} \
-e CGO_ENABLED=0 \
-e GOOS=linux \
-v $(PWD):/go/src/${PKG}:rw \
golang:1.10-alpine \
sh -c 'go build -a -ldflags "${BUILD_FLAGS}" -o bin/puller ${PKG}/main/'
echo "Binary Built!"
#
# host-build (direct build binary by using system installed golang)
# mainly used for CI env
#
host-build:
env CGO_ENABLED=0 GOOS=linux go build -a -ldflags "${BUILD_FLAGS}" -o bin/puller ${PKG}/main/
echo "Binary Built!"
# update dep
# - HTTP[S]_PROXY: golang use proxy
# - ALL_PROXY: git use proxy
update-dep:
cd ${GOPATH}/src/$(PKG) && \
env \
HTTP_PROXY=socks5://127.0.0.1:1080 HTTPS_PROXY=socks5://127.0.0.1:1080 \
ALL_PROXY=socks5://127.0.0.1:1080 \
dep ensure -v
#
# clean up outdated
#
clean:
rm -fv bin/puller
rm -fv product/*