# Render Docker Deployment Notes

This Docker setup packages Tarnova for Render testing. It does not change Laravel routes, controllers, models, migrations, invoices, payments, PDFs, or business logic.

## What Docker Adds

- `Dockerfile` builds PHP, Composer dependencies, frontend assets, and Nginx/PHP-FPM.
- `.dockerignore` keeps secrets, local dependencies, zip files, and runtime storage out of the image.
- `docker/start-web.sh` starts the web app safely.
- `docker/start-worker.sh` runs the queue worker for queued invoice, quotation, and credit note emails.
- `docker/start-scheduler.sh` runs Laravel scheduled tasks every minute for reminders, recurring invoices, quote expiry, backups, and overdue refresh.
- `render.yaml` is a starting Render Blueprint for web, worker, scheduler, and Postgres.

## Does Docker Change the App?

No. Docker is packaging and runtime configuration. It only affects the app when you build or deploy the container.

It does not:

- change your database schema by itself
- change calculations
- change invoice/payment/credit-note logic
- change routes or UI
- overwrite `.env`
- modify local XAMPP behavior

The only runtime action that can change data is migrations when `RUN_MIGRATIONS=true`. This is intentional for Render testing, but for production you may prefer to run migrations manually and set `RUN_MIGRATIONS=false`.

## Required Render Environment Variables

Set these manually in Render:

```text
APP_KEY=base64:...
APP_URL=https://your-render-service.onrender.com
MAIL_MAILER=smtp
MAIL_HOST=...
MAIL_PORT=465
MAIL_USERNAME=...
MAIL_PASSWORD=...
MAIL_ENCRYPTION=ssl
MAIL_FROM_ADDRESS=verified-sender@your-domain
MAIL_FROM_NAME=Tarnova
```

Render database variables are wired in `render.yaml` when using the Blueprint.


## Render Cost Note

Render's free instance type is available for the web service, but not for background workers or cron jobs. The included `tarnova-worker` and `tarnova-scheduler` services are the production-minded shape, but they may require a paid Render plan.

For the cheapest web-only test:

- deploy only `tarnova-web`
- set `QUEUE_CONNECTION=sync`
- set `MAIL_QUEUE_WHEN_AVAILABLE=false`
- manually run/test scheduled behavior later with worker/scheduler services

## Important Storage Warning

Render web service filesystem is ephemeral unless you use persistent disks or external object storage.

For testing, this is acceptable if you understand uploads may disappear on redeploy/restart.

For serious use, configure external storage such as S3-compatible object storage for:

- company logos
- proof-of-payment files
- backups
- generated private/public storage files

## Queue and Scheduler

The Blueprint includes separate worker services:

- `tarnova-worker` runs `queue:work`
- `tarnova-scheduler` runs `schedule:run` every minute

Do not enable queued mail without the worker running.

## First Deploy Checklist

1. Create the Render Blueprint from `render.yaml` or create services manually.
2. Set `APP_KEY` using `php artisan key:generate --show` locally or generate one securely.
3. Set `APP_URL` to the Render web URL.
4. Add real SMTP settings if testing email.
5. Confirm the first deploy runs migrations.
6. Visit `/up`.
7. Log in.
8. Run through one invoice email or quotation email test.
9. Check Render logs for errors.

## Local Docker Smoke Test

If Docker Desktop is installed, run:

```bash
docker build -t tarnova-render-test .
docker run --rm -p 8080:8080 --env-file .env tarnova-render-test
```

Then open:

```text
http://localhost:8080
```

Use a test database only. Do not point local Docker tests at production data.