#!/bin/bash # Makes the Debian deb package and optionally adds it to the public repository. # First builds the debian packager Docker image (which extends and includes the # agent bundle) and then runs "debuild" which does the heavy lifting of # actually building the deb package. set -exuo pipefail SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" . $SCRIPT_DIR/../../scripts/common.sh REPO_STAGE=${1:-test} TARGET_ARCH="amd64" if [ `uname -m` == "aarch64" ]; then TARGET_ARCH="arm64" fi 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*-deb[0-9]' 2>/dev/null || true) deb_revision=1 if [[ -n $current_commit_tag ]]; then if grep -q -- '-deb[0-9]$' <<< "$current_commit_tag"; then deb_revision=$(sed -e "s/v.*-deb//" <<< "$current_commit_tag") fi agent_version=$(echo -n "$current_commit_tag" | sed -e "s/-deb[0-9]//" | sed -e "s/^v//") else agent_version=$($SCRIPT_DIR/../../scripts/current-version) fi GPG_DIR=${GPG_DIR:-"$HOME/.gnupg"} image_name=signalfx-agent-debian-packager image_tag=${agent_version}-deb${deb_revision} package_version=${agent_version}-${deb_revision} COLLECTD_VERSION=${COLLECTD_VERSION} COLLECTD_COMMIT=${COLLECTD_COMMIT} do_docker_build ${image_name} ${image_tag} debian-packager $agent_version OUTPUT_DIR=${OUTPUT_DIR:-$SCRIPT_DIR/output} create_deb() { output_prefix="$OUTPUT_DIR/signalfx-agent_${package_version}_${TARGET_ARCH}" find $OUTPUT_DIR -type f | xargs rm || true docker run --rm \ -v ${SCRIPT_DIR}/../../.git:/git-repo:ro \ -v ${OUTPUT_DIR}:/output \ $image_name:$image_tag \ bash -e -c \ "./make-changelog $agent_version $deb_revision && debuild -us -uc && cp -f ../*.{changes,build,buildinfo,deb} /output" if ! test -e $output_prefix.deb then echo "Could not find output package, something went wrong" >&2 exit 1 fi echo "SignalFx Agent ${package_version} built 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-deb-cache:/repo \ -it \ $image_name:$image_tag \ bash -e -c "./add-output-to-repo $REPO_STAGE" } if [[ ${BUILD_DEB-yes} == "yes" ]]; then create_deb 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