#!/bin/bash # Exit on error set -e ECHO "📦 Starting Release Package Process..." # 1. Clean previous build rm -rf ocr_build mkdir -p ocr_build # 2. Build Frontend Locally echo "🏗️ Building Angular Frontend (Base Href: /ocrf/)..." cd frontend npm install --legacy-peer-deps npm run build -- --configuration production --base-href /ocrf/ cd .. # 3. Prepare Frontend Artifacts echo "📂 Preparing Frontend Packaging..." mkdir -p ocr_build/frontend # Copy the compiled 'browser' folder to ocr_build/frontend/dist cp -r frontend/dist/frontend/browser ocr_build/frontend/dist # Copy the internal nginx config cp frontend/nginx.conf ocr_build/frontend/ # Create a lightweight Production Dockerfile for Frontend # This replaces the multi-stage build with a single stage serving pre-built files cat < ocr_build/frontend/Dockerfile FROM nginx:alpine # Remove default nginx static assets RUN rm -rf /usr/share/nginx/html/* # Create target directory RUN mkdir -p /usr/share/nginx/html/ocrf # Copy Pre-built assets (from local dist) COPY dist /usr/share/nginx/html/ocrf # Copy custom nginx config COPY nginx.conf /etc/nginx/conf.d/default.conf # Expose port 80 EXPOSE 80 CMD ["nginx", "-g", "daemon off;"] EOF # 4. Prepare Backend Artifacts echo "🐍 Preparing Backend Packaging..." mkdir -p ocr_build/backend # Copy Backend Source (Excluding venv and pycache) rsync -av --progress backend/ ocr_build/backend/ --exclude venv --exclude __pycache__ --exclude .pytest_cache --exclude uploads # 5. Copy Root Configurations echo "⚙️ Copying Configuration files..." cp docker-compose.yaml ocr_build/ cp .env.prod ocr_build/.env cp deployment/nginx.conf ocr_build/nginx_host.conf cp DEPLOYMENT.md ocr_build/ echo "✅ Release Package Created: ./ocr_build" echo " Transfer the 'ocr_build' folder to your Linux server and run:" echo " cd ocr_build && docker-compose --env-file .env.prod up -d --build"