Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,16 @@
# sudo tee -a /etc/hosts <<EOF
# 127.0.0.1 auth-dev.velobits.dev
# 127.0.0.1 api-dev.velobits.dev
# 127.0.0.1 develop-fixmytext.velobits.dev
# 127.0.0.1 local-fixmytext.velobits.dev
# EOF
#
# Without these entries the OIDC redirects + API calls will fail.
# The local host must stay a *.velobits.dev name (Keycloak redirect URIs + the
# `.velobits.dev`-scoped SSO cookie), but it must NOT shadow a deployed one:
# develop-fixmytext.velobits.dev is the live develop origin and
# fixmytext.velobits.dev is production - an /etc/hosts entry for either would
# make the real site unreachable from this machine. Hence the `local-` prefix,
# which is reserved for loopback and never deployed.

# ── Backend API URL (Kong API gateway behind Traefik) ─────────────────────
VITE_API_URL=http://api-dev.velobits.dev
Expand Down
43 changes: 31 additions & 12 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,21 @@
# content (Worker, OpenNext - SSR/SEO + share OG cards, bot-routed) ─┘
#
# ── Environments ─────────────────────────────────────────────────────────────
# Every unit is a SEPARATE Cloudflare project per environment, named `<unit>` on
# production and `develop-<unit>` on develop, each with its own
# <project>.velobits.dev / develop-<project>.velobits.dev custom domain.
# Pages custom domains can only ever serve a project's production branch, so
# develop cannot be a branch alias of the production project - hence the split.
# Branch → GitHub environment → Cloudflare target:
# main → production → Pages production deployments (bare *.pages.dev URLs)
# + worker `fixmytext-router` [manual dispatch only]
# develop → develop → Pages branch deployments (develop.<project>.pages.dev)
# + worker `develop-fixmytext-router` (wrangler --env develop)
# main → production → Pages projects fixmytext-{shell,editor-remote,analytics-remote}
# + workers `fixmytext-{content,router}` [manual dispatch only]
# develop → develop → Pages projects develop-fixmytext-{shell,editor-remote,analytics-remote}
# + workers `develop-fixmytext-{content,router}` (wrangler --env develop)
# [auto on green CI]
# Both tracks deploy to their own project's PRODUCTION branch (`--branch main`);
# the environment is selected by `--project-name` (Pages) / `--env` (Workers),
# never by the branch. The custom domains are declared in the wrangler configs,
# so the CI token needs Zone → DNS → Edit + Zone → Workers Routes → Edit too.
#
# ── Selective deploys (deploy "versions") ────────────────────────────────────
# After each successful deploy, the commit is tagged `deployed/<env>/<app>`
Expand All @@ -30,8 +39,8 @@
# vars.VITE_API_URL, vars.VITE_KEYCLOAK_URL, vars.VITE_KEYCLOAK_REALM,
# vars.VITE_KEYCLOAK_CLIENT_ID, vars.VITE_KEYCLOAK_ENABLED_PROVIDERS (+ Sentry as needed)
# vars.NEXT_PUBLIC_SITE_URL = that environment's public origin (content OG/canonical URLs)
# (Confirm the CF Pages project names in package.json deploy:* scripts match your
# account, and that each Pages project's "Production branch" setting is `main`.)
# (All six Pages projects must exist before the first run, and every one of them
# must have its "Production branch" setting = `main`.)
name: Deploy (Cloudflare)

# Release model (asymmetric):
Expand Down Expand Up @@ -139,8 +148,12 @@ jobs:
needs: changes
if: needs.changes.outputs.any_remote == 'true'
env:
DEPLOY_BRANCH: ${{ github.event.workflow_run.head_branch || github.ref_name }}
DEPLOY_ENV: ${{ (github.event.workflow_run.head_branch || github.ref_name) == 'main' && 'production' || 'develop' }}
# Prefixes the Cloudflare project name to select the environment's project.
# The non-main branch carries the truthy operand so production resolves to a
# genuinely empty string (`cond && '' || x` always yields x - empty strings
# are falsy in GitHub expressions).
CF_PROJECT_PREFIX: ${{ (github.event.workflow_run.head_branch || github.ref_name) != 'main' && 'develop-' || '' }}
strategy:
matrix:
# Only the remotes the `changes` job flagged.
Expand All @@ -157,10 +170,14 @@ jobs:
cache: npm
- run: npm ci
- name: Build & deploy ${{ matrix.remote }}-remote to Cloudflare Pages
# --branch selects production vs branch-alias deployment on the same
# Pages project (develop → https://develop.<project>.pages.dev).
run: npm run deploy:${{ matrix.remote }} -- --branch "$DEPLOY_BRANCH"
# The environment is chosen by CF_PAGES_PROJECT_* (which project), not by
# --branch: each project has its own custom domain, and a Pages custom
# domain only serves that project's production branch. Only the variable
# matching this matrix leg is read by the deploy:<remote> script.
run: npm run deploy:${{ matrix.remote }} -- --branch main
env:
CF_PAGES_PROJECT_EDITOR: ${{ env.CF_PROJECT_PREFIX }}fixmytext-editor-remote
CF_PAGES_PROJECT_ANALYTICS: ${{ env.CF_PROJECT_PREFIX }}fixmytext-analytics-remote
VITE_API_URL: ${{ vars.VITE_API_URL }}
- name: Update deploy marker tag
run: |
Expand All @@ -179,8 +196,9 @@ jobs:
needs.changes.outputs.shell == 'true' &&
(needs.deploy-remotes.result == 'success' || needs.deploy-remotes.result == 'skipped')
env:
DEPLOY_BRANCH: ${{ github.event.workflow_run.head_branch || github.ref_name }}
DEPLOY_ENV: ${{ (github.event.workflow_run.head_branch || github.ref_name) == 'main' && 'production' || 'develop' }}
# See the CF_PROJECT_PREFIX note on deploy-remotes for the expression shape.
CF_PROJECT_PREFIX: ${{ (github.event.workflow_run.head_branch || github.ref_name) != 'main' && 'develop-' || '' }}
steps:
- uses: actions/checkout@34e114876b0b11c390a56381ad16ebd13914f8d5 # v4.3.1
with:
Expand All @@ -193,8 +211,9 @@ jobs:
cache: npm
- run: npm ci
- name: Build & deploy shell to Cloudflare Pages
run: npm run deploy:shell -- --branch "$DEPLOY_BRANCH"
run: npm run deploy:shell -- --branch main
env:
CF_PAGES_PROJECT_SHELL: ${{ env.CF_PROJECT_PREFIX }}fixmytext-shell
# Federation entry points baked into the host bundle - must point at the
# environment's router so the browser loads each remote under /remotes/<name>/.
VITE_EDITOR_REMOTE_ENTRY: ${{ vars.VITE_EDITOR_REMOTE_ENTRY }}
Expand Down
25 changes: 22 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ frontend/
└── package.json ← npm workspace root
```

### Path routing (via Cloudflare Worker + Traefik at `develop-fixmytext.velobits.dev`)
### Path routing (via Cloudflare Worker in the cloud, Traefik at `local-fixmytext.velobits.dev` locally)

| URL prefix | App | Framework |
| ---------------------- | ----------------------- | -------------------------------- |
Expand All @@ -31,6 +31,25 @@ frontend/
> `apps/content` (Next.js) is no longer routed on this origin — the shell owns
> the origin root. The container is parked and only reachable directly.

### Deployed origins (`velobits.dev`)

Everything is hosted on the `velobits.dev` zone. A service's Cloudflare project
name is its hostname label; the develop copy is the same name prefixed
`develop-`. The **router is the only origin users should see** — the rest are
addressable for debugging, and all canonical/OG URLs point at the router.

| Service | production | develop |
| --------------------- | ---------------------------------------------- | ------------------------------------------------------ |
| Router (public) | `fixmytext.velobits.dev` | `develop-fixmytext.velobits.dev` |
| Shell (Pages) | `fixmytext-shell.velobits.dev` | `develop-fixmytext-shell.velobits.dev` |
| Editor remote (Pages) | `fixmytext-editor-remote.velobits.dev` | `develop-fixmytext-editor-remote.velobits.dev` |
| Analytics (Pages) | `fixmytext-analytics-remote.velobits.dev` | `develop-fixmytext-analytics-remote.velobits.dev` |
| Content (Worker) | `fixmytext-content.velobits.dev` | `develop-fixmytext-content.velobits.dev` |

Local dev uses `local-fixmytext.velobits.dev` (loopback via `/etc/hosts`) —
never map a deployed hostname to `127.0.0.1`. Setup reference:
[`docs/cloudflare-pages-setup.md`](docs/cloudflare-pages-setup.md).

## Prerequisites

- Node.js 20+
Expand All @@ -50,7 +69,7 @@ Add these to your dev machine's `/etc/hosts` (one-time):
sudo tee -a /etc/hosts <<EOF
127.0.0.1 auth-dev.velobits.dev
127.0.0.1 api-dev.velobits.dev
127.0.0.1 develop-fixmytext.velobits.dev
127.0.0.1 local-fixmytext.velobits.dev
EOF
```

Expand Down Expand Up @@ -107,7 +126,7 @@ npm run dev -w @velobits/content-app # http://localhost:3103
```

With Traefik running (`docker compose --profile dev up`), all apps are accessible
at `http://develop-fixmytext.velobits.dev` with path-based routing.
at `http://local-fixmytext.velobits.dev` with path-based routing.

## Scripts

Expand Down
7 changes: 6 additions & 1 deletion apps/content/.env.example
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,12 @@ CONTENT_API_URL=http://api-dev.velobits.dev
NEXT_PUBLIC_API_URL=http://api-dev.velobits.dev

# ── Site URL (for OG meta + canonical URLs) ────────────────────────────────
NEXT_PUBLIC_SITE_URL=http://develop-fixmytext.velobits.dev
# Always the *router* origin for the environment - never this worker's own
# hostname - so canonical/OG URLs point at the single public entry point:
# local http://local-fixmytext.velobits.dev
# develop https://develop-fixmytext.velobits.dev
# production https://fixmytext.velobits.dev
NEXT_PUBLIC_SITE_URL=http://local-fixmytext.velobits.dev

# ── Auth.js ────────────────────────────────────────────────────────────────
# Generate with: openssl rand -base64 32
Expand Down
2 changes: 1 addition & 1 deletion apps/content/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ Visit:

### Path routing

Traefik routes by path within `develop-fixmytext.velobits.dev`:
Traefik routes by path within `local-fixmytext.velobits.dev`:

| Path | → App | Port |
| -------------------------------- | ----------- | ---- |
Expand Down
20 changes: 19 additions & 1 deletion apps/content/wrangler.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,31 @@ compatibility_flags = ["nodejs_compat"]
[assets]
directory = ".open-next/assets"

# Workers Custom Domain on the velobits.dev zone (wrangler creates the DNS record
# and hostname binding on deploy). The router still reaches this worker through
# its CONTENT service binding - the domain exists so the worker is addressable
# on velobits.dev rather than workers.dev, and so the local-dev fallback in
# worker/src/index.ts has a fetchable host.
#
# SEO note: this hostname serves the same HTML as the router origin. That is
# harmless because every page's canonical/OG URL is built from
# NEXT_PUBLIC_SITE_URL (app/layout.tsx metadataBase, sitemap.ts, robots.ts),
# which points at the router origin - keep that variable set per environment.
[[routes]]
pattern = "fixmytext-content.velobits.dev"
custom_domain = true

# ── Develop environment ──────────────────────────────────────────────────────
# Deployed by CI from the `develop` branch (wrangler deploy --env develop).
# Runtime secrets (AUTH_SECRET, COOKIE_SECRET) are per-worker - set them on
# BOTH workers via the dashboard (Secrets survive deploys; plaintext vars don't).
[env.develop]
name = "develop-fixmytext-content"

# Assets are not inherited into env blocks - redeclare.
# Assets and routes are not inherited into env blocks - redeclare.
[env.develop.assets]
directory = ".open-next/assets"

[[env.develop.routes]]
pattern = "develop-fixmytext-content.velobits.dev"
custom_domain = true
2 changes: 1 addition & 1 deletion apps/shell/playwright.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { defineConfig, devices } from '@playwright/test';

// The Vite app is served at the origin root (Vite base: '/').
// E2E_FRONTEND_URL overrides the full origin (without path suffix).
const FRONTEND_URL = process.env.E2E_FRONTEND_URL || 'http://develop-fixmytext.velobits.dev:3100';
const FRONTEND_URL = process.env.E2E_FRONTEND_URL || 'http://local-fixmytext.velobits.dev:3100';

export default defineConfig({
testDir: './e2e',
Expand Down
Loading
Loading