From fa4dc4e4060588dab4b8a6301132015d7d23d967 Mon Sep 17 00:00:00 2001 From: Bassam Tabbara Date: Sun, 24 Jul 2016 22:27:07 -0700 Subject: [PATCH] Initial support for building embedded ceph and calling it from a go cmd --- .gitignore | 4 ++++ .gitmodules | 1 + LICENSE | 0 Makefile | 51 +++++++++++++++++++++++++++++++++++++++++++++ README.md | 2 ++ ceph | 2 +- cmd/castled/main.go | 34 ++++++++++++++++++++++++++++++ glide.lock | 12 +++++++++++ glide.yaml | 5 +++++ version/version.go | 3 +++ 10 files changed, 113 insertions(+), 1 deletion(-) create mode 100644 .gitignore create mode 100644 LICENSE create mode 100644 Makefile create mode 100644 README.md create mode 100644 cmd/castled/main.go create mode 100644 glide.lock create mode 100644 glide.yaml create mode 100644 version/version.go diff --git a/.gitignore b/.gitignore new file mode 100644 index 000000000..0d88f69ae --- /dev/null +++ b/.gitignore @@ -0,0 +1,4 @@ +bin/ +tools/ +vendor/ + diff --git a/.gitmodules b/.gitmodules index fd7cf875c..eae2aa637 100644 --- a/.gitmodules +++ b/.gitmodules @@ -1,3 +1,4 @@ [submodule "ceph"] path = ceph url = git@github.com:quantum/ceph + branch = wip-embedded-ceph diff --git a/LICENSE b/LICENSE new file mode 100644 index 000000000..e69de29bb diff --git a/Makefile b/Makefile new file mode 100644 index 000000000..877f504ed --- /dev/null +++ b/Makefile @@ -0,0 +1,51 @@ +ifeq ($(origin VERSION), undefined) + VERSION != git describe --dirty --always +endif + +REPOPATH = github.com/quantum/castle + +GOOS=$(shell go env GOOS) +GOARCH=$(shell go env GOARCH) + +NPROCS:=1 +ifeq ($(GOOS),linux) + NPROCS:=$(shell grep -c ^processor /proc/cpuinfo) +endif + +build: vendor ceph/build/lib/libcephd.a + @for i in castled; do \ + go build -o bin/$$i -installsuffix cgo -ldflags "-extldflags '-static' -linkmode external -X $(REPOPATH)/version.Version=$(VERSION)" ./cmd/$$i; \ + done + +ceph/build/Makefile: + git submodule update --init --recursive + cd ceph && ./do_cmake.sh -DWITH_EMBEDDED=ON -DWITH_FUSE=OFF + +ceph/build/lib/libcephd.a: ceph/build/Makefile + cd ceph/build && make -j$(NPROCS) cephd + +test: tools/glide + go test --race $(shell ./tools/glide novendor) + +vet: tools/glide + go vet $(shell ./tools/glide novendor) + +fmt: tools/glide + go fmt $(shell ./tools/glide novendor) + +clean: + rm -rf ./bin + cd ceph/build && make clean + +cleanall: clean + rm -rf bin tools vendor + +vendor: tools/glide + ./tools/glide install + +tools/glide: + @echo "Downloading glide" + mkdir -p tools + curl -L https://github.com/Masterminds/glide/releases/download/v0.11.1/glide-v0.11.1-$(GOOS)-$(GOARCH).tar.gz | tar -xz -C tools + mv tools/$(GOOS)-$(GOARCH)/glide tools/glide + rm -r tools/$(GOOS)-$(GOARCH) diff --git a/README.md b/README.md new file mode 100644 index 000000000..89d118707 --- /dev/null +++ b/README.md @@ -0,0 +1,2 @@ +# Castle - Software Defined Storage + diff --git a/ceph b/ceph index c4da56d0c..d43b87b16 160000 --- a/ceph +++ b/ceph @@ -1 +1 @@ -Subproject commit c4da56d0cbfcd75e37be29dd4853b23487a3526f +Subproject commit d43b87b16610f5278da38953f4bffa03fb788b17 diff --git a/cmd/castled/main.go b/cmd/castled/main.go new file mode 100644 index 000000000..a72dd6df1 --- /dev/null +++ b/cmd/castled/main.go @@ -0,0 +1,34 @@ +package main + +// #cgo CFLAGS: -I${SRCDIR}/../../ceph/src/include +// #cgo LDFLAGS: -L${SRCDIR}/../../ceph/build/lib -lcephd -lstdc++ +// #include "cephd/libcephd.h" +import "C" + +import ( + "fmt" + + "github.com/quantum/castle/version" + "github.com/spf13/cobra" +) + +func CephVersion() (string) { + var c_major, c_minor, c_patch C.int + return C.GoString(C.ceph_version(&c_major,&c_minor,&c_patch)) +} + +func main() { + + var cmdVersion = &cobra.Command{ + Use: "version", + Short: "print castle version", + Long: `prints the version of castle.`, + Run: func(cmd *cobra.Command, args []string) { + fmt.Printf("castled version %v (ceph version %v)\n", version.Version, CephVersion()) + }, + } + + var rootCmd = &cobra.Command{Use: "castled"} + rootCmd.AddCommand(cmdVersion) + rootCmd.Execute() +} diff --git a/glide.lock b/glide.lock new file mode 100644 index 000000000..04bc10ca1 --- /dev/null +++ b/glide.lock @@ -0,0 +1,12 @@ +hash: ed0ac78e36a48a3140bd61be5aba1db8f7a7b3adae518dd6419a49ff46af4424 +updated: 2016-07-24T13:00:22.18839951-07:00 +imports: +- name: github.com/inconshreveable/mousetrap + version: 76626ae9c91c4f2a10f34cad8ce83ea42c93bb75 +- name: github.com/spf13/cobra + version: dbb7c2d02e284aa24423e3e6e105969dffe6e4d6 + subpackages: + - cobra +- name: github.com/spf13/pflag + version: 1560c1005499d61b80f865c04d39ca7505bf7f0b +testImports: [] diff --git a/glide.yaml b/glide.yaml new file mode 100644 index 000000000..27fe5f513 --- /dev/null +++ b/glide.yaml @@ -0,0 +1,5 @@ +package: github.com/quantum/castle +import: +- package: github.com/spf13/cobra + subpackages: + - cobra diff --git a/version/version.go b/version/version.go new file mode 100644 index 000000000..415100dcc --- /dev/null +++ b/version/version.go @@ -0,0 +1,3 @@ +package version + +var Version = "0.0.0"