forked from redspread/spread
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
112 lines (85 loc) · 2.42 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
BASE := rsprd.com/spread
CMD_NAME := spread
EXEC_PKG := $(BASE)/cmd/$(CMD_NAME)
PKGS := ./pkg/... ./cli/... ./cmd/...
GOX_OS ?= linux darwin windows
GOX_ARCH ?= amd64
GO ?= go
GOX ?= gox
GOFMT ?= gofmt # eventually should add "-s"
GOLINT ?= golint
DOCKER ?= docker
GOFILES := find . -name '*.go' -not -path "./vendor/*"
GOBUILD_LDFLAGS ?=
GOBUILD_FLAGS ?= -i -v
GOTEST_FLAGS ?= -v
GOX_FLAGS ?= -output="build/{{.Dir}}_{{.OS}}_{{.Arch}}" -os="${GOX_OS}" -arch="${GOX_ARCH}"
STATIC_LDFLAGS ?= --ldflags '-extldflags "-static" --s -w'
GITLAB_CONTEXT ?= ./build/gitlab
# image data
ORG ?= redspreadapps
NAME ?= gitlabci
TAG ?= latest
GITLAB_IMAGE_NAME = "$(ORG)/$(NAME):$(TAG)"
GOX_OS ?= linux darwin windows
GOX_ARCH ?= amd64
.PHONY: all
all: clean validate test
.PHONY: release
release: validate test crossbuild
.PHONY: test
test: build
$(GO) test $(GOTEST_FLAGS) $(PKGS)
.PHONY: validate
validate: lint checkgofmt vet
.PHONY: build
build:
$(GO) build $(GOBUILD_FLAGS) $(GOBUILD_LDFLAGS) $(EXEC_PKG)
build/spread-linux-static:
GOOS=linux $(GO) build -o $@ $(GOBUILD_FLAGS) $(STATIC_LDFLAGS) $(EXEC_PKG)
chmod +x $@
.PHONY: crossbuild
crossbuild: deps gox-setup
$(GOX) $(GOX_FLAGS) -gcflags="$(GOBUILD_FLAGS)" -ldflags="$(GOBUILD_LDFLAGS)" $(EXEC_PKG)
.PHONY: build-gitlab
build-gitlab: build/spread-linux-static
rm -rf $(GITLAB_CONTEXT)
cp -r ./images/gitlabci $(GITLAB_CONTEXT)
cp ./build/spread-linux-static $(GITLAB_CONTEXT)
$(DOCKER) build $(DOCKER_OPTS) -t $(GITLAB_IMAGE_NAME) $(GITLAB_CONTEXT)
.PHONY: vet
vet:
$(GO) vet $(PKGS)
lint: .golint-install
for pkg in $(PKGS); do \
echo "Running golint on $$i:"; \
golint $$i; \
done;
.PHONY: checkgofmt
checkgofmt:
# get all go files and run go fmt on them
files=$$($(GOFILES) | xargs $(GOFMT) -l); if [[ -n "$$files" ]]; then \
echo "Error: '$(GOFMT)' needs to be run on:"; \
echo "$${files}"; \
exit 1; \
fi;
.PHONY: deps
deps: .golint-install .gox-install
.golint-install:
$(GO) get -x github.com/golang/lint/golint > $@
PHONY: gox-setup
gox-setup: .gox-install
.gox-install:
$(GO) get -x github.com/mitchellh/gox > $@
.PHONY: clean
clean:
rm -vf .gox-* .golint-*
rm -rfv ./build
$(GO) clean $(PKGS) || true
.PHONY: godep
godep:
go get -u -v github.com/tools/godep
@echo "Recalculating godeps, removing Godeps and vendor if not canceled in 5 seconds"
@sleep 5
rm -rf Godeps vendor
GO15VENDOREXPERIMENT="1" godep save -v ./pkg/... ./cli/... ./cmd/...