pvc/build-and-deploy.sh

79 lines
2.2 KiB
Bash
Raw Normal View History

2023-10-17 10:35:38 -04:00
#!/usr/bin/env bash
# A useful script for testing out changes to PVC by building the debs and deploying them out to a
# set of hosts automatically, including restarting the daemon (with a pause between) on the remote
# side. Mostly just useful for quickly testing/debugging changes as Ansible should be used for
# production upgrades.
# Check if we're root, or not
if [[ $( id -u ) -eq 0 ]]; then
SUDO=""
else
SUDO="sudo"
fi
KEEP_ARTIFACTS=""
if [[ -n ${1} ]]; then
for arg in ${@}; do
case ${arg} in
-k|--keep)
KEEP_ARTIFACTS="y"
shift
;;
esac
done
fi
HOSTS=( ${@} )
echo "> Deploying to host(s): ${HOSTS[@]}"
# Move to repo root if we're not
pushd $( git rev-parse --show-toplevel ) &>/dev/null
# Prepare code
echo "Preparing code (format and lint)..."
./format || exit 1
./lint || exit 1
2021-10-27 13:25:14 -04:00
# Build the packages
2023-10-23 22:23:48 -04:00
echo -n "Building packages..."
version="$( ./build-unstable-deb.sh 2>/dev/null )"
2023-10-23 22:23:48 -04:00
echo " done. Package version ${version}."
# Install the client(s) locally
2023-10-23 22:23:48 -04:00
echo -n "Installing client packages locally..."
$SUDO dpkg -i ../pvc-client*_${version}*.deb &>/dev/null
2023-10-23 22:23:48 -04:00
echo " done".
for HOST in ${HOSTS[@]}; do
echo -n "Copying packages to host ${HOST}..."
ssh $HOST $SUDO rm -rf /tmp/pvc &>/dev/null
ssh $HOST mkdir /tmp/pvc &>/dev/null
scp ../pvc-*_${version}*.deb $HOST:/tmp/pvc/ &>/dev/null
2023-10-23 22:23:48 -04:00
echo " done."
done
if [[ -z ${KEEP_ARTIFACTS} ]]; then
rm ../pvc*_${version}*
fi
for HOST in ${HOSTS[@]}; do
echo "> Deploying packages to host ${HOST}"
2023-10-23 22:23:48 -04:00
echo -n "Installing packages..."
ssh $HOST $SUDO dpkg -i /tmp/pvc/{pvc-client-cli,pvc-daemon-common,pvc-daemon-api,pvc-daemon-node}*.deb &>/dev/null
ssh $HOST rm -rf /tmp/pvc &>/dev/null
2023-10-23 22:23:48 -04:00
echo " done."
echo -n "Restarting PVC daemons..."
ssh $HOST $SUDO systemctl restart pvcapid &>/dev/null
2023-11-15 19:13:48 -05:00
ssh $HOST $SUDO systemctl restart pvcworkerd &>/dev/null
ssh $HOST $SUDO systemctl restart pvcnoded &>/dev/null
2023-10-23 22:23:48 -04:00
echo " done."
echo -n "Waiting for node daemon to be running..."
2023-11-16 18:30:32 -05:00
while [[ $( ssh $HOST "pvc -q node list -f json ${HOST%%.*} | jq -r '.[].daemon_state'" 2>/dev/null ) != "run" ]]; do
2023-10-23 22:23:48 -04:00
sleep 5
echo -n "."
done
echo " done."
done
popd &>/dev/null