2016-03-23 12:39:24 +01:00
|
|
|
#!/bin/bash
|
2016-03-24 15:11:56 +01:00
|
|
|
#
|
|
|
|
#
|
2016-08-12 13:04:17 +02:00
|
|
|
|
2018-05-27 20:29:09 +03:00
|
|
|
RELEASE_VERSION=
|
2018-05-27 20:49:08 +03: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 12:39:24 +01:00
|
|
|
|
2016-08-12 13:04:17 +02:00
|
|
|
function build {
|
2018-05-27 20:49:08 +03:00
|
|
|
osname=$1
|
|
|
|
osshort=$2
|
|
|
|
GOOS=$3
|
|
|
|
GOARCH=$4
|
2016-08-12 13:04:17 +02:00
|
|
|
|
2022-01-13 16:07:51 +00:00
|
|
|
if ! go version | egrep -q 'go1\.(1[5-9]|[2-9][0-9]{1})' ; then
|
2021-05-25 13:22:28 +02:00
|
|
|
echo "go version must be 1.15 or above"
|
2019-08-12 08:03:17 +03:00
|
|
|
exit 1
|
2018-05-27 20:49:08 +03:00
|
|
|
fi
|
2017-11-23 12:13:25 +02:00
|
|
|
|
2022-03-11 14:10:58 +01:00
|
|
|
echo "Building ${osname}-${GOARCH} binary"
|
2018-05-27 20:49:08 +03:00
|
|
|
export GOOS
|
|
|
|
export GOARCH
|
2021-06-24 20:19:37 +02:00
|
|
|
go build -ldflags "$ldflags" -o $buildpath/$target go/cmd/gh-ost/main.go
|
2016-08-12 13:04:17 +02:00
|
|
|
|
2018-05-27 20:49:08 +03:00
|
|
|
if [ $? -ne 0 ]; then
|
2022-03-11 14:10:58 +01:00
|
|
|
echo "Build failed for ${osname} ${GOARCH}."
|
2018-05-27 20:49:08 +03:00
|
|
|
exit 1
|
|
|
|
fi
|
2016-08-12 13:04:17 +02:00
|
|
|
|
2022-03-11 14:10:58 +01:00
|
|
|
(cd $buildpath && tar cfz ./gh-ost-binary-${osshort}-${GOARCH}-${timestamp}.tar.gz $target)
|
2018-05-27 20:49:08 +03:00
|
|
|
|
2022-07-20 14:47:51 +01:00
|
|
|
# build RPM and deb for Linux, x86-64 only
|
|
|
|
if [ "$GOOS" == "linux" ] && [ "$GOARCH" == "amd64" ] ; then
|
2018-05-27 20:49:08 +03:00
|
|
|
echo "Creating Distro full packages"
|
2018-05-27 21:03:44 +03:00
|
|
|
builddir=$(setuptree)
|
2018-05-27 20:49:08 +03:00
|
|
|
cp $buildpath/$target $builddir/gh-ost/usr/bin
|
2018-05-27 20:53:18 +03:00
|
|
|
cd $buildpath
|
2022-02-25 14:10:42 +00:00
|
|
|
fpm -v "${RELEASE_VERSION}" --epoch 1 -f -s dir -n gh-ost -m 'GitHub' --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 --rpm-rpmbuild-define "_build_id_links none" --rpm-os linux .
|
2022-01-18 16:15:36 +00:00
|
|
|
fpm -v "${RELEASE_VERSION}" --epoch 1 -f -s dir -n gh-ost -m 'GitHub' --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 .
|
|
|
|
cd -
|
2018-05-27 20:49:08 +03:00
|
|
|
fi
|
2016-08-12 13:04:17 +02:00
|
|
|
}
|
|
|
|
|
2018-05-27 20:29:09 +03: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 12:39:24 +01:00
|
|
|
|
|
|
|
|
2018-05-27 20:59:58 +03:00
|
|
|
buildpath=/tmp/gh-ost-release
|
2018-05-27 20:29:09 +03:00
|
|
|
target=gh-ost
|
|
|
|
timestamp=$(date "+%Y%m%d%H%M%S")
|
|
|
|
ldflags="-X main.AppVersion=${RELEASE_VERSION}"
|
|
|
|
|
|
|
|
mkdir -p ${buildpath}
|
2018-05-27 21:02:00 +03:00
|
|
|
rm -rf ${buildpath:?}/*
|
2018-05-27 20:29:09 +03:00
|
|
|
build GNU/Linux linux linux amd64
|
2022-03-11 14:10:58 +01:00
|
|
|
build GNU/Linux linux linux arm64
|
2022-01-18 16:15:36 +00:00
|
|
|
build macOS osx darwin amd64
|
2022-03-11 14:10:58 +01:00
|
|
|
build macOS osx darwin arm64
|
2018-05-27 20:29:09 +03:00
|
|
|
|
|
|
|
echo "Binaries found in:"
|
2020-02-09 16:11:34 +02:00
|
|
|
find $buildpath/gh-ost* -type f -maxdepth 1
|
2022-01-18 16:15:36 +00:00
|
|
|
|
|
|
|
echo "Checksums:"
|
|
|
|
(cd $buildpath && shasum -a256 gh-ost* 2>/dev/null)
|
2018-05-27 20:29:09 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
main "$@"
|