forked from yp-engineering/rbd-docker-plugin
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Makefile
132 lines (98 loc) · 3.43 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
# building the rbd docker plugin golang binary with version
# makefile mostly used for packing a tpkg
.PHONY: all build install clean test version setup systemd dep-tool
IMAGE_PATH=ypengineering/rbd-docker-plugin
TAG?=latest
IMAGE=$(IMAGE_PATH):$(TAG)
SUDO?=
TMPDIR?=/tmp
INSTALL?=install
#TPKG_VERSION=$(VERSION)-2
TPKG_VERSION=$(VERSION)
BINARY=rbd-docker-plugin
PKG_SRC=main.go driver.go version.go
PKG_SRC_TEST=$(PKG_SRC) driver_test.go unlock_test.go
PACKAGE_BUILD=$(TMPDIR)/$(BINARY).tpkg.buildtmp
PACKAGE_BIN_DIR=$(PACKAGE_BUILD)/reloc/bin
PACKAGE_ETC_DIR=$(PACKAGE_BUILD)/reloc/etc
PACKAGE_INIT_DIR=$(PACKAGE_ETC_DIR)/init
PACKAGE_LOG_CONFIG_DIR=$(PACKAGE_ETC_DIR)/logrotate.d
PACKAGE_SYSTEMD_DIR=$(PACKAGE_ETC_DIR)/systemd/system
CONFIG_FILES=tpkg.yml README.md LICENSE
SYSTEMD_UNIT=etc/systemd/rbd-docker-plugin.service
UPSTART_INIT=etc/init/rbd-docker-plugin.conf
LOG_CONFIG=etc/logrotate.d/rbd-docker-plugin_logrotate
SCRIPT_FILES=postinstall postremove
BIN_FILES=dist/$(BINARY) check-ceph-rbd-docker-plugin.sh
# Run these if you have a local dev env setup, otherwise they will / can be run
# in the container.
all: build
dep-tool:
go get -u github.com/golang/dep/cmd/dep
vendor: dep-tool
dep ensure
# set VERSION from version.go, eval into Makefile for inclusion into tpkg.yml
version: version.go
$(eval VERSION := $(shell grep "VERSION" version.go | cut -f2 -d'"'))
build: dist/$(BINARY)
dist/$(BINARY): $(PKG_SRC) vendor
go build -v -x -o dist/$(BINARY) .
install: build test
go install .
clean:
go clean
rm -f dist/$(BINARY)
rm -fr vendor/
uninstall:
@$(RM) -iv `which $(BINARY)`
# FIXME: TODO: this micro-osd script leaves ceph-mds laying around -- fix it up
test: vendor
TMP_DIR=$$(mktemp -d) && \
./micro-osd.sh $$TMP_DIR && \
export CEPH_CONF=$${TMP_DIR}/ceph.conf && \
ceph -s && \
go test -v && \
rm -rf $$TMP_DIR
# use existing ceph installation instead of micro-osd.sh - expecting CEPH_CONF to be set ...
CEPH_CONF ?= /etc/ceph/ceph.conf
local_test: vendor
@echo "Using CEPH_CONF=$(CEPH_CONF)"
test -n "${CEPH_CONF}" && \
$(SUDO) rbd ls && \
go test -v
dist:
mkdir dist
systemd: dist
cp systemd/rbd-docker-plugin.service dist/
# Used to have build env be inside container and to pull out the binary.
make/%: build_docker
$(SUDO) docker run ${DOCKER_ARGS} --rm -i $(IMAGE) make $*
run:
$(SUDO) docker run ${DOCKER_ARGS} --rm -it $(IMAGE)
build_docker:
$(SUDO) docker build -t $(IMAGE) .
binary_from_container:
$(SUDO) docker run ${DOCKER_ARGS} --rm -it \
-v $${PWD}:/rbd-docker-plugin/dist \
-w /rbd-docker-plugin \
$(IMAGE) make build
local:
$(SUDO) docker run ${DOCKER_ARGS} --rm -it \
-v $${PWD}:/rbd-docker-plugin \
-w /rbd-docker-plugin \
$(IMAGE)
# container actions
test_from_container: make/test
# build relocatable tpkg
# TODO: repair PATHS at install to set TPKG_HOME (assumed /home/ops)
package: version build local_test
$(RM) -fr $(PACKAGE_BUILD)
mkdir -p $(PACKAGE_BIN_DIR) $(PACKAGE_INIT_DIR) $(PACKAGE_SYSTEMD_DIR) $(PACKAGE_LOG_CONFIG_DIR)
$(INSTALL) $(SCRIPT_FILES) $(PACKAGE_BUILD)/.
$(INSTALL) $(BIN_FILES) $(PACKAGE_BIN_DIR)/.
$(INSTALL) -m 0644 $(CONFIG_FILES) $(PACKAGE_BUILD)/.
$(INSTALL) -m 0644 $(SYSTEMD_UNIT) $(PACKAGE_SYSTEMD_DIR)/.
$(INSTALL) -m 0644 $(UPSTART_INIT) $(PACKAGE_INIT_DIR)/.
$(INSTALL) -m 0644 $(LOG_CONFIG) $(PACKAGE_LOG_CONFIG_DIR)/.
sed -i "s/^version:.*/version: $(TPKG_VERSION)/" $(PACKAGE_BUILD)/tpkg.yml
tpkg --make $(PACKAGE_BUILD) --out $(CURDIR)