simplify deploy script with atomic deployment
Completely rewrote deploy script to be simpler and safer: - Requires directory to exist (no automatic creation) - Builds and extracts to /tmp/ FIRST - Only clears target directory after build/extract succeeds - If build fails, existing deployment stays untouched Usage: sudo mkdir -p /opt/jr_test ./deploy.sh /opt/jr_test This atomic approach prevents broken deployments from failed builds. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
This commit is contained in:
parent
c6d34847d5
commit
a9bd96b377
54
deploy.sh
54
deploy.sh
@ -1,57 +1,39 @@
|
||||
#!/bin/bash
|
||||
set -e
|
||||
|
||||
# Default deployment directory
|
||||
DEPLOY_DIR="${1:-/opt/jrunner}"
|
||||
|
||||
# Safety checks
|
||||
if [ -z "${DEPLOY_DIR}" ]; then
|
||||
echo "Error: Deployment directory cannot be empty"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Prevent deleting critical system directories
|
||||
case "${DEPLOY_DIR}" in
|
||||
/|/bin|/boot|/dev|/etc|/lib|/lib64|/proc|/root|/run|/sbin|/sys|/usr|/var|/home)
|
||||
/|/bin|/boot|/dev|/etc|/lib|/lib64|/proc|/root|/run|/sbin|/sys|/usr|/var)
|
||||
echo "Error: Cannot deploy to system directory: ${DEPLOY_DIR}"
|
||||
exit 1
|
||||
;;
|
||||
esac
|
||||
|
||||
if [ ! -d "${DEPLOY_DIR}" ]; then
|
||||
echo "Error: Directory does not exist: ${DEPLOY_DIR}"
|
||||
echo "Create it first: sudo mkdir -p ${DEPLOY_DIR}"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
echo "Building jrunner..."
|
||||
./gradlew build
|
||||
|
||||
echo "Extracting to temporary location..."
|
||||
sudo rm -rf /tmp/jrunner
|
||||
sudo unzip -q jrunner/build/distributions/jrunner.zip -d /tmp/
|
||||
|
||||
echo "Deploying to ${DEPLOY_DIR}..."
|
||||
sudo rm -rf "${DEPLOY_DIR}"/*
|
||||
sudo mv /tmp/jrunner/* "${DEPLOY_DIR}"/
|
||||
sudo rm -rf /tmp/jrunner
|
||||
|
||||
# Remove both target and intermediate jrunner directory if they exist
|
||||
if [ -d "${DEPLOY_DIR}" ]; then
|
||||
echo "Removing existing deployment at ${DEPLOY_DIR}..."
|
||||
sudo rm -rf "${DEPLOY_DIR}"
|
||||
fi
|
||||
|
||||
PARENT_DIR="$(dirname "${DEPLOY_DIR}")"
|
||||
EXTRACT_DIR="${PARENT_DIR}/jrunner"
|
||||
|
||||
if [ -d "${EXTRACT_DIR}" ] && [ "${EXTRACT_DIR}" != "${DEPLOY_DIR}" ]; then
|
||||
echo "Removing existing jrunner directory at ${EXTRACT_DIR}..."
|
||||
sudo rm -rf "${EXTRACT_DIR}"
|
||||
fi
|
||||
|
||||
# Extract and rename if needed
|
||||
sudo mkdir -p "${PARENT_DIR}"
|
||||
sudo unzip -q jrunner/build/distributions/jrunner.zip -d "${PARENT_DIR}"
|
||||
|
||||
if [ "$(basename "${DEPLOY_DIR}")" != "jrunner" ]; then
|
||||
sudo mv "${EXTRACT_DIR}" "${DEPLOY_DIR}"
|
||||
fi
|
||||
|
||||
# Only create symlink for default location
|
||||
# Only create symlink for /opt/jrunner
|
||||
if [ "${DEPLOY_DIR}" = "/opt/jrunner" ]; then
|
||||
echo "Creating symlink..."
|
||||
sudo ln -sf /opt/jrunner/bin/jrunner /usr/local/bin/jrunner
|
||||
echo "✅ Deployment complete!"
|
||||
echo "Run 'jrunner --help' to test"
|
||||
else
|
||||
echo "✅ Deployment complete!"
|
||||
echo "Run '${DEPLOY_DIR}/bin/jrunner --help' to test"
|
||||
fi
|
||||
|
||||
echo "✅ Deployed to ${DEPLOY_DIR}"
|
||||
echo "Run '${DEPLOY_DIR}/bin/jrunner --help' to test"
|
||||
|
||||
Loading…
Reference in New Issue
Block a user