Add redeploy script for enabled apps
This commit is contained in:
Executable
+76
@@ -0,0 +1,76 @@
|
|||||||
|
#!/usr/bin/env bash
|
||||||
|
set -euo pipefail
|
||||||
|
|
||||||
|
APPFACTORY_ROOT="/opt/appfactory"
|
||||||
|
ENV_FILE="$APPFACTORY_ROOT/config/appfactory.env"
|
||||||
|
|
||||||
|
log(){ echo "[redeploy-enabled-apps] $*"; }
|
||||||
|
ok(){ echo "[redeploy-enabled-apps][OK] $*"; }
|
||||||
|
warn(){ echo "[redeploy-enabled-apps][WARN] $*"; }
|
||||||
|
fail(){ echo "[redeploy-enabled-apps][FAIL] $*" >&2; exit 1; }
|
||||||
|
|
||||||
|
[ -f "$ENV_FILE" ] || fail "Missing env file: $ENV_FILE"
|
||||||
|
|
||||||
|
set -a
|
||||||
|
# shellcheck disable=SC1090
|
||||||
|
source "$ENV_FILE"
|
||||||
|
set +a
|
||||||
|
|
||||||
|
APPFACTORY_DIR="${APPFACTORY_DIR:-/opt/appfactory}"
|
||||||
|
WORKSPACE_DIR="${WORKSPACE_DIR:-$APPFACTORY_DIR/workspace}"
|
||||||
|
DB_FILE="$APPFACTORY_DIR/data/appfactory/appfactory.db"
|
||||||
|
DEPLOY_SCRIPT="$APPFACTORY_DIR/workspace/appfactory-tools/scripts/deploy-core-service.sh"
|
||||||
|
|
||||||
|
[ -f "$DB_FILE" ] || fail "Missing AppFactory DB: $DB_FILE"
|
||||||
|
[ -f "$DEPLOY_SCRIPT" ] || fail "Missing deploy script: $DEPLOY_SCRIPT"
|
||||||
|
|
||||||
|
chmod +x "$DEPLOY_SCRIPT"
|
||||||
|
|
||||||
|
command -v sqlite3 >/dev/null 2>&1 || fail "sqlite3 missing"
|
||||||
|
command -v docker >/dev/null 2>&1 || fail "docker missing"
|
||||||
|
|
||||||
|
docker ps >/dev/null 2>&1 || fail "docker ps failed"
|
||||||
|
|
||||||
|
log "Reading deployed enabled apps from DB"
|
||||||
|
|
||||||
|
mapfile -t APP_IDS < <(
|
||||||
|
sqlite3 "$DB_FILE" "
|
||||||
|
select id
|
||||||
|
from apps
|
||||||
|
where is_enabled = 1
|
||||||
|
and status = 'deployed'
|
||||||
|
order by id;
|
||||||
|
"
|
||||||
|
)
|
||||||
|
|
||||||
|
if [ "${#APP_IDS[@]}" -eq 0 ]; then
|
||||||
|
warn "No deployed enabled apps found"
|
||||||
|
exit 0
|
||||||
|
fi
|
||||||
|
|
||||||
|
FAILED=0
|
||||||
|
|
||||||
|
for app_id in "${APP_IDS[@]}"; do
|
||||||
|
[ -n "$app_id" ] || continue
|
||||||
|
|
||||||
|
log "Redeploying app: $app_id"
|
||||||
|
|
||||||
|
if "$DEPLOY_SCRIPT" "$app_id"; then
|
||||||
|
ok "Redeployed app: $app_id"
|
||||||
|
else
|
||||||
|
warn "Redeploy failed for app: $app_id"
|
||||||
|
FAILED=$((FAILED + 1))
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
|
||||||
|
echo
|
||||||
|
echo "Redeploy summary:"
|
||||||
|
echo "Total: ${#APP_IDS[@]}"
|
||||||
|
echo "Failed: $FAILED"
|
||||||
|
|
||||||
|
if [ "$FAILED" -gt 0 ]; then
|
||||||
|
fail "One or more apps failed to redeploy"
|
||||||
|
fi
|
||||||
|
|
||||||
|
echo
|
||||||
|
echo "REDEPLOY ENABLED APPS: READY"
|
||||||
Reference in New Issue
Block a user