forked from heketi/heketi
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
154 lines (125 loc) · 3.83 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
147
148
149
150
151
152
153
154
#
# Based on http://chrismckenzie.io/post/deploying-with-golang/
#
APP_NAME := heketi
CLIENT_PKG_NAME := heketi-client
SHA := $(shell git rev-parse --short HEAD)
BRANCH := $(subst /,-,$(shell git rev-parse --abbrev-ref HEAD))
VER := $(shell git describe --match='v[0-9].[0-9].[0-9]')
TAG := $(shell git tag --points-at HEAD 'v[0-9].[0-9].[0-9]' | tail -n1)
GO:=go
GOARCH := $(shell $(GO) env GOARCH)
GOOS := $(shell $(GO) env GOOS)
GOHOSTARCH := $(shell $(GO) env GOHOSTARCH)
GOHOSTOS := $(shell $(GO) env GOHOSTOS)
GOBUILDFLAGS :=
ifeq ($(GOOS),$(GOHOSTOS))
ifeq ($(GOARCH),$(GOHOSTARCH))
GOBUILDFLAGS :=-i
endif
endif
GLIDEPATH := $(shell command -v glide 2> /dev/null)
DIR=.
ifeq (master,$(BRANCH))
VERSION = $(VER)
else
ifeq ($(VER),$(TAG))
VERSION = $(VER)
else
VERSION = $(VER)-$(BRANCH)
endif
endif
# Sources and Targets
EXECUTABLES :=$(APP_NAME)
# Build Binaries setting main.version and main.build vars
LDFLAGS :=-ldflags "-X main.HEKETI_VERSION=$(VERSION) -extldflags '-z relro -z now'"
# Package target
PACKAGE :=$(DIR)/dist/$(APP_NAME)-$(VERSION).$(GOOS).$(GOARCH).tar.gz
CLIENT_PACKAGE :=$(DIR)/dist/$(APP_NAME)-client-$(VERSION).$(GOOS).$(GOARCH).tar.gz
DEPS_TARBALL :=$(DIR)/dist/$(APP_NAME)-deps-$(VERSION).tar.gz
.DEFAULT: all
all: server client
# print the version
version:
@echo $(VERSION)
# print the name of the app
name:
@echo $(APP_NAME)
# print the package path
package:
@echo $(PACKAGE)
heketi: vendor glide.lock
$(GO) build $(GOBUILDFLAGS) $(LDFLAGS) -o $(APP_NAME)
server: heketi
vendor:
ifndef GLIDEPATH
$(info Please install glide.)
$(info Install it using your package manager or)
$(info by running: curl https://glide.sh/get | sh.)
$(info )
$(error glide is required to continue)
endif
echo "Installing vendor directory"
glide install -v
glide.lock: glide.yaml
echo "Glide.yaml has changed, updating glide.lock"
glide update -v
client: vendor glide.lock
@$(MAKE) -C client/cli/go
run: server
./$(APP_NAME)
test: vendor glide.lock
./test.sh $(TESTOPTIONS)
test-functional: vendor glide.lock
$(MAKE) -C tests/functional test
clean:
@echo Cleaning Workspace...
rm -rf $(APP_NAME)
rm -rf dist coverage packagecover.out
@$(MAKE) -C client/cli/go clean
clean_vendor:
rm -rf vendor
$(PACKAGE): all
@echo Packaging Binaries...
@mkdir -p tmp/$(APP_NAME)
@cp $(APP_NAME) tmp/$(APP_NAME)/
@cp client/cli/go/heketi-cli tmp/$(APP_NAME)/
@cp etc/heketi.json tmp/$(APP_NAME)/
@mkdir -p $(DIR)/dist/
tar -czf $@ -C tmp $(APP_NAME);
@rm -rf tmp
@echo
@echo Package $@ saved in dist directory
$(CLIENT_PACKAGE): all
@echo Packaging client Binaries...
@mkdir -p tmp/$(CLIENT_PKG_NAME)/bin
@mkdir -p tmp/$(CLIENT_PKG_NAME)/share/heketi/openshift/templates
@mkdir -p tmp/$(CLIENT_PKG_NAME)/share/heketi/kubernetes
@cp client/cli/go/topology-sample.json tmp/$(CLIENT_PKG_NAME)/share/heketi
@cp client/cli/go/heketi-cli tmp/$(CLIENT_PKG_NAME)/bin
@cp extras/openshift/templates/* tmp/$(CLIENT_PKG_NAME)/share/heketi/openshift/templates
@cp extras/kubernetes/* tmp/$(CLIENT_PKG_NAME)/share/heketi/kubernetes
@mkdir -p $(DIR)/dist/
tar -czf $@ -C tmp $(CLIENT_PKG_NAME);
@rm -rf tmp
@echo
@echo Package $@ saved in dist directory
deps_tarball: $(DEPS_TARBALL)
$(DEPS_TARBALL): clean clean_vendor vendor glide.lock
@echo Creating dependency tarball...
@mkdir -p $(DIR)/dist/
tar -czf $@ -C vendor .
dist: $(PACKAGE) $(CLIENT_PACKAGE)
linux_amd64_dist:
GOOS=linux GOARCH=amd64 $(MAKE) dist
linux_arm_dist:
GOOS=linux GOARCH=arm $(MAKE) dist
linux_arm64_dist:
GOOS=linux GOARCH=arm64 $(MAKE) dist
darwin_amd64_dist:
GOOS=darwin GOARCH=amd64 $(MAKE) dist
release: deps_tarball darwin_amd64_dist linux_arm64_dist linux_arm_dist linux_amd64_dist
.PHONY: server client test clean name run version release \
darwin_amd64_dist linux_arm_dist linux_amd64_dist linux_arm64_dist \
heketi clean_vendor deps_tarball all dist \
test-functional