#!/usr/bin/env bash set -euo pipefail APP_ID="${1:-}" if [ -z "$APP_ID" ]; then echo "Usage: ./deploy-app.sh " exit 1 fi CONFIG_FILE="/opt/appfactory/config/appfactory.env" source "$CONFIG_FILE" APP_SOURCE_DIR="$WORKSPACE_DIR/$APP_ID" CATALOG_FILE="$APPFACTORY_DIR/apps/catalog.yml" TOOLS_DIR="$WORKSPACE_DIR/appfactory-tools" if [ ! -d "$APP_SOURCE_DIR" ]; then echo "Missing app source: $APP_SOURCE_DIR" exit 1 fi if [ ! -f "$APP_SOURCE_DIR/Dockerfile" ]; then echo "Missing Dockerfile in: $APP_SOURCE_DIR" exit 1 fi chown -R "$APP_USER:$APP_GROUP" "$APP_SOURCE_DIR" || true echo "Updating source code..." cd "$APP_SOURCE_DIR" if [ -d ".git" ]; then git config --global --add safe.directory "$APP_SOURCE_DIR" || true git fetch origin main git reset --hard origin/main fi echo "Building Docker image..." docker build --pull --no-cache -t "$APP_ID:latest" "$APP_SOURCE_DIR" if [ ! -f "$CATALOG_FILE" ]; then echo "apps:" > "$CATALOG_FILE" fi if ! grep -q "id: $APP_ID" "$CATALOG_FILE"; then cat >> "$CATALOG_FILE" <