From ec18df3f2485de93a9ecdbb7c2e3f4c129006e04 Mon Sep 17 00:00:00 2001 From: Jiri Uhlir Date: Thu, 21 May 2026 11:55:16 +0200 Subject: [PATCH] Use catalog as source of truth for app deployment --- scripts/deploy-app.sh | 81 +++++--------------------------- scripts/generate-apps-compose.sh | 29 ++++++++++++ scripts/generate-caddyfile.sh | 17 ++++--- 3 files changed, 53 insertions(+), 74 deletions(-) create mode 100755 scripts/generate-apps-compose.sh diff --git a/scripts/deploy-app.sh b/scripts/deploy-app.sh index c02f167..5197813 100755 --- a/scripts/deploy-app.sh +++ b/scripts/deploy-app.sh @@ -10,12 +10,10 @@ if [ -z "$APP_ID" ]; then fi BASE_DIR="/opt/appfactory" -WORKSPACE_DIR="$HOME/workspace" - -CADDY_FILE="$BASE_DIR/gateway/Caddyfile" -CATALOG_FILE="$BASE_DIR/apps/catalog.yml" +WORKSPACE_DIR="/home/jiri/workspace" APP_SOURCE_DIR="$WORKSPACE_DIR/$APP_ID" +CATALOG_FILE="$BASE_DIR/apps/catalog.yml" if [ ! -d "$APP_SOURCE_DIR" ]; then echo "Missing app source: $APP_SOURCE_DIR" @@ -25,68 +23,12 @@ fi echo "Building Docker image..." docker build -t "$APP_ID:latest" "$APP_SOURCE_DIR" -COMPOSE_FILE="$BASE_DIR/deploy/apps-compose.yml" - -mkdir -p "$BASE_DIR/deploy/generated" - -if [ ! -f "$COMPOSE_FILE" ]; then - cat > "$COMPOSE_FILE" </dev/null; then + true fi -if grep -q "container_name: $APP_ID" "$COMPOSE_FILE"; then - echo "App already registered in compose." -else - -cat >> "$COMPOSE_FILE" < "$TMP_FILE" -# -#cat >> "$TMP_FILE" <> "$CATALOG_FILE" <> "$CATALOG_FILE" <> "$CATALOG_FILE" < "$COMPOSE_FILE" <<'EOF_COMPOSE' +services: +EOF_COMPOSE + +awk ' + /- id:/ { app=$3 } + /language:/ { lang=$2 } + /status:/ { + if (app != "") { + print " " app ":" + print " image: " app ":latest" + print " container_name: " app + print " restart: unless-stopped" + print " environment:" + print " - APP_NAME=" app + print " - ROOT_PATH=/apps/" app + print " networks:" + print " - appfactory" + print "" + } + } +' "$CATALOG_FILE" >> "$COMPOSE_FILE" diff --git a/scripts/generate-caddyfile.sh b/scripts/generate-caddyfile.sh index 3e8f3b6..e534345 100755 --- a/scripts/generate-caddyfile.sh +++ b/scripts/generate-caddyfile.sh @@ -5,7 +5,7 @@ BASE_DIR="/opt/appfactory" CATALOG_FILE="$BASE_DIR/apps/catalog.yml" CADDY_FILE="$BASE_DIR/gateway/Caddyfile" -cat > "$CADDY_FILE" <<'EOF' +cat > "$CADDY_FILE" <<'EOF_CADDY' :80 { handle /health { respond "AppFactory OK" 200 @@ -22,13 +22,18 @@ cat > "$CADDY_FILE" <<'EOF' file_server } -EOF +EOF_CADDY awk ' - /- id:/ { print " handle_path /apps/" $3 "/* {\n reverse_proxy " $3 ":8000\n }\n" } + /- id:/ { + print " handle_path /apps/" $3 "/* {" + print " reverse_proxy " $3 ":8000" + print " }" + print "" + } ' "$CATALOG_FILE" >> "$CADDY_FILE" -cat >> "$CADDY_FILE" <<'EOF' +cat >> "$CADDY_FILE" <<'EOF_CADDY' handle_path /webhook/* { reverse_proxy appfactory-webhook:9000 } @@ -41,6 +46,6 @@ cat >> "$CADDY_FILE" <<'EOF' respond "AppFactory gateway is running" 200 } } -EOF +EOF_CADDY -docker exec appfactory-caddy caddy reload --config /etc/caddy/Caddyfile || docker restart appfactory-caddy +docker exec appfactory-caddy caddy reload --config /etc/caddy/Caddyfile