# Production deploy

## Desktop release profile

Prepare a clean production profile before packaging:

```powershell
cd E:\fotosorter\program
.\.venv\Scripts\python.exe tools\prepare_production_profile.py `
  --api-base-url https://api.example.com/api `
  --update-manifest-url https://downloads.example.com/update_manifest_stable.json
Copy-Item config\commercial_settings.release.json config\commercial_settings.json -Force
```

This keeps the default local `commercial_settings.production.template.json` as the source template and generates a release-ready `commercial_settings.release.json`.

## Desktop release build

Preferred full pipeline:

```powershell
cd E:\fotosorter\program
.\.venv\Scripts\python.exe tools\build_production_release.py `
  --version 2026.04.22 `
  --archive-base-url https://fotosoft.pro `
  --stop-running
```

This helper temporarily swaps in `config\commercial_settings.release.json`, runs build/package/installer, and restores the working `config\commercial_settings.json` afterward.

If the local Windows console interrupts `tools\release_check.py --build` with a spurious `KeyboardInterrupt`, use the manual staged flow instead:

```powershell
cd E:\fotosorter\program
.\.venv\Scripts\python.exe tools\release_check.py --manifest-only
.\.venv\Scripts\python.exe tools\build_backend_release.py --stop-running
.\.venv\Scripts\python.exe tools\release_check.py --verify-dist dist\OrderScanSorter
.\.venv\Scripts\python.exe tools\package_release.py --version 2026.04.22 --archive-base-url https://fotosoft.pro
.\.venv\Scripts\python.exe tools\package_installer.py --version 2026.04.22
```

## Simple backend-enabled desktop build

If you only need a fresh desktop build that already uses the production backend config, run:

```powershell
cd E:\fotosorter\program
.\.venv\Scripts\python.exe tools\build_backend_release.py --stop-running
```

This helper is intended for day-to-day rebuilds. It makes sure that:

- `config\commercial_settings.release.json` is used during the build
- `dist\OrderScanSorter\config\commercial_settings.json` is backend-enabled
- the local working config is restored after the build

If you only want to see which local dev/release copies are still running and may lock `dist`/`dist_release`, run:

```powershell
cd E:\fotosorter\program
.\.venv\Scripts\python.exe tools\build_backend_release.py --list-running
```

The full production pipeline also supports the same pre-build cleanup:

```powershell
cd E:\fotosorter\program
.\.venv\Scripts\python.exe tools\build_production_release.py `
  --version 2026.04.22 `
  --archive-base-url https://fotosoft.pro `
  --stop-running
```

Verify the built config:

```powershell
Get-Content E:\fotosorter\program\dist\OrderScanSorter\config\commercial_settings.json
```

Expected values:

- `"backend_enabled": true`
- `"release_mode": true`
- `"api_base_url": "https://..."`

## Live production URLs

- site: `https://fotosoft.pro`
- cabinet: `https://fotosoft.pro/cabinet.html`
- admin: `https://fotosoft.pro/admin.html`
- api: `https://api.fotosoft.pro/api`
- update manifest: `https://fotosoft.pro/update_manifest_stable.json`
- static site root on server: `/opt/fotosoft/site`

## Publish release/site files

Desktop release artifacts to upload:

- `program\release\OrderScanSorter-<version>.zip`
- `program\release\update_manifest_stable.json`

Current upload commands:

```powershell
scp E:\fotosorter\program\release\OrderScanSorter-2026.04.22.zip root@222.167.208.227:/opt/fotosoft/site/
scp E:\fotosorter\program\release\update_manifest_stable.json root@222.167.208.227:/opt/fotosoft/site/
```

If cabinet UI files were changed, upload them separately:

```powershell
scp E:\fotosorter\cabinet.js root@222.167.208.227:/opt/fotosoft/site/
scp E:\fotosorter\cabinet.html root@222.167.208.227:/opt/fotosoft/site/
```

Static uploads usually do not require `nginx` restart because the container serves `/opt/fotosoft/site` directly.

For the next hardening wave, keep these prep artifacts with the release handoff set:

- `config\transport_pinning.production.template.json`
- `docs\next-hardening-wave.md`
- `..\deploy\CODE_SIGNING.template.md`
- `..\deploy\TRANSPORT_PINNING.template.md`
- `..\deploy\NUITKA_EVALUATION.template.md`

## Backend production env

Use `backend\.env.production.template` as the base file for the server:

```powershell
cd E:\fotosorter
Copy-Item backend\.env.production.template backend\.env -Force
```

Then replace placeholder secrets and provider URLs before starting the backend.

## Minimum production wiring

- `APP_ENV=production`
- strong `SECRET_KEY`, `ADMIN_TOKEN`, `LICENSE_SIGNING_SECRET`
- real `DATABASE_URL`
- real `SMS_*` provider configuration
- real `PAYMENT_*` hosted checkout and webhook configuration
- public `BACKEND_PUBLIC_URL`
- correct `CORS_ORIGINS`
