mirror of
https://github.com/dong-nz/cv.git
synced 2026-11-23 00:20:40 +07:00
feat(ci): deploy-infra pipeline + env-driven site identity (spec-v4-deploy-infra rev.6-7)
Repo side of spec-v4-deploy-infra: deploy-infra.yml (paths-filtered nginx redeploy, test-before-touch, health probe); compose.yaml rename + secrets/site_config entrypoint override; site identity externalized - SITE_URL/SITE_NAME read from env (site.ts, vite site-identity plugin, index.html tokens, generated robots.txt); nginx.conf/vite dev proxy read GITEA_CONTENTS_API; .env.example; AGENTS.md + specs updated. Rev.7: site identity delivered as Gitea Actions variables (vars. context, public values) instead of secrets; upload-artifact unified to v7 across jobs.
This commit is contained in:
1 parent
a1c249c504
commit
5e9c76c62b
16 files changed
+477
-91
No files matched your search
@@ -0,0 +1,10 @@
|
|||||||
|
# Site identity (build-time). In CI these are Gitea Actions variables on the
|
||||||
|
# build and resume jobs; locally they live in .env. A production build without
|
||||||
|
# them fails with an explicit error (src/data/site.ts, vite site-identity plugin).
|
||||||
|
SITE_URL=
|
||||||
|
SITE_NAME=
|
||||||
|
|
||||||
|
# Edit-mode write path (dev only). Production reads both values from the
|
||||||
|
# stack's secrets/site_config on the VPS, never from a .env.
|
||||||
|
GITEA_TOKEN=
|
||||||
|
GITEA_CONTENTS_API=
|
||||||
@@ -0,0 +1,78 @@
|
|||||||
|
name: Redeploy Nginx
|
||||||
|
|
||||||
|
# Infra files only (spec-v4-deploy-infra D1): a change to the nginx template,
|
||||||
|
# the compose definition, or the Basic-auth file redeploys the container —
|
||||||
|
# content commits never do. workflow_dispatch is the token-rotation runbook.
|
||||||
|
on:
|
||||||
|
push:
|
||||||
|
branches:
|
||||||
|
- master
|
||||||
|
paths:
|
||||||
|
- nginx.conf
|
||||||
|
- compose.yaml
|
||||||
|
- deploy/htpasswd
|
||||||
|
workflow_dispatch:
|
||||||
|
|
||||||
|
concurrency:
|
||||||
|
group: deploy-infra
|
||||||
|
cancel-in-progress: false
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
redeploy:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v7
|
||||||
|
|
||||||
|
# Ship exactly the three triggered files; -R keeps deploy/htpasswd under
|
||||||
|
# deploy/ in the stack directory. Never .env, never secrets/ (D6).
|
||||||
|
- name: Sync infra files
|
||||||
|
uses: burnett01/rsync-deployments@v9
|
||||||
|
with:
|
||||||
|
switches: -avzR
|
||||||
|
path: nginx.conf,compose.yaml,deploy/htpasswd
|
||||||
|
remote_path: /opt/stacks/dong-site/
|
||||||
|
remote_host: ${{ secrets.DEPLOY_HOST }}
|
||||||
|
remote_port: ${{ secrets.DEPLOY_SSH_PORT }}
|
||||||
|
remote_user: ${{ secrets.DEPLOY_USER }}
|
||||||
|
remote_key: ${{ secrets.DEPLOY_SSH_PRIVATE_KEY }}
|
||||||
|
|
||||||
|
# Test-before-touch (D3): the throwaway container runs the same entrypoint
|
||||||
|
# render pipeline as production, with placeholder values — nginx -t checks
|
||||||
|
# syntax only, so the real token never enters this container or the job.
|
||||||
|
# A failure here fails the job; the live container keeps serving.
|
||||||
|
- name: Test new config
|
||||||
|
uses: appleboy/ssh-action@v1.2.0
|
||||||
|
with:
|
||||||
|
host: ${{ secrets.DEPLOY_HOST }}
|
||||||
|
port: ${{ secrets.DEPLOY_SSH_PORT }}
|
||||||
|
username: ${{ secrets.DEPLOY_USER }}
|
||||||
|
key: ${{ secrets.DEPLOY_SSH_PRIVATE_KEY }}
|
||||||
|
script: |
|
||||||
|
cd /opt/stacks/dong-site
|
||||||
|
docker run --rm \
|
||||||
|
-v "$PWD/nginx.conf:/etc/nginx/templates/default.conf.template:ro" \
|
||||||
|
-v "$PWD/deploy/htpasswd:/etc/nginx/htpasswd:ro" \
|
||||||
|
-e GITEA_TOKEN=placeholder \
|
||||||
|
-e GITEA_CONTENTS_API=http://placeholder \
|
||||||
|
-e NGINX_ENVSUBST_FILTER=GITEA_TOKEN,GITEA_CONTENTS_API \
|
||||||
|
nginx:alpine nginx -t
|
||||||
|
|
||||||
|
# Apply + verify (D4): recreate is the same command the Dockge deploy
|
||||||
|
# button runs. The health probe uses wget because nginx:alpine carries no
|
||||||
|
# curl; on failure the job prints the container log and fails.
|
||||||
|
- name: Recreate and probe
|
||||||
|
uses: appleboy/ssh-action@v1.2.0
|
||||||
|
with:
|
||||||
|
host: ${{ secrets.DEPLOY_HOST }}
|
||||||
|
port: ${{ secrets.DEPLOY_SSH_PORT }}
|
||||||
|
username: ${{ secrets.DEPLOY_USER }}
|
||||||
|
key: ${{ secrets.DEPLOY_SSH_PRIVATE_KEY }}
|
||||||
|
script: |
|
||||||
|
cd /opt/stacks/dong-site
|
||||||
|
docker compose up -d --force-recreate dong-site
|
||||||
|
sleep 2
|
||||||
|
if ! docker exec dong-site wget -q -O /dev/null http://127.0.0.1/; then
|
||||||
|
docker logs --tail 50 dong-site
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
docker exec dong-site nginx -t
|
||||||
@@ -12,6 +12,12 @@ concurrency:
|
|||||||
jobs:
|
jobs:
|
||||||
build:
|
build:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
|
# Site identity (spec-v4-deploy-infra D10/D12): the build and the resume
|
||||||
|
# generator derive every published URL and the page title from these two
|
||||||
|
# values; the build fails loudly when either is missing.
|
||||||
|
env:
|
||||||
|
SITE_URL: ${{ vars.SITE_URL }}
|
||||||
|
SITE_NAME: ${{ vars.SITE_NAME }}
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v7
|
- uses: actions/checkout@v7
|
||||||
- uses: pnpm/setup@v3
|
- uses: pnpm/setup@v3
|
||||||
@@ -21,7 +27,7 @@ jobs:
|
|||||||
runtime: node@24
|
runtime: node@24
|
||||||
- run: pnpm tsx scripts/validate-content.ts
|
- run: pnpm tsx scripts/validate-content.ts
|
||||||
- run: pnpm build
|
- run: pnpm build
|
||||||
- uses: actions/upload-artifact@v4
|
- uses: actions/upload-artifact@v7
|
||||||
with:
|
with:
|
||||||
name: static-site
|
name: static-site
|
||||||
path: dist/
|
path: dist/
|
||||||
@@ -30,6 +36,9 @@ jobs:
|
|||||||
generate-resume:
|
generate-resume:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
needs: build
|
needs: build
|
||||||
|
env:
|
||||||
|
SITE_URL: ${{ vars.SITE_URL }}
|
||||||
|
SITE_NAME: ${{ vars.SITE_NAME }}
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v7
|
- uses: actions/checkout@v7
|
||||||
- uses: pnpm/setup@v3
|
- uses: pnpm/setup@v3
|
||||||
|
|||||||
+6
-1
@@ -23,4 +23,9 @@ dist-ssr
|
|||||||
*.sln
|
*.sln
|
||||||
*.sw?
|
*.sw?
|
||||||
/.junie/
|
/.junie/
|
||||||
*.pdf
|
*.pdf
|
||||||
|
|
||||||
|
# Deployment/runtime config (spec-v4-deploy-infra D10/D13): the stack's
|
||||||
|
# secrets/site_config and the local .env carry site identity and the write token.
|
||||||
|
.env
|
||||||
|
/secrets/
|
||||||
@@ -22,12 +22,12 @@ Personal engineering portfolio — multi-page SPA built with React + TypeScript
|
|||||||
| Command | Description |
|
| Command | Description |
|
||||||
|---------|-------------|
|
|---------|-------------|
|
||||||
| `pnpm dev` | Start dev server with HMR |
|
| `pnpm dev` | Start dev server with HMR |
|
||||||
| `pnpm build` | Type-check (`tsc -b`), build for production, then generate `dist/sitemap.xml` |
|
| `pnpm build` | Type-check (`tsc -b`), build for production (the site-identity plugin fills `%SITE_URL%` / `%SITE_NAME%` in `index.html`), then generate `dist/sitemap.xml` + `dist/robots.txt` |
|
||||||
| `pnpm build:resume` | Generate resume PDF (default EN) via Playwright |
|
| `pnpm build:resume` | Generate resume PDF (default EN) via Playwright |
|
||||||
| `pnpm build:resume-all` | Generate bilingual resume PDFs (EN + VI) |
|
| `pnpm build:resume-all` | Generate bilingual resume PDFs (EN + VI) |
|
||||||
| `pnpm lint` | Run Oxlint |
|
| `pnpm lint` | Run Oxlint |
|
||||||
| `pnpm validate:content` | Validate the content dictionaries against the structure documents and the page manifests (also run by the loader at module load) |
|
| `pnpm validate:content` | Validate the content dictionaries against the structure documents and the page manifests (also run by the loader at module load) |
|
||||||
| `pnpm sitemap` | Regenerate `dist/sitemap.xml` on its own (also run by `pnpm build`) |
|
| `pnpm sitemap` | Regenerate `dist/sitemap.xml` + `dist/robots.txt` on its own (also run by `pnpm build`) |
|
||||||
| `pnpm preview` | Preview production build locally |
|
| `pnpm preview` | Preview production build locally |
|
||||||
|
|
||||||
## Routing
|
## Routing
|
||||||
@@ -81,7 +81,7 @@ Content is split once, at authoring time, into language-neutral **structure docu
|
|||||||
- `src/data/resume.ts` — resume availability, supported languages, URL generation, and `resumeQr` (the `{id, file, label}` descriptors the resume header renders as QR codes)
|
- `src/data/resume.ts` — resume availability, supported languages, URL generation, and `resumeQr` (the `{id, file, label}` descriptors the resume header renders as QR codes)
|
||||||
- `src/data/navigation.ts` — `navPaths` (bar + sheet order: Home, About, Experience, Projects, Contact, Philosophy), `footerPaths`
|
- `src/data/navigation.ts` — `navPaths` (bar + sheet order: Home, About, Experience, Projects, Contact, Philosophy), `footerPaths`
|
||||||
- `src/data/social.ts` — social tiles as `{id, href, external}` (github, linkedin, email, telegram); `email` is a `mailto:` link with `external: false`, so it renders no `target`/`rel`
|
- `src/data/social.ts` — social tiles as `{id, href, external}` (github, linkedin, email, telegram); `email` is a `mailto:` link with `external: false`, so it renders no `target`/`rel`
|
||||||
- `src/data/palettes.ts`, `src/data/site.ts` — code config, not content: `siteUrl` (the canonical origin) and `siteName`; every absolute URL the site publishes — canonical, Open Graph, JSON-LD, `robots.txt`, `sitemap.xml` — derives from it
|
- `src/data/palettes.ts`, `src/data/site.ts` — code config, not content: `siteUrl` (the canonical origin) and `siteName` are read from the environment (`SITE_URL` / `SITE_NAME` — CI variables in production, the uncommitted local `.env` in development; unset → the build fails with an error naming the variable); every absolute URL the site publishes — canonical, Open Graph, JSON-LD, `robots.txt`, `sitemap.xml` — derives from it
|
||||||
|
|
||||||
## Live Edit Mode (`?edit`, v4)
|
## Live Edit Mode (`?edit`, v4)
|
||||||
|
|
||||||
@@ -92,7 +92,7 @@ Content is split once, at authoring time, into language-neutral **structure docu
|
|||||||
- `src/components/ui/EditableText.tsx` — the site's own element (`as` = the tag or motion component it renders today) becomes the inline editor only in edit mode; commit on blur only (Vietnamese IME-safe), Esc cancels, Enter commits single-line fields, paste is plain-text, empty required values are rejected at commit; without an `EditContext` provider it renders byte-identical markup to the plain element
|
- `src/components/ui/EditableText.tsx` — the site's own element (`as` = the tag or motion component it renders today) becomes the inline editor only in edit mode; commit on blur only (Vietnamese IME-safe), Esc cancels, Enter commits single-line fields, paste is plain-text, empty required values are rejected at commit; without an `EditContext` provider it renders byte-identical markup to the plain element
|
||||||
- `src/components/layout/EditBar.tsx` — fixed save bar: per-path diff with revert and "appears on" page annotations (computed from the page manifests via `manifestsClaiming`, never from component code), conflict resolution (rebase / take-theirs / per-field keep-mine–keep-theirs), per-document save status, partial-save resume, exit confirm
|
- `src/components/layout/EditBar.tsx` — fixed save bar: per-path diff with revert and "appears on" page annotations (computed from the page manifests via `manifestsClaiming`, never from component code), conflict resolution (rebase / take-theirs / per-field keep-mine–keep-theirs), per-document save status, partial-save resume, exit confirm
|
||||||
- Editable surface: content text inline (pencil-triggered, click never edits) **and** structure — chip-level tag editors (technologies, categories, interests, roles, keywords, tagline emphasis), ghost add/delete/move on every record surface, per-record settings popover (`featured`, project section list + type picker, `variant`, location, logo), ids auto-generated from title slugs, social links handle-only with URLs derived in the loaders. Implemented 2026-10-23 (`spec-v4-inline-editing.md` + `spec-v4-data-organization.md`); the JSON panel is deleted. UI documents stay read-only in v4. Field provenance: hovering any pencil shows `document → pointer` (`describeField()` names the per-entity file automatically); the EditBar diff line and a `validate:content` error for the same field read identically
|
- Editable surface: content text inline (pencil-triggered, click never edits) **and** structure — chip-level tag editors (technologies, categories, interests, roles, keywords, tagline emphasis), ghost add/delete/move on every record surface, per-record settings popover (`featured`, project section list + type picker, `variant`, location, logo), ids auto-generated from title slugs, social links handle-only with URLs derived in the loaders. Implemented 2026-10-23 (`spec-v4-inline-editing.md` + `spec-v4-data-organization.md`); the JSON panel is deleted. UI documents stay read-only in v4. Field provenance: hovering any pencil shows `document → pointer` (`describeField()` names the per-entity file automatically); the EditBar diff line and a `validate:content` error for the same field read identically
|
||||||
- Dev parity: `vite.config.ts` proxies `/api/content/` to the Gitea Contents API exactly like production nginx — run `pnpm dev` with `GITEA_TOKEN` set; without it edit mode falls to the offline state (bundled content, save disabled)
|
- Dev parity: `vite.config.ts` builds the `/api/content/` dev proxy from the same `GITEA_CONTENTS_API` value production nginx renders — run `pnpm dev` with `GITEA_TOKEN` + `GITEA_CONTENTS_API` set (local `.env`); without them edit mode falls to the offline state (bundled content, save disabled)
|
||||||
- Spec: `docs/design/specs/v4/spec-v4-live-edit.md` §5–§6
|
- Spec: `docs/design/specs/v4/spec-v4-live-edit.md` §5–§6
|
||||||
|
|
||||||
## Component Structure
|
## Component Structure
|
||||||
@@ -129,7 +129,7 @@ src/
|
|||||||
- `public/resume-logos/` — official company logo SVGs (Lazada, SAP from Wikimedia Commons), embedded in the resume timeline via `ExperienceEntry.logo`
|
- `public/resume-logos/` — official company logo SVGs (Lazada, SAP from Wikimedia Commons), embedded in the resume timeline via `ExperienceEntry.logo`
|
||||||
- `public/resume-qr/` — owner-supplied QR images (`telegram.jpg`, `zalo.jpg`) embedded in the resume header via `resumeQr` in `src/data/resume.ts`; committed like the other resume assets, so CI renders the QR block too — a missing file prints a warning and that QR is skipped
|
- `public/resume-qr/` — owner-supplied QR images (`telegram.jpg`, `zalo.jpg`) embedded in the resume header via `resumeQr` in `src/data/resume.ts`; committed like the other resume assets, so CI renders the QR block too — a missing file prints a warning and that QR is skipped
|
||||||
- `public/profile-photo.webp` — profile photo
|
- `public/profile-photo.webp` — profile photo
|
||||||
- `public/robots.txt` — allow-all crawler rules plus the `Sitemap:` pointer to the canonical origin
|
- `robots.txt` is generated, not committed: `scripts/generate-sitemap.ts` writes `dist/robots.txt` (allow-all + the `Sitemap:` pointer) from the same `SITE_URL` the sitemap uses — no `public/robots.txt` exists anymore
|
||||||
|
|
||||||
## Scripts
|
## Scripts
|
||||||
|
|
||||||
@@ -138,17 +138,19 @@ src/
|
|||||||
|
|
||||||
## Deployment
|
## Deployment
|
||||||
|
|
||||||
- Deployment is triggered automatically by gitea workflow `.gitea/workflows/deploy.yml`
|
- Site deployment is triggered automatically by gitea workflow `.gitea/workflows/deploy.yml` (push to `master`); infra redeployment by `.gitea/workflows/deploy-infra.yml` — triggered ONLY by changes to `nginx.conf` / `compose.yaml` / `deploy/htpasswd`, plus `workflow_dispatch` (the token-rotation runbook): test-before-touch (`nginx -t` in a throwaway container with placeholder values), then `docker compose up -d --force-recreate` + health probe (spec: `docs/design/specs/v4/spec-v4-deploy-infra.md`)
|
||||||
|
- Site identity is deployment-time configuration, not a repo literal: `SITE_URL` / `SITE_NAME` are Gitea Actions **variables** (`vars.` context — public values, not secrets) passed as job env to `build` and `generate-resume`; locally they live in the uncommitted `.env` (template `.env.example`). A production build without them fails with an error naming the variable
|
||||||
- Three jobs: `build` (`pnpm build` → `dist/` artifact) → `generate-resume` (`pnpm tsx scripts/generate-resume.ts --lang=en`, then `--lang=vi`) → `deploy` rsyncs `dist/`, both PDFs included, to `/opt/stacks/dong-site/dist/`
|
- Three jobs: `build` (`pnpm build` → `dist/` artifact) → `generate-resume` (`pnpm tsx scripts/generate-resume.ts --lang=en`, then `--lang=vi`) → `deploy` rsyncs `dist/`, both PDFs included, to `/opt/stacks/dong-site/dist/`
|
||||||
- `nginx.conf` — production Nginx SPA routing + caching config + the `/api/content/` location: auth_basic (`deploy/htpasswd`) in front of a proxied Gitea Contents API whose write token comes from the `GITEA_TOKEN` environment (envsubst at container start; the token never enters the SPA bundle)
|
- `nginx.conf` — production Nginx SPA routing + caching config + the `/api/content/` location: auth_basic (`deploy/htpasswd`) in front of a proxied Gitea Contents API; the upstream URL and the write token are `${GITEA_CONTENTS_API}` / `${GITEA_TOKEN}` substituted by the image's envsubst step at container start — the token and the Gitea host never enter the SPA bundle or the repository
|
||||||
- `docker-compose.yaml` — Docker service for local nginx deployment; mounts the nginx template + `deploy/htpasswd`, passes `GITEA_TOKEN` through
|
- `compose.yaml` — the stack definition for local AND VPS use (repo copy == stack copy): runtime values live in `secrets/site_config` (gitignored file in the stack directory, two lines `GITEA_TOKEN=` / `GITEA_CONTENTS_API=`, chmod 600), sourced by an entrypoint override before the official entrypoint renders the template; the stack directory has no `.env`. On the VPS the same stack is managed by **Dockge** (upstream; stacks dir `/opt/stacks`, stack file `/opt/stacks/dong-site/compose.yaml`) — the repository is the single source of truth for `nginx.conf` / `compose.yaml` / `deploy/htpasswd`. Repo side implemented 2026-10-23; owner-side setup (Gitea Actions variables, stack `secrets/site_config`) and the first verified run are pending
|
||||||
|
|
||||||
```
|
```
|
||||||
.gitea/
|
.gitea/
|
||||||
└── workflows/
|
└── workflows/
|
||||||
└── deploy.yml
|
├── deploy.yml
|
||||||
|
└── deploy-infra.yml
|
||||||
nginx.conf
|
nginx.conf
|
||||||
docker-compose.yaml
|
compose.yaml
|
||||||
```
|
```
|
||||||
|
|
||||||
## CSS Architecture
|
## CSS Architecture
|
||||||
@@ -191,7 +193,7 @@ All specification documents are in `docs/design/`:
|
|||||||
| `specs/ui/spec-ui-*.md` | UI specs per section (hero, about, expertise, etc.) |
|
| `specs/ui/spec-ui-*.md` | UI specs per section (hero, about, expertise, etc.) |
|
||||||
| `specs/v2/spec-v2-*.md` | v2 feature specs (resume, seo, blog, analytics, testing, cicd) |
|
| `specs/v2/spec-v2-*.md` | v2 feature specs (resume, seo, blog, analytics, testing, cicd) |
|
||||||
| `specs/v3/spec-v3-*.md` | v3 feature specs (theme colors, theme switch, theme palette switch, palette reference, UI enhancements, mobile navigation, nav & CTA enhancements, nav swatch & hamburger, typography, i18n, resume improvements, resume redesign, review fixes) |
|
| `specs/v3/spec-v3-*.md` | v3 feature specs (theme colors, theme switch, theme palette switch, palette reference, UI enhancements, mobile navigation, nav & CTA enhancements, nav swatch & hamburger, typography, i18n, resume improvements, resume redesign, review fixes) |
|
||||||
| `specs/v4/spec-v4-*.md` | v4 feature specs (i18n locale overlay, git-backed live edit with preview, authenticated Contents-API write path; supersedes v3-i18n Phase 2). `spec-v4-data-organization.md`: per-entity content files, per-page field-level manifests, per-feature-group UI — implemented 2026-10-23 (automated checks pass; browser walkthrough pending). `spec-v4-inline-editing.md`: edit everything on the page (pencil-icon triggers, tag chips, record add/delete/move, settings popover), JSON panel deleted — implemented 2026-10-23; it supersedes live-edit §5.1/§5.4 panel scope |
|
| `specs/v4/spec-v4-*.md` | v4 feature specs (i18n locale overlay, git-backed live edit with preview, authenticated Contents-API write path; supersedes v3-i18n Phase 2). `spec-v4-data-organization.md`: per-entity content files, per-page field-level manifests, per-feature-group UI — implemented 2026-10-23 (automated checks pass; browser walkthrough pending). `spec-v4-inline-editing.md`: edit everything on the page (pencil-icon triggers, tag chips, record add/delete/move, settings popover), JSON panel deleted — implemented 2026-10-23; it supersedes live-edit §5.1/§5.4 panel scope. `spec-v4-deploy-infra.md`: pipeline redeploy of the VPS nginx container, Dockge-managed stack (paths-filtered `deploy-infra.yml`, test-before-touch, repo-as-source-of-truth, token-safety rules) + externalizing site identity — `SITE_URL` / `SITE_NAME` as CI Actions variables, `GITEA_TOKEN` + `GITEA_CONTENTS_API` in the stack's single config file `secrets/site_config` — repo side implemented 2026-10-23 (`deploy-infra.yml`, `compose.yaml` secret + entrypoint override, env-driven identity); owner-side variables/config file + first verified run pending |
|
||||||
|
|
||||||
Read `spec.md` first for product context. Read `spec-v2.md` for current feature scope.
|
Read `spec.md` first for product context. Read `spec-v2.md` for current feature scope.
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,36 @@
|
|||||||
|
# Repo-as-source-of-truth copy (spec-v4-deploy-infra D7/D9): rsynced to the
|
||||||
|
# stack directory and run there by the pipeline or Dockge. Runtime values live
|
||||||
|
# in secrets/site_config, which is NOT in the repository — the repo carries no
|
||||||
|
# site identity (D10-D13).
|
||||||
|
services:
|
||||||
|
dong-site:
|
||||||
|
image: nginx:alpine
|
||||||
|
container_name: dong-site
|
||||||
|
restart: unless-stopped
|
||||||
|
# Source the config file, then hand over to the image's official entrypoint.
|
||||||
|
# "$$@" is compose's escape: the rendered command sees "$@", forwarding the
|
||||||
|
# image's default CMD (nginx -g 'daemon off;') — without it nginx
|
||||||
|
# daemonizes and the container exits.
|
||||||
|
entrypoint: ["sh", "-c", ". /run/secrets/site_config && exec /docker-entrypoint.sh \"$$@\""]
|
||||||
|
environment:
|
||||||
|
# Names the variables the template renderer substitutes, so $uri/$host
|
||||||
|
# stay nginx runtime variables. The filter itself is not sensitive.
|
||||||
|
NGINX_ENVSUBST_FILTER: GITEA_TOKEN,GITEA_CONTENTS_API
|
||||||
|
volumes:
|
||||||
|
- ./dist:/usr/share/nginx/html:ro
|
||||||
|
# Mounted as a template: the image's envsubst step renders it to
|
||||||
|
# /etc/nginx/conf.d/default.conf with the variables sourced above.
|
||||||
|
- ./nginx.conf:/etc/nginx/templates/default.conf.template:ro
|
||||||
|
- ./deploy/htpasswd:/etc/nginx/htpasswd:ro
|
||||||
|
secrets:
|
||||||
|
- site_config
|
||||||
|
networks:
|
||||||
|
- docker-network
|
||||||
|
|
||||||
|
secrets:
|
||||||
|
site_config:
|
||||||
|
file: ./secrets/site_config
|
||||||
|
|
||||||
|
networks:
|
||||||
|
docker-network:
|
||||||
|
external: true
|
||||||
+1
-1
@@ -1 +1 @@
|
|||||||
editor:$6$ZLNQoSEIIH8uSXd6$mSxe2JJETZV30nt/Gm..mS4h3VAIBuWdfdqmaFmPknyXpwiKEQ0WR8HZihgTDkDp7hmj5oRqLS2Vnn.e9bBsx0
|
editor:$6$r8s2CI52cy1CMFfV$QeLOi/VWtifP.05NLZlUdbb5GP.FahiHBKYD4LKgOZGXLmEMWq1ODfTrLfpheCt0Rvwctp43h.SyirYFj23ll0
|
||||||
@@ -1,23 +0,0 @@
|
|||||||
services:
|
|
||||||
dong-site:
|
|
||||||
image: nginx:alpine
|
|
||||||
container_name: dong-site
|
|
||||||
restart: unless-stopped
|
|
||||||
environment:
|
|
||||||
# The write token for the /api/content/ proxy (spec-v4 §6.2). Set it in
|
|
||||||
# the local .env; NGINX_ENVSUBST_FILTER restricts the template
|
|
||||||
# substitution to this variable only, so $uri/$host stay nginx runtime
|
|
||||||
# variables.
|
|
||||||
GITEA_TOKEN: ${GITEA_TOKEN}
|
|
||||||
NGINX_ENVSUBST_FILTER: GITEA_TOKEN
|
|
||||||
volumes:
|
|
||||||
- ./dist:/usr/share/nginx/html:ro
|
|
||||||
# Mounted as a template: the image's envsubst step renders it to
|
|
||||||
# /etc/nginx/conf.d/default.conf with GITEA_TOKEN filled in.
|
|
||||||
- ./nginx.conf:/etc/nginx/templates/default.conf.template:ro
|
|
||||||
- ./deploy/htpasswd:/etc/nginx/htpasswd:ro
|
|
||||||
networks:
|
|
||||||
- docker-network
|
|
||||||
networks:
|
|
||||||
docker-network:
|
|
||||||
external: true
|
|
||||||
@@ -0,0 +1,174 @@
|
|||||||
|
# Specification — v4 Deploy Infra (redeploy the nginx container; externalize site identity from the repo)
|
||||||
|
|
||||||
|
Status: **Design agreed 2026-10-23 (rev.7); repo side implemented 2026-10-23; owner-side setup + first run TODO.** Closes the manual half of `spec-v4-live-edit.md` §12 row 11 (the infra files ship with a dedicated pipeline), and per the owner's direction of 2026-10-23 removes explicit site identity (`cv.vugado.com`, `code.vugado.com`, repo path, site name) from the repository — those values become deployment-time configuration (D10–D12). Rev.2 added the Dockge reality (D7, D8); rev.3 recorded the owner's confirmed facts (`DOCKGE_STACKS_DIR=/opt/stacks`, upstream Dockge, `compose.yaml` naming) and the matching repository rename (D9, done); rev.4 added the site-identity externalization design (D10–D12); rev.5 moved `GITEA_TOKEN` off the stack `.env` to a Docker secret file after the owner verified file-based secrets work on the VPS's `docker compose` (non-swarm); rev.6 removes the stack `.env` entirely (owner: "don't use .env") — both server-side values live in ONE file, `secrets/site_config` (D13); rev.7 switches the site-identity channel from Gitea Actions secrets to Actions variables (`vars.` context — public values; owner direction 2026-10-23, `deploy.yml` job env updated). Implementation landed the same day: `deploy-infra.yml`, the §4.1 `compose.yaml`, `site.ts` env read, the vite site-identity plugin + env-driven dev proxy, generated `robots.txt`, `deploy.yml` job env, `.env.example`, AGENTS.md — see §8 for what remains owner-side.
|
||||||
|
|
||||||
|
## 1. Current state
|
||||||
|
|
||||||
|
- `deploy.yml` ships `dist/` by rsync to `/opt/stacks/dong-site/dist/` on the VPS. The live container `dong-site` (compose at `/opt/stacks/dong-site/compose.yaml`) mounts `./dist`, `./nginx.conf` as an envsubst **template**, and `./deploy/htpasswd`.
|
||||||
|
- On the VPS the stack is managed by **Dockge** (upstream — confirmed by the owner 2026-10-23, so D8 applies exactly as written): the stack file is `/opt/stacks/dong-site/compose.yaml` — `DOCKGE_STACKS_DIR=/opt/stacks` confirmed — and day-to-day operations (start/stop/logs/deploy button) happen in the Dockge UI. Dockge reads the compose file from disk every time a stack is opened and its deploy action runs `docker compose` in the same directory — so a pipeline that writes those files and runs the same commands is exactly what Dockge itself would do. There is no hidden Dockge state to keep in sync.
|
||||||
|
- `nginx.conf`, `compose.yaml`, `deploy/htpasswd` are committed but **never deployed**: row 11 made them a one-time manual server step. Three editing surfaces exist (repo, manual SSH, Dockge UI) — drift is therefore possible.
|
||||||
|
- `GITEA_TOKEN` lives only in `/opt/stacks/dong-site/.env` on the VPS; `NGINX_ENVSUBST_FILTER=GITEA_TOKEN` restricts the template substitution to that variable.
|
||||||
|
|
||||||
|
## 2. Why the pipeline is Dockge-safe
|
||||||
|
|
||||||
|
Dockge is a UI over compose files on disk: it reads the stack's `compose.yaml` from the stack directory every time the stack is opened, and its deploy action runs `docker compose` in that same directory. A pipeline that writes exactly those files and runs exactly those commands is doing what the Dockge UI itself does — there is no hidden Dockge state to keep in sync.
|
||||||
|
|
||||||
|
- `rsync` writes the stack's own files in Dockge's stack directory — the same files the Dockge UI opens.
|
||||||
|
- `docker compose up -d --force-recreate` in the stack directory is the same command the Dockge deploy button runs.
|
||||||
|
- The test container (step 3) touches nothing in the stack directory.
|
||||||
|
- Verification after a pipeline run: open the stack in the Dockge UI — it shows the deployed file content and live container state. No extra tooling.
|
||||||
|
|
||||||
|
## 3. Decisions
|
||||||
|
|
||||||
|
| # | Decision | Rationale |
|
||||||
|
|---|---|---|
|
||||||
|
| D1 | A **separate workflow** `deploy-infra.yml`, triggered by `push: master` + `paths: [nginx.conf, compose.yaml, deploy/htpasswd]`, plus `workflow_dispatch` for manual redeploy (the token rotation runbook needs this). `concurrency.group: deploy-infra`, independent of `group: deploy` — the dist rsync and a container restart do not collide. | An infra step inside `deploy.yml` would restart nginx on every content commit, and edit mode saves to `master` ARE content commits. The paths filter is the whole point. |
|
||||||
|
| D2 | Remote commands run through **`appleboy/ssh-action`** (pinned), reusing the existing secrets `DEPLOY_HOST` / `DEPLOY_SSH_PORT` / `DEPLOY_USER` / `DEPLOY_SSH_PRIVATE_KEY`. No new secrets. | Chosen by the owner over raw `ssh` steps; the action handles the key file and host-key checking. |
|
||||||
|
| D3 | **Test-before-touch**: validate the new template in a throwaway `docker run --rm nginx:alpine … nginx -t` on the VPS BEFORE restarting the live container; then `docker compose up -d --force-recreate`; then a health probe. | `nginx -t` against the live container only discovers a bad config after production already took it. A failed test fails the job and production keeps serving the old config. |
|
||||||
|
| D4 | Apply with **`up -d --force-recreate`**, never `nginx -s reload`, never plain `up -d`. | The config is mounted as a template: `envsubst` runs at container start. A reload would keep the previously rendered `default.conf`. Plain `up -d` does not recreate on bind-mount content changes (no config-hash change); `--force-recreate` also covers the case where the trigger was `compose.yaml` or the stack's config file itself. |
|
||||||
|
| D5 | Token-safety rules (§5). The infra workflow never sees `GITEA_TOKEN`; it is not added to Gitea Actions secrets. | The token's home stays server-side only — the stack's single config file (D13) — and the workflow never touches its value. |
|
||||||
|
| D6 | The rsync ships exactly the three triggered files, no `--delete`, never `secrets/`. | The stack's config file is server-side config (rev.6 removed the stack `.env` entirely); `--delete` in a partial rsync would risk wiping stack files. |
|
||||||
|
| D7 | **Single source of truth for the three infra files is the repository.** Production compose/config changes are made in the repo and land through the pipeline; the Dockge UI is used for observation and container operations, not for editing the stack files. | Dockge adds a third editing surface on top of repo and manual SSH. Without this rule the copies drift silently. If a change is ever made in the Dockge UI anyway, the pipeline's next run overwrites it from the repo — so commit it back to the repo first. |
|
||||||
|
| D8 | **No Dockge REST API in this design.** Upstream Dockge has no management API yet (louislam/dockge PR #973, an authenticated management API with `X-API-Key`, is an open draft as of 2026-06-21); the `finder39/dockge` fork has one. If the installed Dockge turns out to be that fork — or the PR lands upstream — the restart/health steps can later move to the API as a simplification, replacing only step 4's docker commands. | Designing against an API that does not exist upstream would block implementation on someone else's merge. |
|
||||||
|
| D9 | The repository compose file is named **`compose.yaml`** (repo root), matching Dockge's stack-file convention and the Compose spec standard name. Renamed 2026-10-23 (`git mv`); `docker compose` discovers it automatically, so local usage is unchanged. The rsync maps repo path → stack path 1:1 with no rename step. | Follow the manager's convention: one name across the repo, the stack directory, and the Dockge UI. The old name would have needed an rsync rename or a second copy on the VPS. |
|
||||||
|
| D10 | **`SITE_URL` (canonical origin) becomes a build-time environment value**, not a repo literal. Repository literals removed: `src/data/site.ts` (reads `process.env.SITE_URL` for the tsx scripts, with an `import.meta.env` fallback for any future browser importer; **unset → throw** — a production build never emits a half-configured sitemap/meta, same loud-failure rule as content validation), `index.html` (the 6 absolute-URL literals — canonical, og:url, og:image, twitter:image, JSON-LD url+image — become `%SITE_URL%` tokens filled by a ~8-line inline `transformIndexHtml` plugin in `vite.config.ts`; dev fallback `http://localhost:5173`), `public/robots.txt` (deleted — `scripts/generate-sitemap.ts` writes `dist/robots.txt` together with `dist/sitemap.xml` from the same value; the existing "index.html contains siteUrl" guard stays and now validates the injection). CI: `env: SITE_URL: ${{ vars.SITE_URL }}` on the `build` and `generate-resume` jobs of `deploy.yml` (rev.7: Actions variables — public values, not secrets; the resume template consumes `{{SITE_URL}}`). Local: uncommitted `.env`, committed `.env.example`. | The owner's rule 2026-10-23: the repo stores no explicit website identity. One value in one place (CI variable / local .env); moving the site to a new domain is a settings change, not a code change. |
|
||||||
|
| D11 | **`GITEA_CONTENTS_API` (full Contents-API base URL, incl. repo path) becomes a runtime configuration value** consumed only by the nginx container and the dev proxy — never CI, never the bundle. Repository literals removed: `nginx.conf` (`proxy_pass ${GITEA_CONTENTS_API};`, rev.6; the `proxy_set_header Host code.vugado.com` line is deleted — nginx's default `$proxy_host` for a literal proxy_pass gives the identical Host header) and `vite.config.ts:19-22` (parse `process.env.GITEA_CONTENTS_API` into proxy target + rewrite prefix; unset → no proxy → edit mode offline, identical to today's no-token behavior). `envsubst` renders at container start **before** nginx parses the config, so the rendered `proxy_pass` is a literal string — no `resolver` needed. Server home: the stack's single config file (D13); local home: the uncommitted local `.env` (vite's standard channel; the dev machine has no Dockge UI). `NGINX_ENVSUBST_FILTER=GITEA_TOKEN,GITEA_CONTENTS_API` stays a plain env var in compose — it names variables to substitute, it is not itself sensitive. | The Gitea host + `dong.nguyen/cv` path is infrastructure, not product — today it appears in `nginx.conf:50,52` and `vite.config.ts:19-22`, so the dev proxy drifts from production by hand; after this both read the same value. The URL is public, so its secret-file home is about **placement** (outside the repo, outside the Dockge env tab), not confidentiality. |
|
||||||
|
| D12 | **`SITE_NAME` (the `<title>`/og:title/twitter:title string) also becomes an env value.** The three `index.html` literals become `%SITE_NAME%` tokens filled by the same plugin; `site.ts`'s `siteName` export (currently **dead** — no consumer in the repo) is kept as the config module's typed accessor for the plugin and scripts. Known duplication recorded: the same person string exists in the content dictionaries (`profile.name` + `profile.title`); meta tags are build-time single-language chrome while content is runtime per-language, so v1 accepts the duplication and the env value. A future single-source option (compose the title from the documents at build time) is a follow-up, not part of this change. | Owner chose "Gồm cả siteName" 2026-10-23. Leaving the name in the repo while the URL moves out would half-solve the stated goal. |
|
||||||
|
| D13 | **The stack's runtime config is ONE server-side file, not `.env`, not multiple files** (owner direction 2026-10-23: "don't use .env", "use only one file"). `compose.yaml`: `secrets: [site_config]` with `secrets.site_config.file = ./secrets/site_config` (stack directory, chmod 600, owner-side, gitignored), a dotenv-format file holding exactly `GITEA_TOKEN=…` and `GITEA_CONTENTS_API=…` (shell-safe values: hex token, URL — no spaces/quotes). The entrypoint sources it before the official entrypoint renders: `entrypoint: ["sh", "-c", ". /run/secrets/site_config && exec /docker-entrypoint.sh \"$$@\""]` — `$$` is compose's escape for a literal `$`, so the rendered container command receives `"$@"`, which forwards the image's default CMD (`nginx -g 'daemon off;'`); without it nginx daemonizes and the container exits. The full target file is §4.1. The stack directory has **no `.env` at all**; no sensitive value appears in compose's `environment:`. File-based secrets under plain `docker compose` (non-swarm) were verified on the VPS 2026-10-23. | Env vars appear in plaintext in the Dockge env editor and in `docker inspect`; a sourced secret file appears in neither (only its path is visible). Startup stays unattended: the file is read at container start, no human key (an "encrypted .env + key" scheme would break pipeline/boot recreations, which have no one to type the key). One file = one rotation surface, one rsync exclusion, one drift candidate. The only remaining plaintext is the rendered `default.conf` inside the container's writable layer — never bind-mounted, never on the host. |
|
||||||
|
|
||||||
|
Env surface (the whole contract): `SITE_URL` + `SITE_NAME` = Gitea Actions **variables** (`vars.` context) on the `build`/`generate-resume` jobs — revised 2026-10-23: these are public values, so Gitea's variables mechanism is the correct channel (secrets are for sensitive values; masked secrets also made a missing/empty `SITE_URL` undiagnosable in logs); `GITEA_TOKEN` + `GITEA_CONTENTS_API` = the stack's single config file `secrets/site_config` (D13; never in `.env`, never in the repository, never in CI, never in the bundle). Local development: an uncommitted local `.env` (vite's standard channel) carries the runtime values; `.env.example` is committed with all four names (`SITE_URL`, `SITE_NAME`, `GITEA_TOKEN`, `GITEA_CONTENTS_API`) and no values.
|
||||||
|
|
||||||
|
## 4. Workflow contract (design, not yet the final YAML)
|
||||||
|
|
||||||
|
```
|
||||||
|
name: Redeploy Nginx
|
||||||
|
on:
|
||||||
|
push: { branches: [master], paths: [nginx.conf, compose.yaml, deploy/htpasswd] }
|
||||||
|
workflow_dispatch:
|
||||||
|
concurrency: { group: deploy-infra, cancel-in-progress: false }
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
redeploy:
|
||||||
|
steps:
|
||||||
|
1 actions/checkout
|
||||||
|
2 burnett01/rsync-deployments — switches: -avzR (no --delete; -R keeps deploy/htpasswd under deploy/)
|
||||||
|
paths: nginx.conf,compose.yaml,deploy/htpasswd (comma-separated input)
|
||||||
|
remote_path: <dockge stack dir>/dong-site/ (existing DEPLOY_* secrets)
|
||||||
|
3 appleboy/ssh-action — script:
|
||||||
|
cd <stack dir>/dong-site
|
||||||
|
docker run --rm \
|
||||||
|
-v "$PWD/nginx.conf:/etc/nginx/templates/default.conf.template:ro" \
|
||||||
|
-v "$PWD/deploy/htpasswd:/etc/nginx/htpasswd:ro" \
|
||||||
|
-e GITEA_TOKEN=placeholder \
|
||||||
|
-e GITEA_CONTENTS_API=http://placeholder \
|
||||||
|
-e NGINX_ENVSUBST_FILTER=GITEA_TOKEN,GITEA_CONTENTS_API \
|
||||||
|
nginx:alpine nginx -t
|
||||||
|
4 appleboy/ssh-action — script:
|
||||||
|
cd <stack dir>/dong-site
|
||||||
|
docker compose up -d --force-recreate dong-site
|
||||||
|
sleep 2
|
||||||
|
docker exec dong-site wget -q -O /dev/null http://127.0.0.1/ # alpine nginx has no curl
|
||||||
|
docker exec dong-site nginx -t
|
||||||
|
On failure: docker logs --tail 50 dong-site (and fail the job)
|
||||||
|
```
|
||||||
|
|
||||||
|
Notes:
|
||||||
|
- The test container renders the template with **pure placeholders on the command line** — `nginx -t` validates syntax only, and `proxy_pass http://placeholder/…` is valid syntax (a literal host needs no resolver check at `-t`). It mounts the template and the htpasswd file (`nginx -t` opens `auth_basic_user_file`); it reads no config file and no secrets: the real values never enter the test container or the job. [INFERENCE: the rsync action's comma-separated `path` input — verify on the first real run; fallback = three single-path steps.]
|
||||||
|
- The health probe uses `wget` (busybox) because `nginx:alpine` carries no curl.
|
||||||
|
- Restart gap is ~1–2 s (single container). Accepted for a personal site; a two-container swap is explicitly out of scope.
|
||||||
|
- `on.push.paths` is evaluated by the act runner — assumed supported on this Gitea [INFERENCE: verify on the first real run]. Fallback if the filter is ignored: a first step that diffs `$GITHUB_BASE_REF..$GITHUB_SHA` (or the head commit) against the trigger paths and exits early.
|
||||||
|
|
||||||
|
### 4.1 Target `compose.yaml` — the complete final file (design contract, not yet applied)
|
||||||
|
|
||||||
|
The repo copy == the stack-directory copy (D7, D9). Diff vs today's file: delete `GITEA_TOKEN: ${GITEA_TOKEN}` from `environment:` (that line is the only compose interpolation today, and it is what makes the value visible in `docker inspect` and the Dockge env tab); add the entrypoint override and the secrets block.
|
||||||
|
|
||||||
|
```yaml
|
||||||
|
# Repo-as-source-of-truth copy (deploy-infra spec D7/D9): rsynced to the stack
|
||||||
|
# directory and run there by the pipeline or Dockge. Runtime values live in
|
||||||
|
# secrets/site_config, which is NOT in the repository — the repo carries no
|
||||||
|
# site identity (D10-D13).
|
||||||
|
services:
|
||||||
|
dong-site:
|
||||||
|
image: nginx:alpine
|
||||||
|
container_name: dong-site
|
||||||
|
restart: unless-stopped
|
||||||
|
# Source the config file, then hand over to the image's official entrypoint.
|
||||||
|
# "$$@" is compose's escape: the rendered command sees "$@", forwarding the
|
||||||
|
# image's default CMD (nginx -g 'daemon off;') — without it nginx
|
||||||
|
# daemonizes and the container exits.
|
||||||
|
entrypoint: ["sh", "-c", ". /run/secrets/site_config && exec /docker-entrypoint.sh \"$$@\""]
|
||||||
|
environment:
|
||||||
|
# Names the variables the template renderer substitutes, so $uri/$host
|
||||||
|
# stay nginx runtime variables. The filter itself is not sensitive.
|
||||||
|
NGINX_ENVSUBST_FILTER: GITEA_TOKEN,GITEA_CONTENTS_API
|
||||||
|
volumes:
|
||||||
|
- ./dist:/usr/share/nginx/html:ro
|
||||||
|
# Mounted as a template: the image's envsubst step renders it to
|
||||||
|
# /etc/nginx/conf.d/default.conf with the variables sourced above.
|
||||||
|
- ./nginx.conf:/etc/nginx/templates/default.conf.template:ro
|
||||||
|
- ./deploy/htpasswd:/etc/nginx/htpasswd:ro
|
||||||
|
secrets:
|
||||||
|
- site_config
|
||||||
|
networks:
|
||||||
|
- docker-network
|
||||||
|
|
||||||
|
secrets:
|
||||||
|
site_config:
|
||||||
|
file: ./secrets/site_config
|
||||||
|
```
|
||||||
|
|
||||||
|
`secrets/site_config` (stack directory, chmod 600, gitignored via `.gitignore` += `secrets/`), exactly two lines:
|
||||||
|
|
||||||
|
```
|
||||||
|
GITEA_TOKEN=<restricted write token>
|
||||||
|
GITEA_CONTENTS_API=https://<gitea-host>/api/v1/repos/<owner>/<repo>/contents/
|
||||||
|
```
|
||||||
|
|
||||||
|
- Same file path and format on the VPS and locally: local `docker compose up` for the nginx test needs the same `secrets/site_config` created locally (gitignored); vite keeps reading the local `.env` (D11) — both local files hold the same two values, neither is committed.
|
||||||
|
- No top-level `name:` key: the stack directory already defines the compose project name (matches today's live behavior — do not add one).
|
||||||
|
- Validation before the first run: `docker compose config --quiet` (run by hand, never inside the infra job — it interpolates).
|
||||||
|
|
||||||
|
## 5. Token security (answers "how to secure the Gitea token?")
|
||||||
|
|
||||||
|
1. **Single home.** `GITEA_TOKEN` lives only in the stack's config file `secrets/site_config` (chmod 600, deploy-user owned; D13), mounted by compose as `/run/secrets/site_config` and sourced at container start by the entrypoint override. Never in the repository, never in any `.env`, never in Gitea Actions secrets, never in the SPA bundle, never in workflow logs.
|
||||||
|
2. **Least scope.** A dedicated Gitea **restricted access token** (not the owner's personal token): repository `dong.nguyen/cv` only, Contents write only, named `site-contents-write`, with an expiry (6 months) so rotation is scheduled, not optional.
|
||||||
|
3. **Transport.** Browser → nginx `/api/content/` (HTTP Basic, `deploy/htpasswd` — SHA-512 crypt hashes, committed; hashes not plaintext) → nginx adds `Authorization: token ${GITEA_TOKEN}` server-side (`nginx.conf:53`) → Gitea over HTTPS. The browser never sees the token; the rendered `default.conf` contains it but the file never leaves the container.
|
||||||
|
4. **No-leak rules for the infra workflow:** never rsync `secrets/`; pass env via placeholders or `--env-file`, never `-e GITEA_TOKEN=$GITEA_TOKEN`; never `cat`/source the config file, run `docker compose config`, or `docker exec … env` inside the job (all print interpolated values); no `set -x` around lines that touch the stack config.
|
||||||
|
5. **Rotation runbook:** create the new restricted token in Gitea → overwrite the `GITEA_TOKEN=` line in the stack's `secrets/site_config` on the VPS → run `deploy-infra` via `workflow_dispatch` (it recreates the container cleanly and health-checks it) → revoke the old token. This is why `workflow_dispatch` is part of D1. The config file is intentionally NOT in the workflow's paths filter: config edits must not auto-trigger a redeploy by themselves; the dispatch IS the deploy step.
|
||||||
|
|
||||||
|
## 6. Risks
|
||||||
|
|
||||||
|
- **Stack drift (blocks the first run):** row 11 applied the config manually on the server, and the Dockge UI is a third editing surface (D7). Before enabling the workflow, diff the stack directory's `nginx.conf` / `compose.yaml` / `htpasswd` against the repo copies; the first run overwrites the server with the repo versions. Note the VPS stack file is already named `compose.yaml` (D9) — the repo rename lands on the same name, no server-side rename is needed. (Owner-side check; no repo access from CI to the VPS.)
|
||||||
|
- **Paths filter support** on the act runner [INFERENCE] — fallback in §4.
|
||||||
|
- A bad `compose.yaml` pushed to master recreates the container with the bad definition; the health probe catches it, and rollback = revert the commit + dispatch again.
|
||||||
|
- **Missing config file:** if `secrets/site_config` does not exist in the stack directory, `docker compose up` fails with a "secret … not found" error — caught at step 4, live container untouched. Mitigation: §8 row 3 creates the file before the first run; D6 never rsyncs `secrets/`, so the pipeline can never delete it.
|
||||||
|
|
||||||
|
## 7. Acceptance criteria
|
||||||
|
|
||||||
|
- [ ] A change to `nginx.conf` on master triggers ONLY `deploy-infra` (no site rebuild, no resume job).
|
||||||
|
- [ ] A content-only commit triggers `deploy.yml` only — no nginx restart.
|
||||||
|
- [ ] First real run: test container passes, container recreates, health probe 200, `?edit` probe authenticates through the proxy.
|
||||||
|
- [ ] After a pipeline run, opening the stack in the Dockge UI shows the synced file content and a healthy container (no split-brain between pipeline state and Dockge view).
|
||||||
|
- [ ] A deliberately broken `nginx.conf` fails the job at the test step; the live site keeps serving the previous config.
|
||||||
|
- [ ] `workflow_dispatch` re-runs the pipeline end-to-end (token rotation runbook).
|
||||||
|
- [ ] No workflow log contains the token or any env-interpolated output.
|
||||||
|
- [ ] No runtime source file (`src/`, `scripts/`, `index.html`, `nginx.conf`, `vite.config.ts`, `public/`) contains `vugado` or the repo path — grep-clean except `dist/` output and historical docs.
|
||||||
|
- [ ] `pnpm build` without `SITE_URL` fails with the explicit error naming the variable; with it, `index.html`, `dist/robots.txt`, `dist/sitemap.xml`, and both resume PDFs carry the injected origin/name — all from one value.
|
||||||
|
- [ ] `pnpm dev` without any env still boots (localhost fallback meta, no `/api/content/` proxy → edit mode offline); with `.env` filled, edit mode works exactly as today.
|
||||||
|
- [ ] The rendered production `default.conf` equals today's hand-written block byte-for-byte given the same `GITEA_CONTENTS_API` value (assert with `docker exec dong-site cat /etc/nginx/conf.d/default.conf` on the first run).
|
||||||
|
- [ ] The stack directory contains no `.env` (rev.6); `docker inspect dong-site` and the Dockge env tab show no `GITEA_TOKEN`/`GITEA_CONTENTS_API` values (D13); the only plaintext token is inside the container's rendered `default.conf`.
|
||||||
|
|
||||||
|
## 8. Progress Tracking
|
||||||
|
|
||||||
|
| # | Task | Status |
|
||||||
|
|---|---|---|
|
||||||
|
| 0 | Design agreed (D1–D9, rev.3 owner facts confirmed) | ✅ Done 2026-10-23 |
|
||||||
|
| 1 | Owner-side confirmations: stack path `/opt/stacks` ✅, upstream Dockge ✅, stack-file name `compose.yaml` ✅ (all confirmed 2026-10-23); remaining: stack-vs-repo drift diff (§6) | 🟡 TODO — drift diff blocks the first run |
|
||||||
|
| 1b | Rename `docker-compose.yaml` → `compose.yaml` (D9) + AGENTS.md references | ✅ Done 2026-10-23 — `git mv`; `docker compose config --quiet` validates (only the expected local `GITEA_TOKEN`-unset warning) |
|
||||||
|
| 2 | `.gitea/workflows/deploy-infra.yml` per §4 | ✅ Done 2026-10-23 — checkout → rsync (-avzR, three files) → test container (placeholders + htpasswd mount) → recreate + wget/nginx -t probe; appleboy/ssh-action pinned v1.2.0 |
|
||||||
|
| 3 | Restricted Gitea token `site-contents-write` (Contents write, expiry) + create stack `secrets/site_config` (chmod 600, two KEY=value lines) | ⬜ TODO — owner-side |
|
||||||
|
| 4 | First verified run + acceptance §7 | ⬜ TODO |
|
||||||
|
| 5 | Docs: AGENTS.md Deployment table + live-edit §12 row 11 status | ✅ Done 2026-10-23 |
|
||||||
|
| 6 | D10–D12 implementation: `site.ts` env read, `index.html` tokens + vite plugin, robots generation, `nginx.conf` variables, `vite.config.ts` env proxy, `deploy.yml` env, `.env.example`, AGENTS.md | ✅ Done 2026-10-23 — verified: `pnpm build` with `.env` filled emits injected meta + `dist/robots.txt`; `SITE_URL=` empty fails with the named-variable error; runtime files grep-clean of `vugado` |
|
||||||
|
| 9 | D13 implementation: `compose.yaml` per §4.1 (secret `site_config` + entrypoint override), `.gitignore` += `secrets/`; VPS: create `secrets/site_config`, delete stack `.env` | 🟡 Repo side Done 2026-10-23 (`compose config --quiet` validates); owner-side file + stack `.env` removal TODO |
|
||||||
|
| 7 | Owner-side: Gitea Actions **variables** `SITE_URL`, `SITE_NAME` (rev.: switched from secrets 2026-10-23 — public values belong in the `vars.` context); local `.env` from `.env.example` | 🟡 Local `.env` created 2026-10-23 (values known; `GITEA_TOKEN` left as shell env as before); Gitea variables TODO — owner-side |
|
||||||
@@ -589,7 +589,7 @@ Deferred (not v4):
|
|||||||
| 8 | 22 consumer files migrated; `field.ts`/`strings.ts` deleted | 1 | ✅ Done 2026-10-22 |
|
| 8 | 22 consumer files migrated; `field.ts`/`strings.ts` deleted | 1 | ✅ Done 2026-10-22 |
|
||||||
| 9 | Resume generator migrated to shared documents | 1 | ✅ Done 2026-10-22 |
|
| 9 | Resume generator migrated to shared documents | 1 | ✅ Done 2026-10-22 |
|
||||||
| 10 | Phase 1 verified (build, validate, lint, resume-PDF text diff, browser walkthrough) | 1 | ✅ Automated checks Done 2026-10-22 — `tsc -b`, `pnpm validate:content`, `pnpm lint` (no new warnings), `pnpm build`, `pnpm build:resume-all` all pass; the resume verification was **stronger than planned**: the generated resume HTML (`--dump-html`, both languages) is byte-identical before and after the migration, so no pdftotext diff was needed. A throwaway SSR smoke (`react-dom/server` over the real provider tree) rendered all 7 routes × both languages and matched EN/VI markers from the joined dictionaries (display names, section headings, philosophy quotes, project detail, contact links); it was deleted after the run. ⬜ Browser walkthrough of all 7 routes, both languages — owner |
|
| 10 | Phase 1 verified (build, validate, lint, resume-PDF text diff, browser walkthrough) | 1 | ✅ Automated checks Done 2026-10-22 — `tsc -b`, `pnpm validate:content`, `pnpm lint` (no new warnings), `pnpm build`, `pnpm build:resume-all` all pass; the resume verification was **stronger than planned**: the generated resume HTML (`--dump-html`, both languages) is byte-identical before and after the migration, so no pdftotext diff was needed. A throwaway SSR smoke (`react-dom/server` over the real provider tree) rendered all 7 routes × both languages and matched EN/VI markers from the joined dictionaries (display names, section headings, philosophy quotes, project detail, contact links); it was deleted after the run. ⬜ Browser walkthrough of all 7 routes, both languages — owner |
|
||||||
| 11 | Production nginx step (§6.3) | 2 | ⬜ TODO — server step + `GITEA_TOKEN` are owner-side; the Phase-1 JSON documents must also be pushed to the repository before the proxy answers 200 |
|
| 11 | Production nginx step (§6.3) | 2 | 🟡 Partial 2026-10-23 — the content documents (now the per-entity layout) are pushed and on `master`. The server-side automation is now implemented repo-side: `spec-v4-deploy-infra.md` rev.6 — `deploy-infra.yml` ships `nginx.conf` / `compose.yaml` / `deploy/htpasswd` and redeploys the container (test-before-touch); the runtime values (`GITEA_TOKEN`, `GITEA_CONTENTS_API`) move from the stack `.env` to the stack's single config file `secrets/site_config`. Remaining owner-side: create `secrets/site_config` on the VPS (delete the stack `.env`), add Gitea Actions variables `SITE_URL` / `SITE_NAME` (deploy-infra rev.7), first verified run |
|
||||||
| 12 | Local proxy config + compose + auth | 2 | ✅ Done 2026-10-22 — `nginx.conf` template location, compose env/htpasswd mounts, `deploy/htpasswd`. Compose smoke: unauthenticated GET → 401 + `WWW-Authenticate: Basic realm="Editor"`; authenticated request passes htpasswd and reaches Gitea (answers 404 `rel_path` — the JSON documents are not yet pushed and `GITEA_TOKEN` is unset locally, so the 200/412 legs land with row 11). `vite.config.ts` dev proxy mirrors nginx exactly |
|
| 12 | Local proxy config + compose + auth | 2 | ✅ Done 2026-10-22 — `nginx.conf` template location, compose env/htpasswd mounts, `deploy/htpasswd`. Compose smoke: unauthenticated GET → 401 + `WWW-Authenticate: Basic realm="Editor"`; authenticated request passes htpasswd and reaches Gitea (answers 404 `rel_path` — the JSON documents are not yet pushed and `GITEA_TOKEN` is unset locally, so the 200/412 legs land with row 11). `vite.config.ts` dev proxy mirrors nginx exactly |
|
||||||
| 13 | Edit mode 3a: draft store, inline editing, save happy path | 3 | ✅ Done 2026-10-22 (automated) — `draft.ts` (copy-on-write, path diff, origin/base separation + three-way rebase, sessionStorage snapshot, sequential-PUT save, id-union append), `edit-mode.ts` (`?edit`, session flag, Basic probe, dirty guard), `EditableText.tsx` (§5.3 contract), `useEdit.ts` context split, `App.tsx` lazy `MaybeEditMode` gate; editable surface wrapped in Hero/About/AboutPage/Expertise/Experience/ExperiencePage/Projects/ProjectsListPage/ProjectDetailPage. Verified: `pnpm build` (EditModeShell is a separate 24 kB lazy chunk, entry unchanged), `pnpm lint` (no new warnings), `scripts/smoke-draft.ts` 7/7 (accept/reject, empty-required, orphan-free delete, template, snapshot round-trip, conflict detection, clean rebase). ⬜ Browser: IME dấu commit on blur, cross-page live preview, reload restores the draft |
|
| 13 | Edit mode 3a: draft store, inline editing, save happy path | 3 | ✅ Done 2026-10-22 (automated) — `draft.ts` (copy-on-write, path diff, origin/base separation + three-way rebase, sessionStorage snapshot, sequential-PUT save, id-union append), `edit-mode.ts` (`?edit`, session flag, Basic probe, dirty guard), `EditableText.tsx` (§5.3 contract), `useEdit.ts` context split, `App.tsx` lazy `MaybeEditMode` gate; editable surface wrapped in Hero/About/AboutPage/Expertise/Experience/ExperiencePage/Projects/ProjectsListPage/ProjectDetailPage. Verified: `pnpm build` (EditModeShell is a separate 24 kB lazy chunk, entry unchanged), `pnpm lint` (no new warnings), `scripts/smoke-draft.ts` 7/7 (accept/reject, empty-required, orphan-free delete, template, snapshot round-trip, conflict detection, clean rebase). ⬜ Browser: IME dấu commit on blur, cross-page live preview, reload restores the draft |
|
||||||
| 14 | Edit mode 3b: JSON panel + record templates | 3 | ✅ Done 2026-10-22 (automated) — `JsonPanel.tsx`: per-document tabs + read-only `ui` tabs, shape hints, templates (project / experience / skill-group / philosophy / section-with-project-picker), record list + confirm-gated delete (structure + both text documents in one validated step), side-by-side hand-merge for conflicted documents, parse + validator status line. Verified via an SSR wiring smoke (`react-dom/server`, vi markup: tabs, templates, delete controls, status) — deleted after the run. **Superseded 2026-10-23 by `spec-v4-inline-editing.md` E1**: the panel will be deleted; templates and orphan-free delete are reused by on-page controls. ⬜ Browser: add/delete → live preview + validator behavior (re-targeted to the inline controls) |
|
| 14 | Edit mode 3b: JSON panel + record templates | 3 | ✅ Done 2026-10-22 (automated) — `JsonPanel.tsx`: per-document tabs + read-only `ui` tabs, shape hints, templates (project / experience / skill-group / philosophy / section-with-project-picker), record list + confirm-gated delete (structure + both text documents in one validated step), side-by-side hand-merge for conflicted documents, parse + validator status line. Verified via an SSR wiring smoke (`react-dom/server`, vi markup: tabs, templates, delete controls, status) — deleted after the run. **Superseded 2026-10-23 by `spec-v4-inline-editing.md` E1**: the panel will be deleted; templates and orphan-free delete are reused by on-page controls. ⬜ Browser: add/delete → live preview + validator behavior (re-targeted to the inline controls) |
|
||||||
|
|||||||
+13
-10
@@ -1,41 +1,44 @@
|
|||||||
<!doctype html>
|
<!doctype html>
|
||||||
<html lang="en">
|
<html lang="en">
|
||||||
<head>
|
<head>
|
||||||
|
<!-- The site identity values in this head are filled at build time by the
|
||||||
|
site-identity vite plugin; they come from the CI variables SITE_URL /
|
||||||
|
SITE_NAME or the local .env, never from this file. -->
|
||||||
<meta charset="UTF-8" />
|
<meta charset="UTF-8" />
|
||||||
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
||||||
<title>Nguyễn Đông — Senior Software Engineer</title>
|
<title>%SITE_NAME%</title>
|
||||||
<meta
|
<meta
|
||||||
name="description"
|
name="description"
|
||||||
content="Portfolio of Nguyễn Đông, a Senior Software Engineer in Ho Chi Minh City working on distributed systems, logistics automation, computer vision and practical AI in Java, Go and TypeScript."
|
content="Portfolio of Nguyễn Đông, a Senior Software Engineer in Ho Chi Minh City working on distributed systems, logistics automation, computer vision and practical AI in Java, Go and TypeScript."
|
||||||
/>
|
/>
|
||||||
<meta name="author" content="Nguyễn Đông" />
|
<meta name="author" content="Nguyễn Đông" />
|
||||||
<meta name="robots" content="index, follow" />
|
<meta name="robots" content="index, follow" />
|
||||||
<link rel="canonical" href="https://cv.vugado.com/" />
|
<link rel="canonical" href="%SITE_URL%/" />
|
||||||
<meta name="theme-color" content="#151914" media="(prefers-color-scheme: dark)" />
|
<meta name="theme-color" content="#151914" media="(prefers-color-scheme: dark)" />
|
||||||
<meta name="theme-color" content="#f6f5f2" media="(prefers-color-scheme: light)" />
|
<meta name="theme-color" content="#f6f5f2" media="(prefers-color-scheme: light)" />
|
||||||
|
|
||||||
<meta property="og:type" content="website" />
|
<meta property="og:type" content="website" />
|
||||||
<meta property="og:site_name" content="Nguyễn Đông — Senior Software Engineer" />
|
<meta property="og:site_name" content="%SITE_NAME%" />
|
||||||
<meta property="og:title" content="Nguyễn Đông — Senior Software Engineer" />
|
<meta property="og:title" content="%SITE_NAME%" />
|
||||||
<meta
|
<meta
|
||||||
property="og:description"
|
property="og:description"
|
||||||
content="Distributed systems, logistics automation, computer vision and practical AI — SAP Lab Vietnam, Lazada, and a logistics digital-twin platform."
|
content="Distributed systems, logistics automation, computer vision and practical AI — SAP Lab Vietnam, Lazada, and a logistics digital-twin platform."
|
||||||
/>
|
/>
|
||||||
<meta property="og:url" content="https://cv.vugado.com/" />
|
<meta property="og:url" content="%SITE_URL%/" />
|
||||||
<meta property="og:locale" content="en_US" />
|
<meta property="og:locale" content="en_US" />
|
||||||
<meta property="og:locale:alternate" content="vi_VN" />
|
<meta property="og:locale:alternate" content="vi_VN" />
|
||||||
<meta property="og:image" content="https://cv.vugado.com/profile-photo.webp" />
|
<meta property="og:image" content="%SITE_URL%/profile-photo.webp" />
|
||||||
<meta property="og:image:width" content="1200" />
|
<meta property="og:image:width" content="1200" />
|
||||||
<meta property="og:image:height" content="1600" />
|
<meta property="og:image:height" content="1600" />
|
||||||
<meta property="og:image:alt" content="Portrait of Nguyễn Đông" />
|
<meta property="og:image:alt" content="Portrait of Nguyễn Đông" />
|
||||||
|
|
||||||
<meta name="twitter:card" content="summary_large_image" />
|
<meta name="twitter:card" content="summary_large_image" />
|
||||||
<meta name="twitter:title" content="Nguyễn Đông — Senior Software Engineer" />
|
<meta name="twitter:title" content="%SITE_NAME%" />
|
||||||
<meta
|
<meta
|
||||||
name="twitter:description"
|
name="twitter:description"
|
||||||
content="Distributed systems, logistics automation, computer vision and practical AI — SAP Lab Vietnam, Lazada, and a logistics digital-twin platform."
|
content="Distributed systems, logistics automation, computer vision and practical AI — SAP Lab Vietnam, Lazada, and a logistics digital-twin platform."
|
||||||
/>
|
/>
|
||||||
<meta name="twitter:image" content="https://cv.vugado.com/profile-photo.webp" />
|
<meta name="twitter:image" content="%SITE_URL%/profile-photo.webp" />
|
||||||
|
|
||||||
<link rel="icon" type="image/svg+xml" href="/favicon.svg" />
|
<link rel="icon" type="image/svg+xml" href="/favicon.svg" />
|
||||||
|
|
||||||
@@ -46,9 +49,9 @@
|
|||||||
"name": "Nguyễn Đông",
|
"name": "Nguyễn Đông",
|
||||||
"alternateName": "Dong Nguyen",
|
"alternateName": "Dong Nguyen",
|
||||||
"jobTitle": "Senior Software Engineer",
|
"jobTitle": "Senior Software Engineer",
|
||||||
"url": "https://cv.vugado.com/",
|
"url": "%SITE_URL%/",
|
||||||
"email": "mailto:nguyendong_bkdn@yahoo.com",
|
"email": "mailto:nguyendong_bkdn@yahoo.com",
|
||||||
"image": "https://cv.vugado.com/profile-photo.webp",
|
"image": "%SITE_URL%/profile-photo.webp",
|
||||||
"sameAs": [
|
"sameAs": [
|
||||||
"https://github.com/dong-nz",
|
"https://github.com/dong-nz",
|
||||||
"https://www.linkedin.com/in/dong-nz"
|
"https://www.linkedin.com/in/dong-nz"
|
||||||
|
|||||||
+6
-6
@@ -39,17 +39,17 @@ server {
|
|||||||
log_not_found off;
|
log_not_found off;
|
||||||
}
|
}
|
||||||
|
|
||||||
# Content write path (spec-v4 §6.2): Basic-auth at the proxy, the Gitea
|
# Content write path (spec-v4 §6.2, spec-v4-deploy-infra D11/D13): Basic-auth
|
||||||
# write token lives only in the container environment (${GITEA_TOKEN} is
|
# at the proxy; ${GITEA_TOKEN} and ${GITEA_CONTENTS_API} are substituted by
|
||||||
# substituted by the image's envsubst template step — the SPA bundle never
|
# the image's envsubst template step from the container environment (sourced
|
||||||
# carries a write-capable token).
|
# from the stack's secrets/site_config) — the SPA bundle and the repository
|
||||||
|
# never carry the token or the Gitea host.
|
||||||
location /api/content/ {
|
location /api/content/ {
|
||||||
auth_basic "Editor";
|
auth_basic "Editor";
|
||||||
auth_basic_user_file /etc/nginx/htpasswd;
|
auth_basic_user_file /etc/nginx/htpasswd;
|
||||||
|
|
||||||
proxy_pass https://code.vugado.com/api/v1/repos/dong.nguyen/cv/contents/;
|
proxy_pass ${GITEA_CONTENTS_API};
|
||||||
proxy_ssl_server_name on;
|
proxy_ssl_server_name on;
|
||||||
proxy_set_header Host code.vugado.com;
|
|
||||||
proxy_set_header Authorization "token ${GITEA_TOKEN}";
|
proxy_set_header Authorization "token ${GITEA_TOKEN}";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,4 +0,0 @@
|
|||||||
User-agent: *
|
|
||||||
Allow: /
|
|
||||||
|
|
||||||
Sitemap: https://cv.vugado.com/sitemap.xml
|
|
||||||
@@ -14,13 +14,15 @@ if (!existsSync(distDir)) {
|
|||||||
process.exit(1);
|
process.exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
// index.html carries the canonical origin as static markup; site.ts carries it as data.
|
// The published head is generated from %SITE_URL% tokens (site-identity vite
|
||||||
// A mismatch means one of the two was edited without the other.
|
// plugin, spec-v4-deploy-infra D10); this guard validates that the injection
|
||||||
|
// actually happened with the same value this script derives its URLs from — a
|
||||||
|
// mismatch means the build ran without a consistent SITE_URL.
|
||||||
const indexHtml = readFileSync(join(distDir, 'index.html'), 'utf-8');
|
const indexHtml = readFileSync(join(distDir, 'index.html'), 'utf-8');
|
||||||
if (!indexHtml.includes(siteUrl)) {
|
if (!indexHtml.includes(siteUrl)) {
|
||||||
console.error(
|
console.error(
|
||||||
`Canonical origin mismatch: index.html does not contain "${siteUrl}". ` +
|
`Canonical origin mismatch: dist/index.html does not contain "${siteUrl}". ` +
|
||||||
`Update the canonical/og:url/theme-color block in index.html or src/data/site.ts.`
|
`The site-identity plugin injects it from SITE_URL — check the build environment.`,
|
||||||
);
|
);
|
||||||
process.exit(1);
|
process.exit(1);
|
||||||
}
|
}
|
||||||
@@ -42,3 +44,10 @@ const xml = `<?xml version="1.0" encoding="UTF-8"?>\n<urlset xmlns="http://www.s
|
|||||||
|
|
||||||
writeFileSync(join(distDir, 'sitemap.xml'), xml);
|
writeFileSync(join(distDir, 'sitemap.xml'), xml);
|
||||||
console.log(`sitemap.xml generated at ${join(distDir, 'sitemap.xml')} (${locations.length} urls)`);
|
console.log(`sitemap.xml generated at ${join(distDir, 'sitemap.xml')} (${locations.length} urls)`);
|
||||||
|
|
||||||
|
// robots.txt is generated here too (spec-v4-deploy-infra D10): the Sitemap:
|
||||||
|
// pointer must derive from the same siteUrl as the sitemap itself, so there is
|
||||||
|
// no committed robots.txt that could drift from it.
|
||||||
|
const robots = `User-agent: *\nAllow: /\n\nSitemap: ${siteUrl}/sitemap.xml\n`;
|
||||||
|
writeFileSync(join(distDir, 'robots.txt'), robots);
|
||||||
|
console.log(`robots.txt generated at ${join(distDir, 'robots.txt')}`);
|
||||||
+57
-3
@@ -1,4 +1,58 @@
|
|||||||
/** Canonical origin. Every absolute URL the site publishes derives from this one value. */
|
/**
|
||||||
export const siteUrl = 'https://cv.vugado.com'
|
* Site identity — deployment-time configuration, not a repository literal
|
||||||
|
* (spec-v4-deploy-infra D10/D12). CI supplies SITE_URL / SITE_NAME as Gitea
|
||||||
|
* Actions variables on the build and resume jobs; local runs read them from the
|
||||||
|
* uncommitted `.env` (see `.env.example`). A missing value fails loudly — a
|
||||||
|
* half-configured sitemap, meta block or resume is never emitted.
|
||||||
|
*
|
||||||
|
* Browser code does not import this module today; the scripts
|
||||||
|
* (`generate-sitemap.ts`, `generate-resume.ts`) and the vite build plugin are
|
||||||
|
* its consumers.
|
||||||
|
*/
|
||||||
|
|
||||||
export const siteName = 'Nguyễn Đông — Senior Software Engineer'
|
type EnvRecord = Record<string, string | undefined>;
|
||||||
|
|
||||||
|
interface RuntimeProcess {
|
||||||
|
env?: EnvRecord;
|
||||||
|
loadEnvFile?: (path?: string) => void;
|
||||||
|
}
|
||||||
|
|
||||||
|
// The tsx runtime carries `process`; the app tsconfig (vite/client types only)
|
||||||
|
// deliberately does not declare it. `typeof` keeps the check safe in any
|
||||||
|
// runtime; the module is not imported by browser code today.
|
||||||
|
declare const process: RuntimeProcess | undefined;
|
||||||
|
const runtimeProcess = typeof process === 'undefined' ? undefined : process;
|
||||||
|
|
||||||
|
if (runtimeProcess?.loadEnvFile) {
|
||||||
|
try {
|
||||||
|
runtimeProcess.loadEnvFile();
|
||||||
|
} catch {
|
||||||
|
// No local .env — the real environment must carry the values.
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// `import.meta.env` is typed by vite/client for browser builds and is
|
||||||
|
// undefined under tsx; the spread covers both worlds.
|
||||||
|
const env: EnvRecord = { ...import.meta.env, ...runtimeProcess?.env };
|
||||||
|
|
||||||
|
function required(name: string, purpose: string): string {
|
||||||
|
const value = env[name];
|
||||||
|
if (!value) {
|
||||||
|
throw new Error(
|
||||||
|
`${name} is not set — ${purpose}. Provide it as an environment variable ` +
|
||||||
|
`(CI secret) or in the local .env; see .env.example.`,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Canonical origin. Every absolute URL the site publishes derives from this one value. */
|
||||||
|
export const siteUrl = required(
|
||||||
|
'SITE_URL',
|
||||||
|
'canonical URLs, the sitemap, robots.txt and resume links are derived from it',
|
||||||
|
);
|
||||||
|
|
||||||
|
export const siteName = required(
|
||||||
|
'SITE_NAME',
|
||||||
|
'the page title and the Open Graph / Twitter meta are filled from it',
|
||||||
|
);
|
||||||
+59
-26
@@ -1,33 +1,66 @@
|
|||||||
import path from 'path'
|
import path from 'path'
|
||||||
import react from '@vitejs/plugin-react'
|
import react from '@vitejs/plugin-react'
|
||||||
import { defineConfig } from 'vite'
|
import { defineConfig, loadEnv, type Plugin } from 'vite'
|
||||||
|
|
||||||
export default defineConfig({
|
// Site identity (spec-v4-deploy-infra D10/D12): index.html carries %SITE_URL% /
|
||||||
plugins: [react()],
|
// %SITE_NAME% tokens and this plugin fills them at build time from the
|
||||||
resolve: {
|
// environment — CI variables in production, the local .env in development. A
|
||||||
alias: {
|
// production build without them fails loudly, like content validation.
|
||||||
'@': path.resolve(import.meta.dirname, './src'),
|
function siteIdentity(): Plugin {
|
||||||
|
let siteUrl = ''
|
||||||
|
let siteName = ''
|
||||||
|
return {
|
||||||
|
name: 'site-identity',
|
||||||
|
configResolved(config) {
|
||||||
|
const loaded = loadEnv(config.mode, config.root, '')
|
||||||
|
siteUrl = process.env.SITE_URL || loaded.SITE_URL || ''
|
||||||
|
siteName = process.env.SITE_NAME || loaded.SITE_NAME || ''
|
||||||
|
if (config.command === 'build' && (!siteUrl || !siteName)) {
|
||||||
|
throw new Error(
|
||||||
|
'SITE_URL / SITE_NAME are not set — the production build needs the site identity. ' +
|
||||||
|
'Provide them as CI variables (Gitea Actions variables) or in the local .env; see .env.example.',
|
||||||
|
)
|
||||||
|
}
|
||||||
|
// Dev fallbacks keep `pnpm dev` bootable with no environment at all.
|
||||||
|
if (!siteUrl) siteUrl = 'http://localhost:5173'
|
||||||
|
if (!siteName) siteName = 'Portfolio (dev)'
|
||||||
},
|
},
|
||||||
},
|
transformIndexHtml(html) {
|
||||||
server: {
|
return html.replaceAll('%SITE_URL%', siteUrl).replaceAll('%SITE_NAME%', siteName)
|
||||||
// Mirror the production nginx `/api/content/` proxy (spec-v4 §6.2) so edit
|
},
|
||||||
// mode works against the real repository during development. Start with
|
}
|
||||||
// `GITEA_TOKEN=... pnpm dev`; without the token the proxy answers 404 and
|
}
|
||||||
// edit mode falls back to the offline state.
|
|
||||||
proxy: {
|
export default defineConfig(({ mode }) => {
|
||||||
'/api/content/': {
|
const env = loadEnv(mode, process.cwd(), '')
|
||||||
target: 'http://192.168.10.8:3080',
|
const contentsApiUrl = env.GITEA_CONTENTS_API || process.env.GITEA_CONTENTS_API || ''
|
||||||
changeOrigin: true,
|
// Dev parity with the production nginx `/api/content/` proxy (spec-v4 §6.2):
|
||||||
rewrite: (p) => {
|
// both read the same GITEA_CONTENTS_API value. Without it there is no proxy —
|
||||||
return p.replace(/^\/api\/content\//, '/api/v1/repos/dong.nguyen/cv/contents/');
|
// edit mode falls back to the offline state, exactly like a missing token.
|
||||||
},
|
const contentsApi = contentsApiUrl ? new URL(contentsApiUrl) : null
|
||||||
configure: (proxy) => {
|
return {
|
||||||
proxy.on('proxyReq', (proxyReq) => {
|
plugins: [react(), siteIdentity()],
|
||||||
const token = process.env.GITEA_TOKEN
|
resolve: {
|
||||||
if (token) proxyReq.setHeader('Authorization', `token ${token}`)
|
alias: {
|
||||||
})
|
'@': path.resolve(import.meta.dirname, './src'),
|
||||||
},
|
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
server: {
|
||||||
|
proxy: contentsApi
|
||||||
|
? {
|
||||||
|
'/api/content/': {
|
||||||
|
target: contentsApi.origin,
|
||||||
|
changeOrigin: true,
|
||||||
|
rewrite: (p) => p.replace(/^\/api\/content\//, contentsApi.pathname),
|
||||||
|
configure: (proxy) => {
|
||||||
|
proxy.on('proxyReq', (proxyReq) => {
|
||||||
|
const token = env.GITEA_TOKEN || process.env.GITEA_TOKEN
|
||||||
|
if (token) proxyReq.setHeader('Authorization', `token ${token}`)
|
||||||
|
})
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
: undefined,
|
||||||
|
},
|
||||||
|
}
|
||||||
})
|
})
|
||||||
Reference in new issue
Block a user