fix: Improve deployment script (#1043)

* chore: update Makefile for improved build process and add testing commands

* chore: add git checks to dev_release for branch and status validation

* chore: enhance dev_release with gh CLI checks and release creation

* chore: update dev_release to use versioned tags for Git and GitHub releases

* chore: refactor deploy script to use version argument and improve deployment process

* chore: update Makefile to version 0.5.0 and enhance release process with confirmation prompts and version bumping

* chore: enhance release process in Makefile with pre-release checks and user confirmation for production releases

* chore: refactor build process in Makefile to streamline development builds with a dedicated inner target

* chore: simplify build_release target in Makefile by removing frontend dependency

* chore: enable automatic version bumping in Makefile by uncommenting git commands

* chore: add pre-release testing prompts in Makefile for both development and production releases

* chore: update Makefile and test_release_on_device.sh to implement a new testing flow for pre-release validation

* chore: update Makefile to ensure consistent version handling in build and release processes
This commit is contained in:
Adam Shiervani
2025-12-05 16:09:05 +01:00
committed by GitHub
parent 29f7fe46cf
commit d89231aeec
3 changed files with 235 additions and 102 deletions
+41 -88
View File
@@ -4,113 +4,66 @@ set -e
SCRIPT_PATH=$(realpath "$(dirname $(realpath "${BASH_SOURCE[0]}"))")
source ${SCRIPT_PATH}/build_utils.sh
function show_help() {
echo "Usage: $0 [options]"
echo "Options:"
echo " -b, --branch <branch> Checkout branch"
echo " --set-as-default Set as default"
echo " --skip-confirmation Skip confirmation"
echo " --help Show help"
}
# Parse command line arguments
CHECKOUT_BRANCH=
VERSION=
SET_AS_DEFAULT=false
SKIP_CONFIRMATION=false
while [[ $# -gt 0 ]]; do
case $1 in
-b|--branch)
CHECKOUT_BRANCH="$2"
shift 2
;;
--set-as-default)
SET_AS_DEFAULT=true
shift
;;
--skip-confirmation)
SKIP_CONFIRMATION=true
shift
;;
-v|--version) VERSION="$2"; shift 2 ;;
--set-as-default) SET_AS_DEFAULT=true; shift ;;
--skip-confirmation) SKIP_CONFIRMATION=true; shift ;;
--help)
show_help
exit 0
;;
*)
echo "Unknown option: $1"
show_help
exit 1
;;
echo "Usage: $0 -v VERSION [--set-as-default] [--skip-confirmation]"
echo " -v VERSION Version to deploy (required)"
echo " --set-as-default Also deploy to root (production only)"
echo " --skip-confirmation Skip confirmation prompt"
exit 0 ;;
*) echo "Unknown option: $1"; exit 1 ;;
esac
done
# Checkout current branch in a new temporary directory
# only popd when exiting the script
TMP_DIR=$(mktemp -d)
trap 'popd > /dev/null && rm -rf ${TMP_DIR}' EXIT
msg_info "Copying repository to a new temporary directory ${TMP_DIR} ..."
# git fetch origin ${CH}ECKOUT_BRANCH:${CHECKOUT_BRANCH}
git clone . ${TMP_DIR}
cp ${SCRIPT_PATH}/versioned.patch ${TMP_DIR}
msg_info "Checking out branch ${CHECKOUT_BRANCH} ..."
pushd ${TMP_DIR} > /dev/null
git checkout ${CHECKOUT_BRANCH}
# CURRENT_BRANCH=$(git rev-parse --abbrev-ref HEAD)
# # Verify branch name matches release/x.x.x or release/x.x.x-dev...
# if [[ ! $CURRENT_BRANCH =~ ^(release|release-cloud-app)/[0-9]+\.[0-9]+\.[0-9]+(-dev[0-9]+)?$ ]]; then
# msg_err "Current branch '$CURRENT_BRANCH' does not match required pattern"
# msg_err "Expected: release/x.x.x OR release/x.x.x-dev20241104123632"
# exit 1
# fi
CURRENT_BRANCH=release/0.5.0
[ -z "$VERSION" ] && { msg_err "Version required. Use -v VERSION"; exit 1; }
GIT_COMMIT=$(git rev-parse HEAD)
BUILD_TIMESTAMP=$(date -u +%FT%T%z)
VERSION=${CURRENT_BRANCH#release/}
VERSION=${VERSION#release-cloud-app/}
if [[ ! $VERSION =~ ^[0-9]+\.[0-9]+\.[0-9]+(-dev[0-9]+)?$ ]]; then
msg_err "Version '$VERSION' does not match required pattern"
msg_err "Expected: x.x.x OR x.x.x-dev20241104123632"
exit 1
fi
# Change to ui directory
cd ui
if [ "$SET_AS_DEFAULT" = true ]; then
# Build for root dist
msg_info "Building for root dist..."
npm ci
npm run build:prod
fi
# Build for versioned dist/v/VERSION
msg_info "Building for dist/v/${VERSION}..."
npm ci
# Build versioned app
msg_info "Building cloud app /v/${VERSION}/..."
npm run build:prod -- --base=/v/${VERSION}/ --outDir dist/v/${VERSION}
# Ask for confirmation
if [ "$SKIP_CONFIRMATION" = false ]; then
read -p "Do you want to deploy the cloud app to production? (y/N): " -n 1 -r
echo ""
if [[ ! $REPLY =~ ^[Yy]$ ]]; then
msg_err "Deployment cancelled."
exit 0
fi
# Build root app if --set-as-default
if [ "$SET_AS_DEFAULT" = true ]; then
msg_info "Building root cloud app..."
npm run build:prod -- --outDir dist/root
fi
# Deploy to production
msg_info "Deploying to r2://jetkvm-cloud-app..."
rclone copyto \
--progress \
--stats=1s \
# Confirmation
if [ "$SKIP_CONFIRMATION" = false ]; then
read -p "Deploy cloud app v${VERSION}? [y/N] " -n 1 -r
echo ""
[[ $REPLY =~ ^[Yy]$ ]] || { msg_err "Cancelled."; exit 0; }
fi
# Deploy versioned
msg_info "Deploying /v/${VERSION}/ to r2://jetkvm-cloud-app/v/${VERSION}..."
rclone copyto --progress \
--header-upload="x-amz-meta-jetkvm-version: ${VERSION}" \
--header-upload="x-amz-meta-jetkvm-build-ref: ${GIT_COMMIT}" \
--header-upload="x-amz-meta-jetkvm-build-timestamp: ${BUILD_TIMESTAMP}" \
dist \
r2://jetkvm-cloud-app
dist/v/${VERSION} r2://jetkvm-cloud-app/v/${VERSION}
msg_ok "Successfully deployed v${VERSION} to production"
# Deploy root if --set-as-default
if [ "$SET_AS_DEFAULT" = true ]; then
msg_info "Deploying root to r2://jetkvm-cloud-app..."
rclone copyto --progress \
--header-upload="x-amz-meta-jetkvm-version: ${VERSION}" \
--header-upload="x-amz-meta-jetkvm-build-ref: ${GIT_COMMIT}" \
--header-upload="x-amz-meta-jetkvm-build-timestamp: ${BUILD_TIMESTAMP}" \
dist/root r2://jetkvm-cloud-app
fi
msg_ok "Deployed cloud app v${VERSION}"
+64
View File
@@ -0,0 +1,64 @@
#!/bin/bash
set -e
DEVICE_IP="$1"
BINARY_PATH="$2"
ACTION="$3" # "deploy", "restore", or "test"
VERSION="$4" # required for "test" action
REMOTE_USER="root"
REMOTE_BIN_PATH="/userdata/jetkvm/bin"
REMOTE_UPDATE_PATH="/userdata/jetkvm"
SSH_OPTS="-o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no -o ConnectTimeout=10"
ssh_cmd() { ssh $SSH_OPTS "${REMOTE_USER}@${DEVICE_IP}" "$@"; }
case "$ACTION" in
deploy)
echo "Backing up current binary..."
ssh_cmd "cp ${REMOTE_BIN_PATH}/jetkvm_app ${REMOTE_BIN_PATH}/jetkvm_app.pre_release_backup 2>/dev/null || true"
echo "Deploying new binary via OTA update mechanism..."
ssh_cmd "cat > ${REMOTE_UPDATE_PATH}/jetkvm_app.update" < "$BINARY_PATH"
echo "Rebooting device..."
ssh_cmd "reboot" || true
;;
restore)
echo "Restoring backup..."
ssh_cmd "cp ${REMOTE_BIN_PATH}/jetkvm_app.pre_release_backup ${REMOTE_BIN_PATH}/jetkvm_app"
echo "Rebooting device..."
ssh_cmd "reboot" || true
;;
test)
# Full interactive test flow
[ -z "$VERSION" ] && { echo "Error: VERSION required for test action"; exit 1; }
echo ""
echo "Deploying $VERSION to $DEVICE_IP..."
"$0" "$DEVICE_IP" "$BINARY_PATH" deploy
echo ""
echo "═══════════════════════════════════════════════════════"
echo " Device is rebooting. Please verify:"
echo "═══════════════════════════════════════════════════════"
echo " Expected version: $VERSION"
echo " Settings page: http://$DEVICE_IP/settings/general"
echo ""
echo " Check that the version shown in the UI matches above."
echo "═══════════════════════════════════════════════════════"
echo ""
read -p "Does the version match and binary work correctly? [y/n] " works
echo "Restoring device to previous binary..."
"$0" "$DEVICE_IP" "$BINARY_PATH" restore
if [ "$works" != "y" ]; then
echo "Test failed."
exit 1
fi
echo "Test passed."
;;
*)
echo "Usage: $0 <device_ip> <binary_path> <deploy|restore|test> [version]"
exit 1
;;
esac