Add bootstrap v2, preflight readiness and migration tooling
This commit is contained in:
+125
-26
@@ -2,34 +2,34 @@
|
||||
set -euo pipefail
|
||||
|
||||
CONFIG_FILE="/opt/appfactory/config/appfactory.env"
|
||||
source "$CONFIG_FILE"
|
||||
|
||||
if [ -f "$CONFIG_FILE" ]; then
|
||||
set -a
|
||||
# shellcheck disable=SC1090
|
||||
source "$CONFIG_FILE"
|
||||
set +a
|
||||
fi
|
||||
|
||||
APPFACTORY_DIR="${APPFACTORY_DIR:-/opt/appfactory}"
|
||||
CATALOG_FILE="$APPFACTORY_DIR/apps/catalog.yml"
|
||||
CADDY_FILE="$APPFACTORY_DIR/gateway/Caddyfile"
|
||||
|
||||
APPFACTORY_ENABLE_HTTPS="${APPFACTORY_ENABLE_HTTPS:-false}"
|
||||
APPFACTORY_PORTAL_DOMAIN="${APPFACTORY_PORTAL_DOMAIN:-}"
|
||||
APPFACTORY_GITEA_DOMAIN="${APPFACTORY_GITEA_DOMAIN:-}"
|
||||
APPFACTORY_REGISTRY_DOMAIN="${APPFACTORY_REGISTRY_DOMAIN:-}"
|
||||
|
||||
mkdir -p "$(dirname "$CADDY_FILE")"
|
||||
mkdir -p "$APPFACTORY_DIR/gateway/static"
|
||||
|
||||
cat > "$CADDY_FILE" <<EOF_CADDY
|
||||
:80 {
|
||||
handle /health {
|
||||
respond "AppFactory OK" 200
|
||||
}
|
||||
write_app_routes() {
|
||||
local target_file="$1"
|
||||
|
||||
handle /portal* {
|
||||
uri strip_prefix /portal
|
||||
reverse_proxy appfactory-portal:9100
|
||||
}
|
||||
if [ ! -f "$CATALOG_FILE" ]; then
|
||||
return 0
|
||||
fi
|
||||
|
||||
handle /apps {
|
||||
root * /srv/static
|
||||
rewrite * /apps.html
|
||||
file_server
|
||||
}
|
||||
|
||||
EOF_CADDY
|
||||
|
||||
if [ -f "$CATALOG_FILE" ]; then
|
||||
python3 - "$CATALOG_FILE" "$CADDY_FILE" <<'PY'
|
||||
python3 - "$CATALOG_FILE" "$target_file" <<'PY'
|
||||
import sys
|
||||
|
||||
catalog_file = sys.argv[1]
|
||||
@@ -45,7 +45,7 @@ with open(catalog_file, "r", encoding="utf-8") as f:
|
||||
if stripped.startswith("- id:"):
|
||||
if current:
|
||||
apps.append(current)
|
||||
current = {"id": stripped.split(":", 1)[1].strip()}
|
||||
current = {"id": stripped.split(":", 1)[1].strip().strip('"')}
|
||||
elif current and ":" in stripped:
|
||||
key, value = stripped.split(":", 1)
|
||||
current[key.strip()] = value.strip().strip('"')
|
||||
@@ -65,9 +65,32 @@ with open(caddy_file, "a", encoding="utf-8") as f:
|
||||
f.write(f" reverse_proxy {app_id}:{port}\n")
|
||||
f.write(" }\n\n")
|
||||
PY
|
||||
fi
|
||||
}
|
||||
|
||||
cat >> "$CADDY_FILE" <<EOF_CADDY
|
||||
write_common_path_routes() {
|
||||
local target_file="$1"
|
||||
|
||||
cat >> "$target_file" <<'EOF_ROUTES'
|
||||
handle /health {
|
||||
respond "AppFactory OK" 200
|
||||
}
|
||||
|
||||
handle /portal* {
|
||||
uri strip_prefix /portal
|
||||
reverse_proxy appfactory-portal:9100
|
||||
}
|
||||
|
||||
handle /apps {
|
||||
root * /srv/static
|
||||
rewrite * /apps.html
|
||||
file_server
|
||||
}
|
||||
|
||||
EOF_ROUTES
|
||||
|
||||
write_app_routes "$target_file"
|
||||
|
||||
cat >> "$target_file" <<'EOF_ROUTES'
|
||||
handle_path /webhook/* {
|
||||
reverse_proxy appfactory-webhook:9000
|
||||
}
|
||||
@@ -79,11 +102,87 @@ cat >> "$CADDY_FILE" <<EOF_CADDY
|
||||
handle {
|
||||
respond "AppFactory gateway is running" 200
|
||||
}
|
||||
EOF_ROUTES
|
||||
}
|
||||
|
||||
write_http_only_caddyfile() {
|
||||
cat > "$CADDY_FILE" <<'EOF_CADDY'
|
||||
:80 {
|
||||
EOF_CADDY
|
||||
|
||||
write_common_path_routes "$CADDY_FILE"
|
||||
|
||||
cat >> "$CADDY_FILE" <<'EOF_CADDY'
|
||||
}
|
||||
EOF_CADDY
|
||||
}
|
||||
|
||||
write_domain_caddyfile() {
|
||||
: > "$CADDY_FILE"
|
||||
|
||||
if [ -n "$APPFACTORY_PORTAL_DOMAIN" ]; then
|
||||
cat >> "$CADDY_FILE" <<EOF_CADDY
|
||||
$APPFACTORY_PORTAL_DOMAIN {
|
||||
EOF_CADDY
|
||||
write_common_path_routes "$CADDY_FILE"
|
||||
cat >> "$CADDY_FILE" <<'EOF_CADDY'
|
||||
}
|
||||
|
||||
EOF_CADDY
|
||||
fi
|
||||
|
||||
if [ -n "$APPFACTORY_GITEA_DOMAIN" ]; then
|
||||
cat >> "$CADDY_FILE" <<EOF_CADDY
|
||||
$APPFACTORY_GITEA_DOMAIN {
|
||||
handle /health {
|
||||
respond "Gitea gateway OK" 200
|
||||
}
|
||||
|
||||
handle {
|
||||
reverse_proxy appfactory-gitea:3000
|
||||
}
|
||||
}
|
||||
|
||||
EOF_CADDY
|
||||
fi
|
||||
|
||||
if [ -n "$APPFACTORY_REGISTRY_DOMAIN" ]; then
|
||||
cat >> "$CADDY_FILE" <<EOF_CADDY
|
||||
$APPFACTORY_REGISTRY_DOMAIN {
|
||||
handle /v2/* {
|
||||
reverse_proxy appfactory-registry:5000
|
||||
}
|
||||
|
||||
handle /health {
|
||||
respond "Registry gateway OK" 200
|
||||
}
|
||||
|
||||
handle {
|
||||
reverse_proxy appfactory-registry:5000
|
||||
}
|
||||
}
|
||||
|
||||
EOF_CADDY
|
||||
fi
|
||||
|
||||
if [ ! -s "$CADDY_FILE" ]; then
|
||||
write_http_only_caddyfile
|
||||
fi
|
||||
}
|
||||
|
||||
if [ "$APPFACTORY_ENABLE_HTTPS" = "true" ] && {
|
||||
[ -n "$APPFACTORY_PORTAL_DOMAIN" ] || [ -n "$APPFACTORY_GITEA_DOMAIN" ] || [ -n "$APPFACTORY_REGISTRY_DOMAIN" ];
|
||||
}; then
|
||||
write_domain_caddyfile
|
||||
else
|
||||
write_http_only_caddyfile
|
||||
fi
|
||||
|
||||
echo "Generated: $CADDY_FILE"
|
||||
|
||||
docker exec appfactory-caddy caddy validate --config /etc/caddy/Caddyfile
|
||||
|
||||
docker exec appfactory-caddy caddy reload --config /etc/caddy/Caddyfile
|
||||
if docker inspect appfactory-caddy >/dev/null 2>&1; then
|
||||
docker exec appfactory-caddy caddy validate --config /etc/caddy/Caddyfile
|
||||
docker exec appfactory-caddy caddy reload --config /etc/caddy/Caddyfile
|
||||
else
|
||||
echo "WARN: appfactory-caddy container not found, skipping validate/reload"
|
||||
fi
|
||||
|
||||
Reference in New Issue
Block a user