From d20903e2605672a34a3003aa0468e38fe97af613 Mon Sep 17 00:00:00 2001 From: Shlomi Noach Date: Sun, 27 May 2018 20:29:09 +0300 Subject: [PATCH 1/6] Package builds --- build.sh | 32 ++++++++++++++++++++++---------- 1 file changed, 22 insertions(+), 10 deletions(-) diff --git a/build.sh b/build.sh index 4f38512..7f44a8a 100755 --- a/build.sh +++ b/build.sh @@ -2,7 +2,7 @@ # # -RELEASE_VERSION=$(cat RELEASE_VERSION) +RELEASE_VERSION= function build { osname=$1 @@ -28,14 +28,26 @@ function build { (cd $buildpath && tar cfz ./gh-ost-binary-${osshort}-${timestamp}.tar.gz $target) } -buildpath=/tmp/gh-ost -target=gh-ost -timestamp=$(date "+%Y%m%d%H%M%S") -ldflags="-X main.AppVersion=${RELEASE_VERSION}" +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 -mkdir -p ${buildpath} -build macOS osx darwin amd64 -build GNU/Linux linux linux amd64 -echo "Binaries found in:" -ls -1 $buildpath/gh-ost-binary*${timestamp}.tar.gz + buildpath=/tmp/gh-ost + target=gh-ost + timestamp=$(date "+%Y%m%d%H%M%S") + ldflags="-X main.AppVersion=${RELEASE_VERSION}" + + mkdir -p ${buildpath} + 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 "$@" From 460b15d827b98e8423e995eeceb214a06b295cb3 Mon Sep 17 00:00:00 2001 From: Shlomi Noach Date: Sun, 27 May 2018 20:49:08 +0300 Subject: [PATCH 2/6] rpm and deb --- build.sh | 55 ++++++++++++++++++++++++++++++++++++++----------------- 1 file changed, 38 insertions(+), 17 deletions(-) diff --git a/build.sh b/build.sh index 7f44a8a..3094123 100755 --- a/build.sh +++ b/build.sh @@ -3,29 +3,50 @@ # RELEASE_VERSION= +buildpath= +builddir= + +function setuptree() { + mkdir -p $buildpath + rm -rf ${buildpath:?}/* + b=$( mktemp -d $buildpath/gh-ostXXXXXX ) || return 1 + mkdir -p $b/gh-ost + mkdir -p $b/gh-ost/usr/bin + echo $b +} function build { - osname=$1 - osshort=$2 - GOOS=$3 - GOARCH=$4 + osname=$1 + osshort=$2 + GOOS=$3 + GOARCH=$4 - 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" + builddir=$(setuptree) + + + 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 + + echo "Building ${osname} binary" + export GOOS + export GOARCH + go build -ldflags "$ldflags" -o $buildpath/$target go/cmd/gh-ost/main.go + + if [ $? -ne 0 ]; then + echo "Build failed for ${osname}" exit 1 - fi + fi - echo "Building ${osname} binary" - export GOOS - export GOARCH - go build -ldflags "$ldflags" -o $buildpath/$target go/cmd/gh-ost/main.go + (cd $buildpath && tar cfz ./gh-ost-binary-${osshort}-${timestamp}.tar.gz $target) - if [ $? -ne 0 ]; then - echo "Build failed for ${osname}" - exit 1 - fi - - (cd $buildpath && tar cfz ./gh-ost-binary-${osshort}-${timestamp}.tar.gz $target) + if [ "$GOOS" == "linux" ] ; then + echo "Creating Distro full packages" + cp $buildpath/$target $builddir/gh-ost/usr/bin + 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 } main() { From 33e5974549ef24cb38560f168862ba29dd012067 Mon Sep 17 00:00:00 2001 From: Shlomi Noach Date: Sun, 27 May 2018 20:53:18 +0300 Subject: [PATCH 3/6] working directory --- build.sh | 1 + 1 file changed, 1 insertion(+) diff --git a/build.sh b/build.sh index 3094123..cfc55b8 100755 --- a/build.sh +++ b/build.sh @@ -44,6 +44,7 @@ function build { if [ "$GOOS" == "linux" ] ; then echo "Creating Distro full packages" cp $buildpath/$target $builddir/gh-ost/usr/bin + cd $buildpath 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 From 7da0cbc270993327eb54a506968a5bbd5013fc7b Mon Sep 17 00:00:00 2001 From: Shlomi Noach Date: Sun, 27 May 2018 20:59:58 +0300 Subject: [PATCH 4/6] /tmp/gh-ost-release --- build.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build.sh b/build.sh index cfc55b8..029a946 100755 --- a/build.sh +++ b/build.sh @@ -59,7 +59,7 @@ main() { fi - buildpath=/tmp/gh-ost + buildpath=/tmp/gh-ost-release target=gh-ost timestamp=$(date "+%Y%m%d%H%M%S") ldflags="-X main.AppVersion=${RELEASE_VERSION}" From 0454c5ecb081b24b7a1ce6326ad4e1234ed9bb35 Mon Sep 17 00:00:00 2001 From: Shlomi Noach Date: Sun, 27 May 2018 21:02:00 +0300 Subject: [PATCH 5/6] do not delete during build --- build.sh | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/build.sh b/build.sh index 029a946..78b2481 100755 --- a/build.sh +++ b/build.sh @@ -7,8 +7,6 @@ buildpath= builddir= function setuptree() { - mkdir -p $buildpath - rm -rf ${buildpath:?}/* b=$( mktemp -d $buildpath/gh-ostXXXXXX ) || return 1 mkdir -p $b/gh-ost mkdir -p $b/gh-ost/usr/bin @@ -65,6 +63,7 @@ main() { ldflags="-X main.AppVersion=${RELEASE_VERSION}" mkdir -p ${buildpath} + rm -rf ${buildpath:?}/* build macOS osx darwin amd64 build GNU/Linux linux linux amd64 From 609890aec1d81781eec2684ddb4e8445fa39a1e9 Mon Sep 17 00:00:00 2001 From: Shlomi Noach Date: Sun, 27 May 2018 21:03:44 +0300 Subject: [PATCH 6/6] only create builddir for linux --- build.sh | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/build.sh b/build.sh index 78b2481..264620b 100755 --- a/build.sh +++ b/build.sh @@ -4,7 +4,6 @@ RELEASE_VERSION= buildpath= -builddir= function setuptree() { b=$( mktemp -d $buildpath/gh-ostXXXXXX ) || return 1 @@ -19,7 +18,6 @@ function build { GOOS=$3 GOARCH=$4 - builddir=$(setuptree) if ! go version | egrep -q 'go(1[.]9|1[.]1[0-9])' ; then @@ -41,6 +39,7 @@ function build { if [ "$GOOS" == "linux" ] ; then echo "Creating Distro full packages" + builddir=$(setuptree) cp $buildpath/$target $builddir/gh-ost/usr/bin cd $buildpath 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 .