diff --git a/.gitignore b/.gitignore index 25442a3da..cd99c1b06 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ default.etcd/ *.test +vendor diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 000000000..cea0d3d1a --- /dev/null +++ b/.travis.yml @@ -0,0 +1,8 @@ +language: go +go: + - 1.7.x + - master +script: make test +notifications: + slack: + secure: k0m8IqQIjb8L5b1plR9+w4hGo5iWlGtrR9nxvPsHL7gShwez74dpHCmFUCjR/uJoZa5Xq6849IWmiBB71ZHE/wNVN60HpMeui9VKkYvUDVpgBuqoIo969ySPDyQo4jNsk0wRRv/dG5/wXo7ArY8qOp5UDjdVuEf4nEbDlBtKjo0A2W8qXBTdZ5EJ3VeP5nrtrT7knuWxXgeUyVmLkpnUaLgkY7icvH6evqkftfcb56n3l5ulKtlQkI/ij2XCUK+5xtNB9m0e1QbiqIFS7sjwlSly/GCstPVnTEp4oHNHE7LtS6TJ8lgRV90Qy6LPtROjbSdfVjhJ5cYKus8DdddSfcsm2qgHCHQThyYtVAfOXaFPYPb50WXEu3HOckHk1tYChfkdxwEGdn/cN8/xxa7Khd7T/+SaS1B4CPxOFp0ie+rD4lF6IhApmpr/UwtiW6srHcPB04lF5mioYWmyS2eyGKTzSZR82nifg5KYUgBL1FjywQDYb8t9QaAn/6svu08k4H29TBnYpOQWREb38pYmEnMtRqiRmbfQL6IyV8405TJkl/PZmIElX6IQGjf53M1KoFdCUuTL1we6rh8gen5zRVUwmM6BJxkVt4NJ2wGkrXg/HD3feYCMrv+DY3lfDN7tADx90lPb+ukmanB8oSIQHLuLCJ2XcFixEC3QSvVlnH0= diff --git a/Makefile b/Makefile index 61abf2026..09b5616be 100644 --- a/Makefile +++ b/Makefile @@ -1,10 +1,47 @@ -.PHONY: vendor +.PHONY: glide vendor-update docker pilosa pilosactl crossbuild install -default: +GLIDE := $(shell command -v glide 2>/dev/null) +VERSION := $(shell git describe --tags) +IDENTIFIER := $(VERSION)-$(GOOS)-$(GOARCH) +CLONE_URL=github.com/pilosa/pilosa +BUILD_TIME=`date -u +%FT%T%z` +LDFLAGS=-ldflags "-X main.Version=$(VERSION) -X main.BuildTime=$(BUILD_TIME)" -vendor: - godep save ./... - cp -r $(GOPATH)/src/github.com/gogo/protobuf/proto/testdata vendor/github.com/gogo/protobuf/proto/testdata +default: test pilosa pilosactl -docker: +$(GOPATH)/bin: + mkdir $(GOPATH)/bin + +glide: $(GOPATH)/bin +ifndef GLIDE + curl https://glide.sh/get | sh +endif + +vendor: glide glide.yaml + glide install + +glide.lock: glide glide.yaml + glide update + +vendor-update: glide.lock + +test: vendor + go test $(shell cd $(GOPATH)/src/$(CLONE_URL); go list ./... | grep -v vendor) + +pilosa: vendor + go build $(LDFLAGS) $(FLAGS) $(CLONE_URL)/cmd/pilosa + +pilosactl: vendor + go build $(LDFLAGS) $(FLAGS) $(CLONE_URL)/cmd/pilosactl + +crossbuild: vendor + mkdir -p build/pilosa-$(IDENTIFIER) + make pilosa FLAGS="-o build/pilosa-$(IDENTIFIER)/pilosa" + make pilosactl FLAGS="-o build/pilosa-$(IDENTIFIER)/pilosactl" + +install: vendor + go install $(LDFLAGS) $(FLAGS) $(CLONE_URL)/cmd/pilosa + go install $(LDFLAGS) $(FLAGS) $(CLONE_URL)/cmd/pilosactl + +docker: vendor docker build -t pilosa:latest . diff --git a/cmd/pilosa/main.go b/cmd/pilosa/main.go index bcd3ee453..4f7474996 100644 --- a/cmd/pilosa/main.go +++ b/cmd/pilosa/main.go @@ -17,13 +17,19 @@ import ( "github.com/pilosa/pilosa" ) -// Version holds the version information passed in at compile time. -var Version string +// Version and BuildTime hold the version/build time information passed in at compile time. +var ( + Version string + BuildTime string +) func init() { if Version == "" { Version = "v0.0.0" } + if BuildTime == "" { + BuildTime = "not recorded" + } rand.Seed(time.Now().UTC().UnixNano()) } @@ -36,7 +42,7 @@ const ( func main() { m := NewMain() m.Server.Handler.Version = Version - fmt.Fprintf(m.Stderr, "Pilosa %s\n", Version) + fmt.Fprintf(m.Stderr, "Pilosa %s, build time %s\n", Version, BuildTime) // Parse command line arguments. if err := m.ParseFlags(os.Args[1:]); err != nil { diff --git a/cmd/pilosactl/main.go b/cmd/pilosactl/main.go index 331459c31..bb22d14ac 100644 --- a/cmd/pilosactl/main.go +++ b/cmd/pilosactl/main.go @@ -42,11 +42,24 @@ var ( // ErrPathRequired is returned when executing a command without a required path. ErrPathRequired = errors.New("path required") + Version string + BuildTime string ) +func init() { + if Version == "" { + Version = "v0.0.0" + } + if BuildTime == "" { + BuildTime = "not recorded" + } +} + func main() { m := NewMain() + fmt.Fprintf(m.Stderr, "Pilosactl %s, build time %s\n", Version, BuildTime) + // Parse command line arguments. if err := m.ParseFlags(os.Args[1:]); err == flag.ErrHelp { os.Exit(2) diff --git a/pilosactl/import.go b/pilosactl/import.go index 6a278fe9a..9d4ad63f4 100644 --- a/pilosactl/import.go +++ b/pilosactl/import.go @@ -128,15 +128,22 @@ func (cmd *ImportCommand) Run(ctx context.Context) error { func (cmd *ImportCommand) importPath(ctx context.Context, path string) error { a := make([]pilosa.Bit, 0, cmd.BufferSize) - // Open file for reading. - f, err := os.Open(path) - if err != nil { - return err - } - defer f.Close() + var r *csv.Reader + + if path != "-" { + // Open file for reading. + f, err := os.Open(path) + if err != nil { + return err + } + defer f.Close() + + // Read rows as bits. + r = csv.NewReader(f) + } else { + r = csv.NewReader(cmd.Stdin) + } - // Read rows as bits. - r := csv.NewReader(f) r.FieldsPerRecord = -1 rnum := 0 for {