2016-03-05 02:08:16 +03:00
|
|
|
#!/bin/bash
|
|
|
|
set -e
|
|
|
|
|
2017-08-16 20:02:56 +03:00
|
|
|
VERSION="1.9.1"
|
2016-03-08 16:12:39 +03:00
|
|
|
PROTECTED_MODE="no"
|
|
|
|
|
|
|
|
# Hardcode some values to the core package
|
|
|
|
LDFLAGS="$LDFLAGS -X github.com/tidwall/tile38/core.Version=${VERSION}"
|
2016-03-14 02:39:04 +03:00
|
|
|
if [ -d ".git" ]; then
|
|
|
|
LDFLAGS="$LDFLAGS -X github.com/tidwall/tile38/core.GitSHA=$(git rev-parse --short HEAD)"
|
|
|
|
fi
|
2016-03-08 16:12:39 +03:00
|
|
|
LDFLAGS="$LDFLAGS -X github.com/tidwall/tile38/core.BuildTime=$(date +%FT%T%z)"
|
|
|
|
if [ "$PROTECTED_MODE" == "no" ]; then
|
|
|
|
LDFLAGS="$LDFLAGS -X github.com/tidwall/tile38/core.ProtectedMode=no"
|
|
|
|
fi
|
2016-03-05 02:08:16 +03:00
|
|
|
|
2016-12-29 21:54:35 +03:00
|
|
|
if [ "$1" == "update-version" ]; then
|
|
|
|
# update the versions in the README.md and Dockerfile
|
|
|
|
sed -i '' "s/version-.\..\../version-$VERSION/g" README.md
|
|
|
|
sed -i '' "s/ENV\ TILE38_VERSION\ .\..\../ENV TILE38_VERSION $VERSION/g" docker/Dockerfile
|
|
|
|
exit
|
|
|
|
fi
|
|
|
|
|
2016-03-17 22:15:35 +03:00
|
|
|
# Check go install
|
2016-03-17 21:55:50 +03:00
|
|
|
if [ "$(which go)" == "" ]; then
|
|
|
|
echo "error: Go is not installed. Please download and follow installation instructions at https://golang.org/dl to continue."
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
2016-03-17 22:15:35 +03:00
|
|
|
# Check go version
|
2016-03-17 21:55:50 +03:00
|
|
|
GOVERS="$(go version | cut -d " " -f 3)"
|
2016-03-17 22:02:10 +03:00
|
|
|
if [ "$GOVERS" != "devel" ]; then
|
2016-03-17 22:15:35 +03:00
|
|
|
vercomp () {
|
|
|
|
if [[ $1 == $2 ]]
|
|
|
|
then
|
|
|
|
echo "0"
|
|
|
|
return
|
|
|
|
fi
|
|
|
|
local IFS=.
|
|
|
|
local i ver1=($1) ver2=($2)
|
|
|
|
# fill empty fields in ver1 with zeros
|
|
|
|
for ((i=${#ver1[@]}; i<${#ver2[@]}; i++))
|
|
|
|
do
|
|
|
|
ver1[i]=0
|
|
|
|
done
|
|
|
|
for ((i=0; i<${#ver1[@]}; i++))
|
|
|
|
do
|
|
|
|
if [[ -z ${ver2[i]} ]]
|
|
|
|
then
|
|
|
|
# fill empty fields in ver2 with zeros
|
|
|
|
ver2[i]=0
|
|
|
|
fi
|
|
|
|
if ((10#${ver1[i]} > 10#${ver2[i]}))
|
|
|
|
then
|
|
|
|
echo "1"
|
|
|
|
return
|
|
|
|
fi
|
|
|
|
if ((10#${ver1[i]} < 10#${ver2[i]}))
|
|
|
|
then
|
|
|
|
echo "-1"
|
|
|
|
return
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
echo "0"
|
|
|
|
return
|
|
|
|
}
|
|
|
|
GOVERS="${GOVERS:2}"
|
2017-07-24 21:20:10 +03:00
|
|
|
EQRES=$(vercomp "$GOVERS" "1.7")
|
2016-03-17 22:02:10 +03:00
|
|
|
if [ "$EQRES" == "-1" ]; then
|
2017-07-24 21:20:10 +03:00
|
|
|
echo "error: Go '1.7' or greater is required and '$GOVERS' is currently installed. Please upgrade Go at https://golang.org/dl to continue."
|
2016-03-17 22:15:35 +03:00
|
|
|
exit 1
|
2016-03-17 22:02:10 +03:00
|
|
|
fi
|
2016-03-17 21:55:50 +03:00
|
|
|
fi
|
|
|
|
|
2016-03-05 02:28:32 +03:00
|
|
|
export GO15VENDOREXPERIMENT=1
|
|
|
|
|
2016-03-05 02:08:16 +03:00
|
|
|
cd $(dirname "${BASH_SOURCE[0]}")
|
|
|
|
OD="$(pwd)"
|
|
|
|
|
2016-04-03 18:35:15 +03:00
|
|
|
package(){
|
|
|
|
echo Packaging $1 Binary
|
2016-04-03 18:43:31 +03:00
|
|
|
bdir=tile38-${VERSION}-$2-$3
|
2016-04-03 18:35:15 +03:00
|
|
|
rm -rf packages/$bdir && mkdir -p packages/$bdir
|
|
|
|
GOOS=$2 GOARCH=$3 ./build.sh
|
2016-07-22 21:22:55 +03:00
|
|
|
if [ "$2" == "windows" ]; then
|
|
|
|
mv tile38-server packages/$bdir/tile38-server.exe
|
|
|
|
mv tile38-cli packages/$bdir/tile38-cli.exe
|
2017-03-31 00:14:44 +03:00
|
|
|
mv tile38-benchmark packages/$bdir/tile38-benchmark.exe
|
2016-07-22 21:22:55 +03:00
|
|
|
else
|
|
|
|
mv tile38-server packages/$bdir
|
|
|
|
mv tile38-cli packages/$bdir
|
2017-03-31 00:14:44 +03:00
|
|
|
mv tile38-benchmark packages/$bdir
|
2016-07-22 21:22:55 +03:00
|
|
|
fi
|
2016-04-03 18:35:15 +03:00
|
|
|
cp README.md packages/$bdir
|
2016-11-17 19:22:17 +03:00
|
|
|
cp CHANGELOG.md packages/$bdir
|
|
|
|
cp LICENSE packages/$bdir
|
2016-04-03 18:35:15 +03:00
|
|
|
cd packages
|
|
|
|
if [ "$2" == "linux" ]; then
|
|
|
|
tar -zcf $bdir.tar.gz $bdir
|
|
|
|
else
|
|
|
|
zip -r -q $bdir.zip $bdir
|
|
|
|
fi
|
|
|
|
rm -rf $bdir
|
|
|
|
cd ..
|
|
|
|
}
|
|
|
|
|
|
|
|
if [ "$1" == "package" ]; then
|
|
|
|
rm -rf packages/
|
|
|
|
package "Windows" "windows" "amd64"
|
|
|
|
package "Mac" "darwin" "amd64"
|
|
|
|
package "Linux" "linux" "amd64"
|
2016-06-08 21:58:10 +03:00
|
|
|
package "FreeBSD" "freebsd" "amd64"
|
2016-04-03 18:35:15 +03:00
|
|
|
exit
|
|
|
|
fi
|
|
|
|
|
2016-03-08 03:37:16 +03:00
|
|
|
# temp directory for storing isolated environment.
|
2016-03-05 02:28:32 +03:00
|
|
|
TMP="$(mktemp -d -t tile38.XXXX)"
|
2016-03-05 02:08:16 +03:00
|
|
|
function rmtemp {
|
2016-03-17 22:15:35 +03:00
|
|
|
rm -rf "$TMP"
|
2016-03-05 02:08:16 +03:00
|
|
|
}
|
|
|
|
trap rmtemp EXIT
|
|
|
|
|
2017-10-06 00:08:03 +03:00
|
|
|
|
2017-10-05 17:40:19 +03:00
|
|
|
if [ "$NOLINK" != "1" ]; then
|
|
|
|
# symlink root to isolated directory
|
|
|
|
mkdir -p "$TMP/go/src/github.com/tidwall"
|
|
|
|
ln -s $OD "$TMP/go/src/github.com/tidwall/tile38"
|
|
|
|
export GOPATH="$TMP/go"
|
|
|
|
cd "$TMP/go/src/github.com/tidwall/tile38"
|
2016-03-08 03:37:16 +03:00
|
|
|
fi
|
|
|
|
|
2016-03-05 02:08:16 +03:00
|
|
|
# build and store objects into original directory.
|
|
|
|
go build -ldflags "$LDFLAGS" -o "$OD/tile38-server" cmd/tile38-server/*.go
|
|
|
|
go build -ldflags "$LDFLAGS" -o "$OD/tile38-cli" cmd/tile38-cli/*.go
|
2017-03-31 00:14:44 +03:00
|
|
|
go build -ldflags "$LDFLAGS" -o "$OD/tile38-benchmark" cmd/tile38-benchmark/*.go
|
Lua scripting feature. (#224)
* Start on lua scripting
* Implement evalsha, script load, script exists, and script flush
* Type conversions from lua to resp/json.
Refactor to make luastate and luascripts persistent in the controller.
* Change controller.command and all underlying commands to return resp.Value.
Serialize only during the ouput.
* First stab at tile38 call from lua
* Change tile38 into tile38.call in Lua
* Property return errors from scripts
* Minor refactoring. No locking on script run
* Cleanup/refactoring
* Create a pool of 5 lua states, allow for more as needed. Refactor.
* Use safe map for scripts. Add a limit for max number of lua states. Refactor.
* Refactor
* Refactor script commands into atomic, read-only, and non-atomic classes.
Proper locking for all three classes.
Add tests for scripts
* More tests for scripts
* Properly escape newlines in lua-produced errors
* Better test for readonly failure
* Correctly convert ok/err messages between lua and resp.
Add pcall, sha1hex, error_reply, status_reply functions to tile38 namespace in lua.
* Add pcall test. Change writeErr to work with string argument
* Make sure eval/evalsha never attempt to write AOF
* Add eval-set and eval-get to benchmarks
* Fix eval benchmark tests, add more
* Improve benchmarks
* Optimizations and refactoring.
* Add lua memtest
* Typo
* Add dependency
* golint fixes
* gofmt fixes
* Add scripting commands to the core/commands.json
* Use ARGV for args inside lua
2017-10-05 18:20:40 +03:00
|
|
|
go build -ldflags "$LDFLAGS" -o "$OD/tile38-luamemtest" cmd/tile38-luamemtest/*.go
|
2016-03-05 02:08:16 +03:00
|
|
|
|
2016-03-07 16:44:38 +03:00
|
|
|
# test if requested
|
|
|
|
if [ "$1" == "test" ]; then
|
|
|
|
$OD/tile38-server -p 9876 -d "$TMP" -q &
|
|
|
|
PID=$!
|
|
|
|
function testend {
|
2016-03-17 22:15:35 +03:00
|
|
|
kill $PID &
|
2016-03-07 16:44:38 +03:00
|
|
|
}
|
|
|
|
trap testend EXIT
|
2016-12-02 19:14:34 +03:00
|
|
|
cd tests && go test && cd ..
|
|
|
|
go test $(go list ./... | grep -v /vendor/ | grep -v /tests)
|
2016-03-07 16:44:38 +03:00
|
|
|
fi
|
2016-03-05 02:08:16 +03:00
|
|
|
|
2016-04-03 17:59:23 +03:00
|
|
|
# cover if requested
|
|
|
|
if [ "$1" == "cover" ]; then
|
|
|
|
$OD/tile38-server -p 9876 -d "$TMP" -q &
|
|
|
|
PID=$!
|
|
|
|
function testend {
|
|
|
|
kill $PID &
|
|
|
|
}
|
|
|
|
trap testend EXIT
|
|
|
|
go test -cover $(go list ./... | grep -v /vendor/)
|
|
|
|
fi
|
|
|
|
|
2016-04-03 18:35:15 +03:00
|
|
|
|