Skip to content

Commit

Permalink
Modify the grove/build/build_rpm.sh script to incorporate the
Browse files Browse the repository at this point in the history
last 9 digit commit hash on the grove/ directory as the release
when building the grove rpm.
  • Loading branch information
jrushford authored and dangogh committed Jul 3, 2018
1 parent a8c364c commit e8fa8ea
Show file tree
Hide file tree
Showing 2 changed files with 77 additions and 32 deletions.
107 changes: 76 additions & 31 deletions grove/build/build_rpm.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,44 +12,89 @@
# See the License for the specific language governing permissions and
# limitations under the License.

ROOTDIR=$(git rev-parse --show-toplevel)
[ ! -z "$ROOTDIR" ] || { echo "Cannot find repository root." >&2 ; exit 1; }
#----------------------------------------
function importFunctions() {
TC_DIR=$(git rev-parse --show-toplevel)
[ ! -z "$TC_DIR" ] || { echo "Cannot find repository root." >&2 ; exit 1; }
export TC_DIR
functions_sh="$TC_DIR/build/functions.sh"
if [[ ! -r $functions_sh ]]; then
echo "Error: Can't find $functions_sh"
exit 1
fi
. "$functions_sh"
}

cd "$ROOTDIR/grove"
#----------------------------------------
function checkGroveEnvironment() {
echo "Verifying the build configuration environment."
local script=$(readlink -f "$0")
local scriptdir=$(dirname "$script")

BUILDDIR="$ROOTDIR/grove/rpmbuild"
VERSION=`cat ./VERSION`.`git rev-list --all --count`
export GROVE_DIR=$(dirname "$scriptdir")
export GROVE_VERSION=`cat ${GROVE_DIR}/VERSION`
export PACKAGE="grove"
export BUILD_NUMBER=${BUILD_NUMBER:-$(getBuildNumber)}
export RPMBUILD="${GROVE_DIR}/rpmbuild"
export DIST="${TC_DIR}/dist"
export RPM="${PACKAGE}-${GROVE_VERSION}-${BUILD_NUMBER}.x86_64.rpm"

# prep build environment
[ -e $BUILDDIR ] && rm -rf $BUILDDIR
[ ! -e $BUILDDIR ] || { echo "Failed to clean up rpm build directory '$BUILDDIR': $?" >&2; exit 1; }
mkdir -p $BUILDDIR/{BUILD,RPMS,SOURCES} || { echo "Failed to create build directory '$BUILDDIR': $?" >&2; exit 1; }
echo "=================================================="
echo "TC_DIR: $TC_DIR"
echo "PACKAGE: $PACKAGE"
echo "GROVE_DIR: $GROVE_DIR"
echo "GROVE_VERSION: $GROVE_VERSION"
echo "BUILD_NUMBER: $BUILD_NUMBER"
echo "DIST: $DIST"
echo "RPM: $RPM"
echo "RPMBUILD: $RPMBUILD"
echo "--------------------------------------------------"
}

# build
go get -v -d . || { echo "Failed to go get dependencies: $?" >&2; exit 1; }
go build -v -ldflags "-X main.Version=$VERSION" || { echo "Failed to build grove: $?" >&2; exit 1; }
# ---------------------------------------
function initBuildArea() {
cd "$GROVE_DIR"

# tar
tar -cvzf $BUILDDIR/SOURCES/grove-${VERSION}.tgz grove conf/grove.cfg build/grove.init build/grove.logrotate || { echo "Failed to create archive for rpmbuild: $?" >&2; exit 1; }
# prep build environment
[ -e $RPMBUILD ] && rm -rf $RPMBUILD
[ ! -e $RPMBUILD ] || { echo "Failed to clean up rpm build directory '$RPMBUILD': $?" >&2; exit 1; }
mkdir -p $RPMBUILD/{BUILD,RPMS,SOURCES} || { echo "Failed to create build directory '$RPMBUILD': $?" >&2; exit 1; }
}

# Work around bug in rpmbuild. Fixed in rpmbuild 4.13.
# See: https://github.com/rpm-software-management/rpm/commit/916d528b0bfcb33747e81a57021e01586aa82139
# Takes ownership of the spec file.
spec=build/grove.spec
spec_owner=$(stat -c%u $spec)
spec_group=$(stat -c%g $spec)
if ! id $spec_owner >/dev/null 2>&1; then
chown $(id -u):$(id -g) build/grove.spec
# ---------------------------------------
function buildRpmGrove() {
# build
go get -v -d . || { echo "Failed to go get dependencies: $?" >&2; exit 1; }
go build -v -ldflags "-X main.Version=$GROVE_VERSION" || { echo "Failed to build grove: $?" >&2; exit 1; }

function give_spec_back {
# tar
tar -cvzf $RPMBUILD/SOURCES/grove-${GROVE_VERSION}.tgz grove conf/grove.cfg build/grove.init build/grove.logrotate || { echo "Failed to create archive for rpmbuild: $?" >&2; exit 1; }

# Work around bug in rpmbuild. Fixed in rpmbuild 4.13.
# See: https://github.com/rpm-software-management/rpm/commit/916d528b0bfcb33747e81a57021e01586aa82139
# Takes ownership of the spec file.
spec=build/grove.spec
spec_owner=$(stat -c%u $spec)
spec_group=$(stat -c%g $spec)
if ! id $spec_owner >/dev/null 2>&1; then
chown $(id -u):$(id -g) build/grove.spec

function give_spec_back {
chown ${spec_owner}:${spec_group} build/grove.spec
}
trap give_spec_back EXIT
fi
}
trap give_spec_back EXIT
fi

# build RPM
rpmbuild --define "_topdir $RPMBUILD" --define "version ${GROVE_VERSION}" --define "build_number ${BUILD_NUMBER}" -ba build/grove.spec || { echo "rpmbuild failed: $?" >&2; exit 1; }

# copy build RPM to .
[ -e $DIST ] || mkdir -p $DIST
cp $RPMBUILD/RPMS/x86_64/${RPM} $DIST
}

# build RPM
rpmbuild --define "_topdir $BUILDDIR" --define "version ${VERSION}" -ba build/grove.spec || { echo "rpmbuild failed: $?" >&2; exit 1; }
importFunctions
checkGroveEnvironment
initBuildArea
buildRpmGrove

# copy build RPM to .
[ -e ../dist ] || mkdir -p ../dist
cp $BUILDDIR/RPMS/x86_64/grove-${VERSION}-1.x86_64.rpm ../dist
2 changes: 1 addition & 1 deletion grove/build/grove.spec
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
Summary: Grove HTTP Caching Proxy
Name: grove
Version: %{version}
Release: 1
Release: %{build_number}
License: Apache License, Version 2.0
Group: Base System/System Tools
Prefix: /usr/sbin/%{name}
Expand Down

0 comments on commit e8fa8ea

Please sign in to comment.