# Customer Deployment

This package supports two customer deployment paths:

- New machine: bootstrap missing runtime dependencies, install project dependencies, copy the bundled env file, and start the app.
- Existing machine: keep the existing `.env`, refresh dependencies with `pnpm install --frozen-lockfile`, and start the app.

## Quick Start

From the package root:

```bash
bash scripts/install.sh
```

Useful variants:

```bash
bash scripts/install.sh --no-start
bash scripts/install.sh --prod
bash scripts/install.sh --prod --reset-db
bash scripts/install.sh --with-python
bash scripts/install.sh --env-file /secure/path/.env
```

By default, Python is not installed because the current document extraction flow does not require the old local document conversion runtime. Use `--with-python` only for deployments that explicitly need uv and Python 3.13.

## Env Handling

Real secrets must not be committed to Git.

For customer delivery, generate a local artifact from the development machine:

```bash
pnpm build:delivery-bundle -- --env-file .env
```

The bundle source defaults to the latest version-sorted tag in the delivery repository. Use `--tag <tag>` to rebuild a specific delivered version.
Archive names include the delivery tag. Dry runs plan `<name>-<tag>.delivery.tar.gz`; real bundles include the resolved delivery commit too: `<name>-<tag>-<shortsha>.delivery.tar.gz`.

`pnpm publish:delivery --yes --delivery-tag <tag>` automatically tags `origin/main`, publishes the single-commit delivery repository, tags that delivery commit with the same tag, and creates the customer delivery bundle for that tag after the push succeeds. Running `pnpm build:delivery-bundle` manually is only needed when you want to regenerate the package without pushing again.

The generated archive contains:

```text
deploy/env/.env
```

On the customer machine, `scripts/install.sh` copies that file to the package root as `.env` only when `.env` does not already exist. Existing customer `.env` files are never overwritten.

## Startup Modes

Default mode runs:

```bash
pnpm install --frozen-lockfile
pnpm run dev
```

Production mode delegates to the existing deployment script:

```bash
bash scripts/install.sh --prod
```

That path reuses `scripts/deploy.sh` for Docker, Supabase, build, and systemd/nohup startup behavior.

## Logs

Runtime logs are written under:

```text
logs/
```

When production mode falls back to nohup, the app log is:

```text
logs/app.log
```
