2016-03-23 11:39:24 +00:00
|
|
|
#!/bin/bash
|
2016-03-24 14:11:56 +00:00
|
|
|
#
|
|
|
|
#
|
2016-08-12 11:04:17 +00:00
|
|
|
|
2018-05-27 17:29:09 +00:00
|
|
|
RELEASE_VERSION=
|
2018-05-27 17:49:08 +00:00
|
|
|
buildpath=
|
|
|
|
|
|
|
|
function setuptree() {
|
|
|
|
b=$( mktemp -d $buildpath/gh-ostXXXXXX ) || return 1
|
|
|
|
mkdir -p $b/gh-ost
|
|
|
|
mkdir -p $b/gh-ost/usr/bin
|
|
|
|
echo $b
|
|
|
|
}
|
2016-03-23 11:39:24 +00:00
|
|
|
|
2016-08-12 11:04:17 +00:00
|
|
|
function build {
|
2018-05-27 17:49:08 +00:00
|
|
|
osname=$1
|
|
|
|
osshort=$2
|
|
|
|
GOOS=$3
|
|
|
|
GOARCH=$4
|
2016-08-12 11:04:17 +00:00
|
|
|
|
2018-05-27 17:49:08 +00:00
|
|
|
|
|
|
|
|
|
|
|
if ! go version | egrep -q 'go(1[.]9|1[.]1[0-9])' ; then
|
|
|
|
echo "go version is too low. Must use 1.9 or above"
|
|
|
|
exit 1
|
|
|
|
fi
|
2017-11-23 10:13:25 +00:00
|
|
|
|
2018-05-27 17:49:08 +00:00
|
|
|
echo "Building ${osname} binary"
|
|
|
|
export GOOS
|
|
|
|
export GOARCH
|
|
|
|
go build -ldflags "$ldflags" -o $buildpath/$target go/cmd/gh-ost/main.go
|
2016-08-12 11:04:17 +00:00
|
|
|
|
2018-05-27 17:49:08 +00:00
|
|
|
if [ $? -ne 0 ]; then
|
|
|
|
echo "Build failed for ${osname}"
|
|
|
|
exit 1
|
|
|
|
fi
|
2016-08-12 11:04:17 +00:00
|
|
|
|
2018-05-27 17:49:08 +00:00
|
|
|
(cd $buildpath && tar cfz ./gh-ost-binary-${osshort}-${timestamp}.tar.gz $target)
|
|
|
|
|
|
|
|
if [ "$GOOS" == "linux" ] ; then
|
|
|
|
echo "Creating Distro full packages"
|
2018-05-27 18:03:44 +00:00
|
|
|
builddir=$(setuptree)
|
2018-05-27 17:49:08 +00:00
|
|
|
cp $buildpath/$target $builddir/gh-ost/usr/bin
|
2018-05-27 17:53:18 +00:00
|
|
|
cd $buildpath
|
2018-05-27 17:49:08 +00:00
|
|
|
fpm -v "${RELEASE_VERSION}" --epoch 1 -f -s dir -n gh-ost -m shlomi-noach --description "GitHub's Online Schema Migrations for MySQL " --url "https://github.com/github/gh-ost" --vendor "GitHub" --license "Apache 2.0" -C $builddir/gh-ost --prefix=/ -t rpm .
|
|
|
|
fpm -v "${RELEASE_VERSION}" --epoch 1 -f -s dir -n gh-ost -m shlomi-noach --description "GitHub's Online Schema Migrations for MySQL " --url "https://github.com/github/gh-ost" --vendor "GitHub" --license "Apache 2.0" -C $builddir/gh-ost --prefix=/ -t deb --deb-no-default-config-files .
|
|
|
|
fi
|
2016-08-12 11:04:17 +00:00
|
|
|
}
|
|
|
|
|
2018-05-27 17:29:09 +00:00
|
|
|
main() {
|
|
|
|
if [ -z "${RELEASE_VERSION}" ] ; then
|
|
|
|
RELEASE_VERSION=$(git describe --abbrev=0 --tags | tr -d 'v')
|
|
|
|
fi
|
|
|
|
if [ -z "${RELEASE_VERSION}" ] ; then
|
|
|
|
RELEASE_VERSION=$(cat RELEASE_VERSION)
|
|
|
|
fi
|
2016-03-23 11:39:24 +00:00
|
|
|
|
|
|
|
|
2018-05-27 17:59:58 +00:00
|
|
|
buildpath=/tmp/gh-ost-release
|
2018-05-27 17:29:09 +00:00
|
|
|
target=gh-ost
|
|
|
|
timestamp=$(date "+%Y%m%d%H%M%S")
|
|
|
|
ldflags="-X main.AppVersion=${RELEASE_VERSION}"
|
|
|
|
|
|
|
|
mkdir -p ${buildpath}
|
2018-05-27 18:02:00 +00:00
|
|
|
rm -rf ${buildpath:?}/*
|
2018-05-27 17:29:09 +00:00
|
|
|
build macOS osx darwin amd64
|
|
|
|
build GNU/Linux linux linux amd64
|
|
|
|
|
|
|
|
echo "Binaries found in:"
|
|
|
|
ls -1 $buildpath/gh-ost-binary*${timestamp}.tar.gz
|
|
|
|
}
|
|
|
|
|
|
|
|
main "$@"
|