Skip to content

Commit 582e44a

Browse files
author
Shlomi Noach
authored
Merge pull request #599 from github/build-packaging
Build packaging
2 parents bba8b25 + 609890a commit 582e44a

File tree

1 file changed

+59
-27
lines changed

1 file changed

+59
-27
lines changed

build.sh

Lines changed: 59 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -2,40 +2,72 @@
22
#
33
#
44

5-
RELEASE_VERSION=$(cat RELEASE_VERSION)
5+
RELEASE_VERSION=
6+
buildpath=
7+
8+
function setuptree() {
9+
b=$( mktemp -d $buildpath/gh-ostXXXXXX ) || return 1
10+
mkdir -p $b/gh-ost
11+
mkdir -p $b/gh-ost/usr/bin
12+
echo $b
13+
}
614

715
function build {
8-
osname=$1
9-
osshort=$2
10-
GOOS=$3
11-
GOARCH=$4
16+
osname=$1
17+
osshort=$2
18+
GOOS=$3
19+
GOARCH=$4
1220

13-
if ! go version | egrep -q 'go(1[.]9|1[.]1[0-9])' ; then
14-
echo "go version is too low. Must use 1.9 or above"
15-
exit 1
16-
fi
1721

18-
echo "Building ${osname} binary"
19-
export GOOS
20-
export GOARCH
21-
go build -ldflags "$ldflags" -o $buildpath/$target go/cmd/gh-ost/main.go
2222

23-
if [ $? -ne 0 ]; then
24-
echo "Build failed for ${osname}"
25-
exit 1
26-
fi
23+
if ! go version | egrep -q 'go(1[.]9|1[.]1[0-9])' ; then
24+
echo "go version is too low. Must use 1.9 or above"
25+
exit 1
26+
fi
27+
28+
echo "Building ${osname} binary"
29+
export GOOS
30+
export GOARCH
31+
go build -ldflags "$ldflags" -o $buildpath/$target go/cmd/gh-ost/main.go
32+
33+
if [ $? -ne 0 ]; then
34+
echo "Build failed for ${osname}"
35+
exit 1
36+
fi
2737

28-
(cd $buildpath && tar cfz ./gh-ost-binary-${osshort}-${timestamp}.tar.gz $target)
38+
(cd $buildpath && tar cfz ./gh-ost-binary-${osshort}-${timestamp}.tar.gz $target)
39+
40+
if [ "$GOOS" == "linux" ] ; then
41+
echo "Creating Distro full packages"
42+
builddir=$(setuptree)
43+
cp $buildpath/$target $builddir/gh-ost/usr/bin
44+
cd $buildpath
45+
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 .
46+
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 .
47+
fi
2948
}
3049

31-
buildpath=/tmp/gh-ost
32-
target=gh-ost
33-
timestamp=$(date "+%Y%m%d%H%M%S")
34-
ldflags="-X main.AppVersion=${RELEASE_VERSION}"
50+
main() {
51+
if [ -z "${RELEASE_VERSION}" ] ; then
52+
RELEASE_VERSION=$(git describe --abbrev=0 --tags | tr -d 'v')
53+
fi
54+
if [ -z "${RELEASE_VERSION}" ] ; then
55+
RELEASE_VERSION=$(cat RELEASE_VERSION)
56+
fi
57+
58+
59+
buildpath=/tmp/gh-ost-release
60+
target=gh-ost
61+
timestamp=$(date "+%Y%m%d%H%M%S")
62+
ldflags="-X main.AppVersion=${RELEASE_VERSION}"
3563

36-
mkdir -p ${buildpath}
37-
build macOS osx darwin amd64
38-
build GNU/Linux linux linux amd64
64+
mkdir -p ${buildpath}
65+
rm -rf ${buildpath:?}/*
66+
build macOS osx darwin amd64
67+
build GNU/Linux linux linux amd64
68+
69+
echo "Binaries found in:"
70+
ls -1 $buildpath/gh-ost-binary*${timestamp}.tar.gz
71+
}
3972

40-
echo "Binaries found in:"
41-
ls -1 $buildpath/gh-ost-binary*${timestamp}.tar.gz
73+
main "$@"

0 commit comments

Comments
 (0)