# OCR Application Deployment Guide This guide describes how to deploy the OCR application on a Linux host (e.g., Ubuntu/Debian). ## Architecture - **Backend**: Containerized (FastAPI, Python 3.9). - **Database**: Containerized (PostgreSQL 15). - **Frontend**: Static files (Angular) served by Host Nginx. - **Reverse Proxy**: Host Nginx proxies requests to Frontend (Static) and Backend (API). ## Prerequisites - **Deployment Host**: Docker & Docker Compose, Nginx. - **Build Machine**: Node.js & NPM (to run the package script). --- ## 1. Full Stack Deployment (Docker) The app connects to your **existing Postgres container** (`postgres-db`) in the `arbit-app_arbit-network`. 1. **Create the Database**: Since we are using an existing postgres instance, we must manually create the `ocr_db`. ```bash # Run this on your host to create the DB inside the existing container docker exec -it postgres-db psql -U postgres -c "CREATE DATABASE ocr_db;" ``` 2. **Navigate to the packaged directory**: ```bash cd ocr_build ``` 3. **Verify Environment**: Ensure `.env.prod` exists and points to `DB_HOST=postgres-db`. **Also configure your Email credentials** in `.env.prod` if you want the Mailbox feature to work (Gmail requires an App Password). ```bash cat .env.prod ``` 4. **Start App Containers**: This will start `ocr_backend` and `ocr_frontend`. ```bash # Build and start in detached mode docker-compose up -d --build ``` 5. **Verify Status**: ```bash docker-compose ps ``` You should see `ocr_backend` and `ocr_frontend` running. --- ## 2. Nginx Configuration (Host Reverse Proxy) Since the Frontend is now running in a container on port 8080 (serving `/ocrf/`), we configure the Host Nginx to proxy traffic to it. 1. **Create Config File**: Copy the provided config to `/etc/nginx/sites-available/ocr`. ```bash sudo cp nginx_host.conf /etc/nginx/sites-available/ocr ``` 2. **Enable Site**: ```bash sudo ln -s /etc/nginx/sites-available/ocr /etc/nginx/sites-enabled/ ``` 3. **Test & Reload**: ```bash sudo nginx -t sudo systemctl reload nginx ``` --- ## 3. Verification - **Url**: `http://app.technobeesolutions.in/ocrf/` (Proxies to Frontend Container) - **API**: `http://app.technobeesolutions.in/ocrb/` (Proxies to Backend Container) --- ## 4. Troubleshooting - **Logs**: ```bash docker-compose logs -f backend ``` - **Database**: Connect via the existing container: ```bash docker exec -it postgres-db psql -U postgres -d ocr_db ```