71 lines
1.8 KiB
Bash
Executable File
71 lines
1.8 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
set -euo pipefail
|
|
|
|
APP_ID="${1:-}"
|
|
|
|
if [ -z "$APP_ID" ]; then
|
|
echo "Usage:"
|
|
echo " ./delete-app.sh <app-id>"
|
|
exit 1
|
|
fi
|
|
|
|
BASE_DIR="/opt/appfactory"
|
|
WORKSPACE_DIR="/home/jiri/workspace"
|
|
COMPOSE_FILE="$BASE_DIR/deploy/apps-compose.yml"
|
|
CADDY_FILE="$BASE_DIR/gateway/Caddyfile"
|
|
CATALOG_FILE="$BASE_DIR/apps/catalog.yml"
|
|
|
|
echo "Deleting app: $APP_ID"
|
|
|
|
docker rm -f "$APP_ID" 2>/dev/null || true
|
|
docker rmi -f "$APP_ID:latest" 2>/dev/null || true
|
|
|
|
python3 - "$APP_ID" "$COMPOSE_FILE" "$CATALOG_FILE" "$CADDY_FILE" <<'PY'
|
|
import sys
|
|
from pathlib import Path
|
|
|
|
app_id = sys.argv[1]
|
|
compose_file = Path(sys.argv[2])
|
|
catalog_file = Path(sys.argv[3])
|
|
caddy_file = Path(sys.argv[4])
|
|
|
|
def remove_yaml_block(path: Path, start_patterns):
|
|
lines = path.read_text().splitlines()
|
|
out = []
|
|
i = 0
|
|
while i < len(lines):
|
|
line = lines[i]
|
|
if any(p in line for p in start_patterns):
|
|
indent = len(line) - len(line.lstrip())
|
|
i += 1
|
|
while i < len(lines):
|
|
next_line = lines[i]
|
|
if next_line.strip() and (len(next_line) - len(next_line.lstrip())) <= indent:
|
|
break
|
|
i += 1
|
|
continue
|
|
out.append(line)
|
|
i += 1
|
|
path.write_text("\n".join(out).rstrip() + "\n")
|
|
|
|
remove_yaml_block(compose_file, [f" {app_id}:"])
|
|
remove_yaml_block(catalog_file, [f" - id: {app_id}"])
|
|
|
|
text = caddy_file.read_text()
|
|
block = f""" handle_path /apps/{app_id}/* {{
|
|
reverse_proxy {app_id}:8000
|
|
}}
|
|
|
|
"""
|
|
text = text.replace(block, "")
|
|
caddy_file.write_text(text)
|
|
PY
|
|
|
|
rm -rf "$WORKSPACE_DIR/$APP_ID" || true
|
|
|
|
cd "$BASE_DIR/deploy"
|
|
docker compose -f docker-compose.yml -f apps-compose.yml up -d
|
|
docker exec appfactory-caddy caddy reload --config /etc/caddy/Caddyfile || docker restart appfactory-caddy
|
|
|
|
echo "Deleted: $APP_ID"
|