# CloudCare — cPanel / Passenger Runtime Deploy (Quick Start)

**Audience:** Operator (hostap user, no root SSH)  
**Architecture:** RC0.5 AD-02 — one Passenger app, Node 20, Option A custom server  
**Full runbook:** `docs/ops/RC1_DEPLOYMENT_RUNBOOK.md`

---

## Prerequisites

- CI artifact: `cloudcare-frontend-runtime-<SHA>-<BUILD_ID>.tar.gz`
- Application root: `/home/hostap/hostap/cloudcare/frontend-nextjs`
- Node.js **20.x** in cPanel Setup Node.js App
- Startup file: `server.js`

---

## 1. Verify artifact before upload

On your workstation:

```bash
tar -tzf cloudcare-frontend-runtime-*.tar.gz | head -20
tar -tzf cloudcare-frontend-runtime-*.tar.gz | grep 'node_modules/next'
tar -xOf cloudcare-frontend-runtime-*.tar.gz ARTIFACT_MANIFEST.json | jq .
sha256sum cloudcare-frontend-runtime-*.tar.gz
```

**Abort if `node_modules/next` is missing.**

---

## 2. Backup live runtime

```bash
STAMP=$(date +%Y%m%d-%H%M%S)
cp -a /home/hostap/hostap/cloudcare/frontend-nextjs \
      /home/hostap/cloudcare/deploy-backups/rc1-pre-${STAMP}
echo "BACKUP=/home/hostap/cloudcare/deploy-backups/rc1-pre-${STAMP}"
```

---

## 3. Stage and extract

```bash
mkdir -p /home/hostap/cloudcare/deploy-staging/extract-${STAMP}
tar -xzf /path/to/cloudcare-frontend-runtime-*.tar.gz \
  -C /home/hostap/cloudcare/deploy-staging/extract-${STAMP}
test -d /home/hostap/cloudcare/deploy-staging/extract-${STAMP}/node_modules/next && echo OK
```

---

## 4. Sync to live (preserve `.env`)

```bash
LIVE=/home/hostap/hostap/cloudcare/frontend-nextjs
STAGE=/home/hostap/cloudcare/deploy-staging/extract-${STAMP}

for item in .next public server.js package.json package-lock.json next.config.js lib node_modules ARTIFACT_MANIFEST.json CPANEL_RUNTIME_DEPLOY.md; do
  if [[ -e "${STAGE}/${item}" ]]; then
    rm -rf "${LIVE}/${item}"
    cp -a "${STAGE}/${item}" "${LIVE}/${item}"
  fi
done
# Do NOT overwrite LIVE/.env if present — use cPanel Environment Variables
```

---

## 5. cPanel settings

| Setting | Value |
|---------|-------|
| Node.js version | **20.x** |
| Application mode | Production |
| Application root | `hostap/cloudcare/frontend-nextjs` |
| Startup file | `server.js` |
| `NODE_ENV` | `production` |
| `NEXT_PUBLIC_*` | See `RC1_RELEASE_MANIFEST.md` |

**Do not set `PORT` manually** — Passenger injects it.

Click **Restart**. Use **Run NPM Install** only if tarball lacked `node_modules` (should not happen with CI artifact).

---

## 6. Verify

```bash
curl -sS https://app.cloudcare.live/health | jq .
curl -sSI https://app.cloudcare.live/health | grep -i passenger
```

Expect HTTP 200, BUILD_ID matches `ARTIFACT_MANIFEST.json`, Passenger log shows `server_ready`.

---

## 7. Rollback

```bash
rm -rf /home/hostap/hostap/cloudcare/frontend-nextjs
cp -a /home/hostap/cloudcare/deploy-backups/rc1-pre-${STAMP} \
      /home/hostap/hostap/cloudcare/frontend-nextjs
# cPanel → Restart
```

See `docs/ops/ROLLBACK_PROCEDURE.md` and `docs/ops/RC1_DEPLOYMENT_RUNBOOK.md`.

---

## Domain binding (RC4 cutover)

Bind **all three** hostnames to the **same** application root:

- `cloudcare.live`
- `www.cloudcare.live`
- `app.cloudcare.live`

Do **not** maintain a second Node app at `/home/hostap/cloudcare.live`.
