mirror of
https://github.com/dong-nz/cv.git
synced 2026-11-22 16:10:40 +07:00
GitHub becomes the primary repository host; the site keeps its VPS + nginx + Dockge host, the three-job pipeline and the same concurrency, so what moves is the CI host and the write-path target. .github/workflows/{deploy,deploy-infra}.yml are ports of the Gitea files with permissions: contents: read on every job. .gitea/workflows/ stays until the first green GitHub run (D9); its infra test step carries the new template variable names because the template it validates is the one this repository now ships.
The write-path values are renamed GITEA_TOKEN / GITEA_CONTENTS_API -> CONTENT_API_TOKEN / CONTENT_API_BASE and the upstream header becomes Bearer — in nginx.conf, in the compose envsubst filter and in the dev proxy, so dev and production send the identical header (D4). draft.ts learns GitHub's answer to a stale blob sha (409) while keeping the 422 "does not match" and 412 legs; smoke-draft.ts check 14 drives a stubbed proxy that answers 409 with GitHub's body and asserts the conflict refreshes the base, keeps the draft and never stops the save sequence.
Both workflows read the stack directory and the compose service / container name from the STACK_DIR and CONTAINER_NAME repository variables instead of hard-coding them, and each job refuses a missing, relative, trailing-slash or compose-disagreeing value in its first step, before any artifact download or rsync reaches the VPS (D15).
Verified: tsc -b and oxlint pass with no new warnings; validate:content, smoke-draft (14 checks) and smoke-generated-ids (7 checks) pass; both workflows parse, every run/script block passes bash -n with the variables substituted, and the guard refuses every bad value against the real compose.yaml. Owner-side variables, secrets, the write token and the VPS config rewrite stay open in spec-v6 §6.
70 lines
2.8 KiB
TypeScript
70 lines
2.8 KiB
TypeScript
import path from 'path'
|
|
import react from '@vitejs/plugin-react'
|
|
import { defineConfig, loadEnv, type Plugin } from 'vite'
|
|
|
|
// Site identity (spec-v4-deploy-infra D10/D12): index.html carries %SITE_URL% /
|
|
// %SITE_NAME% tokens and this plugin fills them at build time from the
|
|
// environment — CI variables in production, the local .env in development. A
|
|
// production build without them fails loudly, like content validation.
|
|
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 repository variables (GitHub Actions) 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) {
|
|
return html.replaceAll('%SITE_URL%', siteUrl).replaceAll('%SITE_NAME%', siteName)
|
|
},
|
|
}
|
|
}
|
|
|
|
export default defineConfig(({ mode }) => {
|
|
const env = loadEnv(mode, process.cwd(), '')
|
|
const contentsApiUrl = env.CONTENT_API_BASE || process.env.CONTENT_API_BASE || ''
|
|
// Dev parity with the production nginx `/api/content/` proxy (spec-v4 §6.2,
|
|
// spec-v6 D4): both read the same CONTENT_API_BASE value and send the same
|
|
// Authorization form. Without it there is no proxy — edit mode falls back to
|
|
// the offline state, exactly like a missing token.
|
|
const contentsApi = contentsApiUrl ? new URL(contentsApiUrl) : null
|
|
return {
|
|
plugins: [react(), siteIdentity()],
|
|
resolve: {
|
|
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.CONTENT_API_TOKEN || process.env.CONTENT_API_TOKEN
|
|
// Bearer, not the legacy "token" prefix: the dev proxy must send
|
|
// exactly what the production nginx proxy sends (spec-v6 D4).
|
|
if (token) proxyReq.setHeader('Authorization', `Bearer ${token}`)
|
|
})
|
|
},
|
|
},
|
|
}
|
|
: undefined,
|
|
},
|
|
}
|
|
})
|