Skip to content

Commit

Permalink
packer/build_images.sh: get version and release values from pipline
Browse files Browse the repository at this point in the history
related to changes in scylladb/scylla-pkg#4635,
modifying the script to get `version` and `release` values from the
pipeline to remove the constrain between dpackager OS and image OS

Should be merged together with scylladb/scylla-pkg#4635
  • Loading branch information
yaronkaikov committed Dec 2, 2024
1 parent 10adaa1 commit 1675f57
Showing 1 changed file with 21 additions and 37 deletions.
58 changes: 21 additions & 37 deletions packer/build_image.sh
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,21 @@ while [ $# -gt 0 ]; do
echo "--build-tag parameter: BUILD_TAG |$BUILD_TAG|"
shift 2
;;
"--version")
VERSION=$2
echo "--version: VERSION |$VERSION|"
shift 2
;;
"--scylla-release")
SCYLLA_RELEASE=$2
echo "--scylla-release: SCYLLA_RELEASE |$SCYLLA_RELEASE|"
shift 2
;;
"--scylla-machine-image-release")
SCYLLA_MACHINE_IMAGE_RELEASE=$2
echo "--scylla-machine-image-release: SCYLLA_MACHINE_IMAGE_RELEASE |$SCYLLA_MACHINE_IMAGE_RELEASE|"
shift 2
;;
"--branch")
BRANCH=$2
echo "--branch parameter: BRANCH |$BRANCH|"
Expand Down Expand Up @@ -155,23 +170,10 @@ done
if [ -z "$PRODUCT" ]; then
PRODUCT=$(cat build/SCYLLA-PRODUCT-FILE)
fi
VERSION=$(cat build/SCYLLA-VERSION-FILE)
INSTALL_ARGS="$INSTALL_ARGS --product $PRODUCT"

echo "INSTALL_ARGS: |$INSTALL_ARGS|"

get_version_from_local_deb () {
DEB=$1
FULL_VERSION=$(dpkg -f "$DEB" version)
echo "$FULL_VERSION"
}

get_version_from_remote_deb () {
DEB=$1
FULL_VERSION=$(sudo apt-cache madison "$DEB"|head -n1|awk '{print $3}')
echo "$FULL_VERSION"
}

deb_arch() {
declare -A darch
darch=(["x86_64"]=amd64 ["aarch64"]=arm64)
Expand All @@ -190,31 +192,21 @@ check_deb_exists () {
done
}

import_gpg_key () {
echo "Importing apt key ($APT_KEY)"
TMPREPO=$(mktemp -u -p /etc/apt/sources.list.d/ --suffix .list)
sudo curl -sSo $TMPREPO $REPO_FOR_INSTALL
sudo mkdir -p $APT_KEYS_DIR
sudo gpg --homedir /tmp --no-default-keyring --keyring $APT_KEYS_DIR/scylladb.gpg --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys $APT_KEY
sudo apt-get update -y
}

if [ -z "$TARGET" ]; then
echo "Missing --target parameter. Please specify target cloud (aws/gce/azure)"
exit 1
fi

SSH_USERNAME=ubuntu

SCYLLA_FULL_VERSION="$VERSION-$SCYLLA_RELEASE"
SCYLLA_MACHINE_IMAGE_VERSION="$VERSION-$SCYLLA_MACHINE_IMAGE_RELEASE"

if [ $LOCALDEB -eq 1 ]; then
INSTALL_ARGS="$INSTALL_ARGS --localdeb"

check_deb_exists "$DIR"/files

SCYLLA_FULL_VERSION=$(get_version_from_local_deb "$DIR"/files/"$PRODUCT"-server*_$(deb_arch).deb)
SCYLLA_MACHINE_IMAGE_VERSION=$(get_version_from_local_deb "$DIR"/files/"$PRODUCT"-machine-image*_all.deb)
SCYLLA_PYTHON3_VERSION=$(get_version_from_local_deb "$DIR"/files/"$PRODUCT"-python3*_$(deb_arch).deb)

cd "$DIR"/files
dpkg-scanpackages . /dev/null | gzip -9c > Packages.gz
cd -
Expand All @@ -225,8 +217,6 @@ elif [ $DOWNLOAD_ONLY -eq 1 ]; then
exit 1
fi

import_gpg_key

cd "$DIR"/files
apt-get download --allow-unauthenticated "$PRODUCT" "$PRODUCT"-machine-image "$PRODUCT"-python3
sudo rm -f $TMPREPO
Expand All @@ -238,12 +228,6 @@ else
exit 1
fi

import_gpg_key

SCYLLA_FULL_VERSION=$(get_version_from_remote_deb $PRODUCT-server)
SCYLLA_MACHINE_IMAGE_VERSION=$(get_version_from_remote_deb $PRODUCT-machine-image)
SCYLLA_PYTHON3_VERSION=$(get_version_from_remote_deb $PRODUCT-python3)

sudo rm -f $TMPREPO

fi
Expand Down Expand Up @@ -273,7 +257,7 @@ if [ "$TARGET" = "aws" ]; then
exit 1
esac

SCYLLA_AMI_DESCRIPTION="scylla-$SCYLLA_FULL_VERSION scylla-machine-image-$SCYLLA_MACHINE_IMAGE_VERSION scylla-python3-$SCYLLA_PYTHON3_VERSION"
SCYLLA_AMI_DESCRIPTION="scylla-$SCYLLA_FULL_VERSION scylla-machine-image-$SCYLLA_MACHINE_IMAGE_VERSION scylla-python3-$SCYLLA_FULL_VERSION"

PACKER_ARGS+=(-var region="$REGION")
PACKER_ARGS+=(-var buildMode="$BUILD_MODE")
Expand All @@ -289,7 +273,7 @@ elif [ "$TARGET" = "gce" ]; then
elif [ "$TARGET" = "azure" ]; then
REGION="EAST US"
SSH_USERNAME=azureuser
SCYLLA_IMAGE_DESCRIPTION="scylla-$SCYLLA_FULL_VERSION scylla-machine-image-$SCYLLA_MACHINE_IMAGE_VERSION scylla-python3-$SCYLLA_PYTHON3_VERSION"
SCYLLA_IMAGE_DESCRIPTION="scylla-$SCYLLA_FULL_VERSION scylla-machine-image-$SCYLLA_MACHINE_IMAGE_VERSION scylla-python3-$SCYLLA_FULL_VERSION"

PACKER_ARGS+=(-var scylla_image_description="${SCYLLA_IMAGE_DESCRIPTION:0:255}")
PACKER_ARGS+=(-var client_id="$AZURE_CLIENT_ID")
Expand Down Expand Up @@ -334,7 +318,7 @@ set -x
-var scylla_full_version="$SCYLLA_FULL_VERSION" \
-var scylla_version="$VERSION" \
-var scylla_machine_image_version="$SCYLLA_MACHINE_IMAGE_VERSION" \
-var scylla_python3_version="$SCYLLA_PYTHON3_VERSION" \
-var scylla_python3_version="$SCYLLA_FULL_VERSION" \
-var creation_timestamp="$CREATION_TIMESTAMP" \
-var scylla_build_sha_id="$SCYLLA_BUILD_SHA_ID" \
-var build_tag="$BUILD_TAG" \
Expand Down

0 comments on commit 1675f57

Please sign in to comment.