diff --git a/.gitignore b/.gitignore index e9c42d2..2cecb63 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ little_bigtable.db little_bigtable build +dist diff --git a/Makefile b/Makefile index 74d1988..c26996a 100644 --- a/Makefile +++ b/Makefile @@ -1,7 +1,7 @@ PREFIX=/usr/local BINDIR=${PREFIX}/bin DESTDIR= -BLDDIR = build +BLDDIR=build BLDFLAGS= EXT= ifeq (${GOOS},windows) diff --git a/README.md b/README.md index 56d4495..511728b 100644 --- a/README.md +++ b/README.md @@ -23,6 +23,15 @@ Usage of ./little_bigtable: the address to bind to on the local machine (default "localhost") -port int the port number to bind to on the local machine (default 9000) + -version + show version +``` + +In the environment for your application, set the `BIGTABLE_EMULATOR_HOST` environment variable to the host and port where `little_bigtable` is running. This environment variable is automatically detected by the Bigtable SDK or the `cbt` CLI. For example: + +```bash +$ export BIGTABLE_EMULATOR_HOST="127.0.0.1:9000" +$ ./run_my_app ``` ## Limitations diff --git a/dist.sh b/dist.sh new file mode 100755 index 0000000..4e6366f --- /dev/null +++ b/dist.sh @@ -0,0 +1,33 @@ +#!/bin/bash + +# 1. commit to bump the version (little_bigtable.go) +# 2. tag that commit +# 3. use dist.sh to produce tar.gz for all platforms +# 4. update the release metadata on github / upload the binaries + +set -e + +DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" + +version=$(awk '/version / {print $NF}' < $DIR/little_bigtable.go | sed 's/"//g') +goversion=$(go version | awk '{print $3}') + +echo "... running tests" +./test.sh + +mkdir -p dist +for target in "linux/amd64"; do + os=${target%/*} + arch=${target##*/} + echo "... building v$version for $os/$arch" + BUILD=$(mktemp -d ${TMPDIR:-/tmp}/build-XXXXX) + TARGET="little_bigtable-$version.$os-$arch.$goversion" + GOOS=$os GOARCH=$arch \ + go build --tags "$os" -o $BUILD/$TARGET . + pushd $BUILD + sudo chown -R 0:0 $TARGET + tar czvf $TARGET.tar.gz $TARGET + mv $TARGET.tar.gz $DIR/dist + popd + sudo rm -r $BUILD +done diff --git a/little_bigtable.go b/little_bigtable.go index 71f1acb..a5fb419 100644 --- a/little_bigtable.go +++ b/little_bigtable.go @@ -9,28 +9,35 @@ import ( "flag" "fmt" "log" + "os" + "runtime" "github.com/bitly/little_bigtable/bttest" _ "github.com/mattn/go-sqlite3" "google.golang.org/grpc" ) -var ( - host = flag.String("host", "localhost", "the address to bind to on the local machine") - port = flag.Int("port", 9000, "the port number to bind to on the local machine") - dbFile = flag.String("db-file", "little_bigtable.db", "path to data file") -) - const ( maxMsgSize = 256 * 1024 * 1024 // 256 MiB + version = "0.1.0" ) func main() { + host := flag.String("host", "localhost", "the address to bind to on the local machine") + port := flag.Int("port", 9000, "the port number to bind to on the local machine") + dbFile := flag.String("db-file", "little_bigtable.db", "path to data file") + showVersion := flag.Bool("version", false, "show version") + ctx := context.Background() grpc.EnableTracing = false flag.Parse() log.SetFlags(log.Ldate | log.Ltime | log.Lshortfile) + if *showVersion { + fmt.Printf("little_bigtable v%s (built w/%s)", version, runtime.Version()) + os.Exit(0) + } + if *dbFile == "" { log.Fatal("missing --db-file") }