# Render deploy checklist

## Why deploy failed with `127.0.0.1`

Render ran `db:prepare` but Rails had **no Aiven connection settings**, so it used the default host **`127.0.0.1`** (localhost). There is no MySQL inside the Render container.

Fix: add **Environment** variables on the **Web Service** (same values as local `.env`).

## Required environment variables

In Render → **farm_backend** → **Environment** → add:

| Key | Value |
|-----|--------|
| `RAILS_ENV` | `production` |
| `DB_HOST` | Aiven host (`mysql-….d.aivencloud.com`) |
| `DB_PORT` | `15229` (your Aiven port) |
| `DB_USERNAME` | `avnadmin` |
| `DB_PASSWORD` | from Aiven |
| `DB_DATABASE` | `defaultdb` |
| `SECRET_KEY_BASE` | from your `.env` |
| `JWT_SECRET_KEY` | from your `.env` |
| `DB_SSL_CA` | **Full PEM text** of `config/certs/aiven-ca.pem` (file is not in git) |

Interim OTP without SMS (testing only):

| Key | Value |
|-----|--------|
| `OTP_INCLUDE_IN_RESPONSE` | `true` — returns OTP in `/request-otp` JSON; **remove when Fast2SMS is on** |
| `INTERNAL_SHARED_TOTP_SECRET` | optional — defaults to `JBSWY3DPEHPK3PXP` so **one Google Authenticator entry works for all 3-series** (see [totp.md](totp.md)) |

Recommended (Sidekiq + faster OTP); OTP also stored on user row if Redis is down:


| Key | Value |
|-----|--------|
| `REDIS_URL` | Render Key Value **Internal** URL |

Optional for uploaded photo URLs:

| Key | Value |
|-----|--------|
| `APP_HOST` | `https://farm-backend-kiei.onrender.com` — **required** for app photo upload URLs |

Cron alert password (GitHub Actions header `X-Cron-Secret`; not used by the app):

| Key | Value |
|-----|--------|
| `CRON_SECRET` | from local `.env` (`GrowKit-…`). Same string as GitHub secret `CRON_SECRET`. |

## Service settings

| Setting | Value |
|---------|--------|
| **Health Check Path** | `/health` |
| **Pre-deploy command** | *(leave empty — entrypoint runs `db:prepare` on start)* |
| **Docker Command** | leave default (`puma` via Dockerfile) |

## Keep the Free instance awake

Render **Free** web services spin down after **15 minutes** with no HTTP traffic. The next request then cold-starts for **~50 seconds**.

This repo pings `GET /health` about every 10 minutes via GitHub Actions (`.github/workflows/keep-alive.yml`) — under Render’s 15-minute idle window. GitHub cron can skip runs; confirm under Actions that a run’s event is **schedule**, not only **workflow_dispatch**. After this file is on `main`:

1. GitHub → **Actions** → enable workflows if asked.
2. Optional: repo **Settings → Variables → Actions** → `HEALTH_URL` = `https://farm-backend-kiei.onrender.com/health` (defaults to that URL if unset).
3. **Actions → Keep Render awake → Run workflow** once to confirm.

This uses most of the **750 free instance hours/month**. Upgrade to **Starter** if the API must stay up without relying on GitHub cron.

If you set a custom start command, use:

```bash
bundle exec puma -C config/puma.rb
```

## After saving env vars

**Manual Deploy** → **Deploy latest commit** (or push a new commit).

Success: logs show `db:prepare` without connection errors, then Puma listening. Test:

```text
https://YOUR-SERVICE.onrender.com/health
```

## Empty mall feed (no listings)

**Render → Shell** (or local Docker + Aiven `.env`):

```bash
bundle exec rails db:seed
```

Adds ~10 demo listings, sellers (incl. **Sahooo** `8688259303`), and listing photos (external URLs).  
Check: `GET /mall/listings` → `{ "listings": [...], "live_members_count": <random 1–10000>, "has_more": ... }`.

Re-seed: `FORCE_DEMO_SEED=true bundle exec rails db:seed`
