|
| 1 | +# Deploying mploy (Oracle Cloud + Dokploy) |
| 2 | + |
| 3 | +mploy (the MAC Jobs Board webapp) runs as a Docker container on an Oracle |
| 4 | +Cloud VM, fronted by [Dokploy](https://dokploy.com). This mirrors the setup |
| 5 | +used for our sibling repo `monmap`. |
| 6 | + |
| 7 | +## Architecture: build off-box, run on-box |
| 8 | + |
| 9 | +The Oracle VM is shared by several apps (monmap, mploy, monashcoding). A |
| 10 | +Docker build peaks at 2–4 GB RAM and pegs the CPU; several racing on one box |
| 11 | +is how you OOM production. So **we never build on the Oracle box**: |
| 12 | + |
| 13 | +``` |
| 14 | +push to production ──▶ GitHub Actions (ubuntu-24.04-arm) |
| 15 | + │ builds linux/arm64 image |
| 16 | + ▼ |
| 17 | + GHCR: ghcr.io/monashcoding/mploy:latest |
| 18 | + │ Dokploy pulls (webhook-triggered) |
| 19 | + ▼ |
| 20 | + Oracle VM: `node server.js` (~200–400 MB idle) |
| 21 | +``` |
| 22 | + |
| 23 | +The box only ever runs the finished containers. |
| 24 | + |
| 25 | +## This app's shape (why the config looks the way it does) |
| 26 | + |
| 27 | +- The webapp is `frontend/` — a **self-contained npm app** (not a pnpm |
| 28 | + workspace), so the Docker **build context is `frontend/`** and deps install |
| 29 | + with `npm ci` from `frontend/package-lock.json`. The Spring Boot `backend/` |
| 30 | + is a separate service, not part of this image. |
| 31 | +- Next.js is built with `output: "standalone"`; the runtime just runs |
| 32 | + `node server.js`. `outputFileTracingRoot` is pinned to `frontend/` so the |
| 33 | + standalone entrypoint always lands at `.next/standalone/server.js`. |
| 34 | +- **No build-time vars.** There are no `NEXT_PUBLIC_*` values (the Google |
| 35 | + Analytics id is hardcoded), and `next build` does **not** touch MongoDB — |
| 36 | + every DB-backed route is `force-dynamic` or reads `searchParams`, so nothing |
| 37 | + is prerendered against the database. Everything below is therefore a |
| 38 | + **runtime** env var set in Dokploy; nothing is baked into the image. |
| 39 | + |
| 40 | +## One-time GitHub setup |
| 41 | + |
| 42 | +1. **Repo Secret** (Settings → Secrets and variables → Actions → _Secrets_): |
| 43 | + - `DOKPLOY_DEPLOY_WEBHOOK` = the deploy webhook URL Dokploy generates for |
| 44 | + the app (added after the Dokploy step below). Until it exists, the |
| 45 | + workflow builds/pushes the image but skips the redeploy trigger. |
| 46 | +2. **Make the GHCR package public** (or give Dokploy a read token) so the VM |
| 47 | + can pull without auth: after the first push, open the package at |
| 48 | + `github.com/orgs/monashcoding/packages` → Package settings → change |
| 49 | + visibility to Public. |
| 50 | + |
| 51 | +There are no repo _Variables_ to set — the build takes no build-args. |
| 52 | + |
| 53 | +## One-time Dokploy setup |
| 54 | + |
| 55 | +1. **Create Application** → Provider: **Docker**. |
| 56 | + - Image: `ghcr.io/monashcoding/mploy:latest` |
| 57 | + - (If you kept the package private: add GHCR registry credentials — a |
| 58 | + GitHub PAT with `read:packages`.) |
| 59 | +2. **Environment** (runtime vars): |
| 60 | + ``` |
| 61 | + MONGODB_URI=mongodb+srv://<user>:<pass>@<atlas-cluster>/<db> |
| 62 | + MONGODB_DATABASE=default |
| 63 | + NEXTAUTH_SECRET=<random secret> |
| 64 | + NEXTAUTH_URL=https://jobs.monashcoding.com |
| 65 | + GOOGLE_CLIENT_ID=<oauth client id> |
| 66 | + GOOGLE_CLIENT_SECRET=<oauth client secret> |
| 67 | + NOTION_API_KEY=<notion integration token> |
| 68 | + NOTION_DATABASE_ID=<notion database id> |
| 69 | + ``` |
| 70 | + MongoDB is hosted externally (Atlas), so `MONGODB_URI` is a normal |
| 71 | + `mongodb+srv://` connection string — no on-box private-IP caveat. Make sure |
| 72 | + the Atlas cluster's IP access list allows the Oracle VM's egress IP. |
| 73 | +3. **Port**: container listens on `3000`. |
| 74 | +4. **Domains**: add `jobs.monashcoding.com` → container port `3000` → enable |
| 75 | + HTTPS (Let's Encrypt). |
| 76 | + - DNS is on Cloudflare. **Grey-cloud (DNS-only)** the record first so |
| 77 | + Dokploy/Traefik can complete the Let's Encrypt HTTP-01 challenge and |
| 78 | + issue the cert, then switch it back to **orange-cloud (proxied)** |
| 79 | + afterwards. |
| 80 | +5. **Deploy webhook**: copy the app's deploy webhook URL into the GitHub repo |
| 81 | + secret `DOKPLOY_DEPLOY_WEBHOOK` (GitHub setup step 1) so each pushed image |
| 82 | + auto-redeploys. |
| 83 | + |
| 84 | +## Deploying a change |
| 85 | + |
| 86 | +Push to `production`. GitHub Actions builds + pushes the image, then hits the |
| 87 | +Dokploy webhook, which pulls and restarts the container. Watch the run under |
| 88 | +the repo's Actions tab; watch the pull/restart in Dokploy. |
| 89 | + |
| 90 | +To deploy manually: Actions → **Build & publish image** → _Run workflow_, then |
| 91 | +hit **Deploy** in Dokploy. |
| 92 | + |
| 93 | +## Notes |
| 94 | + |
| 95 | +- `next build` does **not** touch MongoDB, so `MONGODB_URI` is a runtime-only |
| 96 | + var. There are no build-args at all. |
| 97 | +- The container runs as a non-root user (`nextjs`, uid 1001). |
| 98 | +- The image is `linux/arm64` only — it runs on the Ampere A1 box and won't run |
| 99 | + on an x86 host without emulation. |
0 commit comments