50 lines
1.5 KiB
Bash
Executable File
50 lines
1.5 KiB
Bash
Executable File
#!/bin/bash
|
|
set -e
|
|
|
|
PROD_DIR="/home/www/new-api-prod"
|
|
COMPOSE_FILE="$PROD_DIR/docker-compose.prod.yml"
|
|
IMAGE_NAME="my-new-api:latest"
|
|
PROJECT_DIR="$(cd "$(dirname "$0")" && pwd)"
|
|
|
|
echo "========================================="
|
|
echo " New API Auto Deploy"
|
|
echo " $(date '+%Y-%m-%d %H:%M:%S')"
|
|
echo "========================================="
|
|
|
|
# Step 1: Build frontend
|
|
echo "[1/4] Building web/default..."
|
|
export PATH="$HOME/.bun/bin:$PATH"
|
|
cd "$PROJECT_DIR/web"
|
|
bun install --frozen-lockfile
|
|
cd "$PROJECT_DIR/web/default"
|
|
bun run build
|
|
echo " web/default built."
|
|
|
|
echo "[2/4] Building web/image-gen..."
|
|
cd "$PROJECT_DIR/web/image-gen"
|
|
if command -v npm >/dev/null 2>&1; then
|
|
npm ci --no-audit --no-fund
|
|
npm run build
|
|
else
|
|
echo " WARNING: npm not found, image-gen dist not built."
|
|
echo " Install Node.js 20+ to build the image-gen sub-app."
|
|
mkdir -p dist
|
|
echo '<!doctype html><html><head><title>image-gen placeholder</title></head><body>image-gen dist not built (npm missing)</body></html>' > dist/index.html
|
|
fi
|
|
echo " web/image-gen built."
|
|
|
|
# Step 3: Build Docker image
|
|
echo "[3/4] Building Docker image: $IMAGE_NAME"
|
|
cd "$PROJECT_DIR"
|
|
docker build -t "$IMAGE_NAME" .
|
|
echo " Image built."
|
|
|
|
# Step 4: Restart production containers
|
|
echo "[4/4] Restarting production containers..."
|
|
sudo -u www docker compose -f "$COMPOSE_FILE" up -d
|
|
echo " Production deployed."
|
|
|
|
echo "========================================="
|
|
echo " Done! Production at http://localhost:3001"
|
|
echo "========================================="
|