Restore stable delete script
This commit is contained in:
+78
-27
@@ -9,16 +9,39 @@ if [ -z "$APP_ID" ]; then
|
|||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
BASE_DIR="/opt/appfactory"
|
CONFIG_FILE="/opt/appfactory/config/appfactory.env"
|
||||||
WORKSPACE_DIR="/home/jiri/workspace"
|
|
||||||
COMPOSE_FILE="$BASE_DIR/deploy/apps-compose.yml"
|
if [ -f "$CONFIG_FILE" ]; then
|
||||||
CADDY_FILE="$BASE_DIR/gateway/Caddyfile"
|
source "$CONFIG_FILE"
|
||||||
CATALOG_FILE="$BASE_DIR/apps/catalog.yml"
|
fi
|
||||||
|
|
||||||
|
APPFACTORY_DIR="${APPFACTORY_DIR:-/opt/appfactory}"
|
||||||
|
WORKSPACE_DIR="${WORKSPACE_DIR:-/home/jiri/workspace}"
|
||||||
|
|
||||||
|
COMPOSE_FILE="$APPFACTORY_DIR/deploy/apps-compose.yml"
|
||||||
|
CATALOG_FILE="$APPFACTORY_DIR/apps/catalog.yml"
|
||||||
|
CADDY_FILE="$APPFACTORY_DIR/gateway/Caddyfile"
|
||||||
|
|
||||||
|
TOOLS_DIR="$WORKSPACE_DIR/appfactory-tools"
|
||||||
|
|
||||||
echo "Deleting app: $APP_ID"
|
echo "Deleting app: $APP_ID"
|
||||||
|
|
||||||
docker rm -f "$APP_ID" 2>/dev/null || true
|
if [ -n "${GITEA_URL:-}" ] && [ -n "${GITEA_TOKEN:-}" ] && [ -n "${GITEA_ORG:-}" ]; then
|
||||||
docker rmi -f "$APP_ID:latest" 2>/dev/null || true
|
echo "Deleting Gitea repository..."
|
||||||
|
|
||||||
|
curl -sS -X DELETE \
|
||||||
|
"$GITEA_URL/api/v1/repos/$GITEA_ORG/$APP_ID" \
|
||||||
|
-H "Authorization: token $GITEA_TOKEN" || true
|
||||||
|
fi
|
||||||
|
|
||||||
|
echo "Stopping container..."
|
||||||
|
docker rm -f "$APP_ID" || true
|
||||||
|
|
||||||
|
echo "Removing image..."
|
||||||
|
docker rmi -f "$APP_ID:latest" || true
|
||||||
|
|
||||||
|
echo "Removing workspace..."
|
||||||
|
rm -rf "$WORKSPACE_DIR/$APP_ID"
|
||||||
|
|
||||||
python3 - "$APP_ID" "$COMPOSE_FILE" "$CATALOG_FILE" "$CADDY_FILE" <<'PY'
|
python3 - "$APP_ID" "$COMPOSE_FILE" "$CATALOG_FILE" "$CADDY_FILE" <<'PY'
|
||||||
import sys
|
import sys
|
||||||
@@ -29,42 +52,70 @@ compose_file = Path(sys.argv[2])
|
|||||||
catalog_file = Path(sys.argv[3])
|
catalog_file = Path(sys.argv[3])
|
||||||
caddy_file = Path(sys.argv[4])
|
caddy_file = Path(sys.argv[4])
|
||||||
|
|
||||||
def remove_yaml_block(path: Path, start_patterns):
|
def remove_block(lines, predicate):
|
||||||
lines = path.read_text().splitlines()
|
|
||||||
out = []
|
out = []
|
||||||
i = 0
|
i = 0
|
||||||
|
|
||||||
while i < len(lines):
|
while i < len(lines):
|
||||||
line = lines[i]
|
line = lines[i]
|
||||||
if any(p in line for p in start_patterns):
|
|
||||||
|
if predicate(line):
|
||||||
indent = len(line) - len(line.lstrip())
|
indent = len(line) - len(line.lstrip())
|
||||||
i += 1
|
i += 1
|
||||||
|
|
||||||
while i < len(lines):
|
while i < len(lines):
|
||||||
next_line = lines[i]
|
next_line = lines[i]
|
||||||
if next_line.strip() and (len(next_line) - len(next_line.lstrip())) <= indent:
|
|
||||||
break
|
if next_line.strip():
|
||||||
|
next_indent = len(next_line) - len(next_line.lstrip())
|
||||||
|
|
||||||
|
if next_indent <= indent:
|
||||||
|
break
|
||||||
|
|
||||||
i += 1
|
i += 1
|
||||||
|
|
||||||
continue
|
continue
|
||||||
|
|
||||||
out.append(line)
|
out.append(line)
|
||||||
i += 1
|
i += 1
|
||||||
path.write_text("\n".join(out).rstrip() + "\n")
|
|
||||||
|
|
||||||
remove_yaml_block(compose_file, [f" {app_id}:"])
|
return out
|
||||||
remove_yaml_block(catalog_file, [f" - id: {app_id}"])
|
|
||||||
|
|
||||||
text = caddy_file.read_text()
|
if compose_file.exists():
|
||||||
block = f""" handle_path /apps/{app_id}/* {{
|
compose_lines = compose_file.read_text().splitlines()
|
||||||
reverse_proxy {app_id}:8000
|
|
||||||
}}
|
|
||||||
|
|
||||||
"""
|
compose_lines = remove_block(
|
||||||
text = text.replace(block, "")
|
compose_lines,
|
||||||
caddy_file.write_text(text)
|
lambda l: l.startswith(f" {app_id}:")
|
||||||
|
)
|
||||||
|
|
||||||
|
compose_file.write_text("\n".join(compose_lines) + "\n")
|
||||||
|
|
||||||
|
if catalog_file.exists():
|
||||||
|
catalog_lines = catalog_file.read_text().splitlines()
|
||||||
|
|
||||||
|
catalog_lines = remove_block(
|
||||||
|
catalog_lines,
|
||||||
|
lambda l: l.strip() == f"- id: {app_id}"
|
||||||
|
)
|
||||||
|
|
||||||
|
catalog_file.write_text("\n".join(catalog_lines) + "\n")
|
||||||
|
|
||||||
|
if caddy_file.exists():
|
||||||
|
caddy_lines = caddy_file.read_text().splitlines()
|
||||||
|
|
||||||
|
caddy_lines = remove_block(
|
||||||
|
caddy_lines,
|
||||||
|
lambda l: f"/apps/{app_id}/*" in l
|
||||||
|
)
|
||||||
|
|
||||||
|
caddy_file.write_text("\n".join(caddy_lines) + "\n")
|
||||||
PY
|
PY
|
||||||
|
|
||||||
rm -rf "$WORKSPACE_DIR/$APP_ID" || true
|
echo "Regenerating generated files..."
|
||||||
|
|
||||||
cd "$BASE_DIR/deploy"
|
"$TOOLS_DIR/scripts/generate-apps-compose.sh"
|
||||||
docker compose -f docker-compose.yml -f apps-compose.yml up -d
|
"$TOOLS_DIR/scripts/generate-caddyfile.sh"
|
||||||
docker exec appfactory-caddy caddy reload --config /etc/caddy/Caddyfile || docker restart appfactory-caddy
|
"$TOOLS_DIR/scripts/generate-apps-page.sh"
|
||||||
|
|
||||||
echo "Deleted: $APP_ID"
|
echo "DONE"
|
||||||
|
|||||||
Reference in New Issue
Block a user