# Windows Server 2012 Deployment Options

## Current Challenge
- **Target**: Windows Server 2012 (EOL 2023, Python 2.7 only)
- **Current App**: FastAPI + uvicorn (Python 3.7+)
- **Dependencies**: Pillow, pyodbc

## Available Options

### Option 1: Rebuild as Windows Service in Python 2.7 ⚠️ HARD
**Pros:**
- Native to Windows Server 2012
- No additional infrastructure

**Cons:**
- Must rewrite entire app in Python 2.7
- FastAPI doesn't support Python 2.7
- Pillow 6.x is last version for Python 2.7 (potentially insecure)
- pyodbc support limited

**Recommendation:** ❌ Not viable due to security and maintainability

---

### Option 2: Container Deployment ✅ BEST
**Architecture:**
- Deploy as Docker container on Windows Server 2016/2019/2022 host
- Windows Server 2012 VM/machine accesses via network

**Pros:**
- Keep current Python 3.11 code
- No code changes needed
- Isolated, reproducible environment
- Easy updates/deployments

**Cons:**
- Need Windows Server 2016+ or Docker Desktop
- Network latency to document store

**Setup:**
```dockerfile
# Dockerfile.win
FROM python:3.11-windowsservercore

COPY PLAGIS_AUMENTUM/ /app/
RUN pip install -r requirements.txt

EXPOSE 8001
CMD python aumentum_api.py
```

```powershell
docker build -f Dockerfile.win -t aumentum-api .
docker run -p 8001:8001 -v C:\contentstore:/mnt/contentstore aumentum-api
```

**Recommendation:** ✅ Best if you have a newer Windows Server available

---

### Option 3: Linux VM/Container on Same Network ✅ GOOD
**Architecture:**
- Spin up Linux VM (Ubuntu 20.04 LTS)
- Deploy app in Docker container
- Windows Server 2012 accesses via network share + API

**Pros:**
- Latest Python versions
- Lower resource usage
- Modern deployment practices
- Share files via SMB/NFS

**Cons:**
- Cross-platform setup complexity
- Network configuration

**Setup:**
```bash
# On Linux VM
git clone <repo>
cd mlstp_convertion
docker-compose up -d
```

**Docker Compose:**
```yaml
version: '3.8'
services:
  aumentum-api:
    build: .
    ports:
      - "8001:8001"
    volumes:
      - /mnt/contentstore:/mnt/contentstore
      - ./PLAGIS_AUMENTUM:/app
    environment:
      - DB_HOST=10.10.10.3
    restart: unless-stopped
```

**Recommendation:** ✅ Practical and modern approach

---

### Option 4: Standalone Windows Executable (Single File) ✅ VIABLE
**Architecture:**
- Use PyInstaller on Python 3.x machine
- Create self-contained .exe
- Deploy to Windows Server 2012

**Pros:**
- Single file deployment
- No Python installation needed on 2012 server
- Uses Python 3.x runtime bundled

**Cons:**
- Large file size (~200-300MB)
- Slower startup
- PyInstaller complexity with some dependencies
- Need access to Windows build machine

**Setup:**
```bash
# On Python 3.11 Windows machine
pip install pyinstaller

# Create .spec file
pyinstaller --onedir --windowed --name aumentum-api \
  --add-data "PLAGIS_AUMENTUM;PLAGIS_AUMENTUM" \
  PLAGIS_AUMENTUM/aumentum_api.py

# Or single file
pyinstaller --onefile --name aumentum-api.exe \
  --hidden-import fastapi \
  --hidden-import uvicorn \
  PLAGIS_AUMENTUM/aumentum_api.py
```

**Recommendation:** ✅ Works if you have a Windows build machine

---

### Option 5: Minimal Rewrite Using Available Tech ✅ COMPROMISE
**Architecture:**
- Rewrite API layer in Flask (supports Python 2.7)
- Keep core conversion logic
- Use older compatible versions

**Pros:**
- Can run on Python 2.7
- Maintains most functionality

**Cons:**
- Security risks of old Python 2.7
- Limited package versions
- Significant code changes
- Pillow 2.x for Python 2.7 (old)

**Example:**
```python
# Old Flask approach
from flask import Flask, request
app = Flask(__name__)

@app.route('/documents/by-document-number')
def get_by_docnum():
    docnum = request.args.get('document_number')
    # ... logic
```

**Recommendation:** ❌ Security risks outweigh benefits

---

## Recommended Approach: Hybrid Solution

### Phase 1: Immediate (Option 4)
1. Build standalone .exe with PyInstaller on modern Windows
2. Deploy single file to Windows Server 2012
3. Configure Windows Service wrapper

### Phase 2: Long-term (Option 2 or 3)
1. Move to Windows Server 2019/2022 + Docker
2. Or deploy Linux VM with container
3. Modern infrastructure with security updates

---

## Migration Path

```
Windows Server 2012 (2013-2023) EOL ❌
    ↓
Build .exe on modern Windows → Deploy to 2012 (temp solution)
    ↓
Windows Server 2019/2022 + Docker (modern solution) ✅
```

---

## Recommendation Summary

| Option | Viability | Security | Effort | Long-term |
|--------|-----------|----------|--------|-----------|
| Python 2.7 Rewrite | ❌ | ❌❌❌ | ⭐⭐⭐⭐⭐ | ❌ |
| Docker on 2016+ | ✅✅✅ | ✅✅✅ | ⭐⭐ | ✅✅✅ |
| Linux VM + Docker | ✅✅✅ | ✅✅✅ | ⭐⭐⭐ | ✅✅✅ |
| Standalone .exe | ✅✅ | ✅✅ | ⭐⭐⭐ | ✅ |
| Flask + Python 2.7 | ⚠️ | ❌ | ⭐⭐⭐⭐ | ❌ |

**Best Bet:** **Option 2 (Docker) on Windows Server 2016+** or **Option 4 (.exe)** as temporary bridge.

Would you like me to:
1. Set up PyInstaller configuration for standalone .exe?
2. Create Docker setup for Linux/Windows?
3. Build minimal Flask version for compatibility testing?

