#!/bin/bash # Builds the agent RPM package and optionally adds it to the public yum repo.. # First builds the RPM packager Docker image (which extends and includes the # agent bundle) and then runs "rpmbuild" which does the heavy lifting of # actually building the package. set -exuo pipefail SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" . $SCRIPT_DIR/../../scripts/common.sh REPO_STAGE=${1:-test} cpu_arch="$(uname -m)" case $REPO_STAGE in final|beta|test) ;; *) echo "REPO_STAGE must be 'final', 'beta' or 'test'" >&2 && exit 1 ;; esac current_commit_tag=$(git describe --abbrev=0 --tags --exact-match --match 'v*-rpm[0-9]' 2>/dev/null || true) rpm_revision=1 if [[ -n $current_commit_tag ]]; then if grep -q -- '-rpm[0-9]$' <<< "$current_commit_tag"; then rpm_revision=$(sed -e "s/v.*-rpm//" <<< "$current_commit_tag") fi agent_version=$(echo -n "$current_commit_tag" | sed -e "s/-rpm[0-9]$//" | sed -e "s/^v//") else agent_version=$($SCRIPT_DIR/../../scripts/current-version) fi # RPM really dislikes dashes in version names, so replace them with tilde if # any (e.g. in beta releases). clean_agent_version=$(echo "$agent_version" | sed -e 's/-/~/g') GPG_DIR=${GPG_DIR:-"$HOME/.gnupg"} image_name=signalfx-agent-rpm-packager image_tag=${agent_version}-rpm${rpm_revision} COLLECTD_VERSION=${COLLECTD_VERSION} COLLECTD_COMMIT=${COLLECTD_COMMIT} do_docker_build ${image_name} ${image_tag} rpm-packager $agent_version OUTPUT_DIR=${OUTPUT_DIR:-$SCRIPT_DIR/output} create_rpm() { find ${OUTPUT_DIR}/x86_64 -name "*.rpm" | xargs rm || true docker run --rm \ -v ${OUTPUT_DIR}:/output \ $image_name:$image_tag \ rpmbuild -bb \ --nodeps \ --define "_version $clean_agent_version" \ --define "_release $rpm_revision" \ --define "_rpmdir /output" \ SPECS/signalfx-agent.spec if ! test -e ${OUTPUT_DIR}/${cpu_arch}/signalfx-agent-${clean_agent_version}-${rpm_revision}.${cpu_arch}.rpm then echo "Could not find output package, something went wrong" >&2 exit 1 fi echo "SignalFx Agent ${agent_version}-${rpm_revision} build successfully. Output is in ${OUTPUT_DIR}." } push_to_repo() { docker run --rm \ -v $HOME/.gnupg:/root/.gnupg \ -v $HOME/.aws:/root/.aws \ -v ${OUTPUT_DIR}:/output \ -v /opt/signalfx-agent-rpm-cache:/repo \ -it \ $image_name:$image_tag \ bash -e -c "./add-output-to-repo $REPO_STAGE" } if [[ ${BUILD_RPM-yes} == "yes" ]]; then create_rpm fi if [[ "${PUSH_TO_REPO-}" == "yes" ]]; then if [[ ! "$agent_version" =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]] && [[ "$REPO_STAGE" = "final" ]]; then echo "Only final releases should go to the final package repo" >&2 exit 2 fi if [[ "$agent_version" =~ ^[0-9]+\.[0-9]+\.[0-9]+-post$ ]] && [[ "$REPO_STAGE" = "beta" ]]; then echo "Only beta or final releases should go to the beta package repo" >&2 exit 3 fi push_to_repo fi