mirror of
https://github.com/dong-nz/cv.git
synced 2026-11-22 16:10: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
+59
-26
@@ -1,33 +1,66 @@
|
||||
import path from 'path'
|
||||
import react from '@vitejs/plugin-react'
|
||||
import { defineConfig } from 'vite'
|
||||
import { defineConfig, loadEnv, type Plugin } from 'vite'
|
||||
|
||||
export default defineConfig({
|
||||
plugins: [react()],
|
||||
resolve: {
|
||||
alias: {
|
||||
'@': path.resolve(import.meta.dirname, './src'),
|
||||
// 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 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)'
|
||||
},
|
||||
},
|
||||
server: {
|
||||
// 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: {
|
||||
'/api/content/': {
|
||||
target: 'http://192.168.10.8:3080',
|
||||
changeOrigin: true,
|
||||
rewrite: (p) => {
|
||||
return p.replace(/^\/api\/content\//, '/api/v1/repos/dong.nguyen/cv/contents/');
|
||||
},
|
||||
configure: (proxy) => {
|
||||
proxy.on('proxyReq', (proxyReq) => {
|
||||
const token = process.env.GITEA_TOKEN
|
||||
if (token) proxyReq.setHeader('Authorization', `token ${token}`)
|
||||
})
|
||||
},
|
||||
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.GITEA_CONTENTS_API || process.env.GITEA_CONTENTS_API || ''
|
||||
// Dev parity with the production nginx `/api/content/` proxy (spec-v4 §6.2):
|
||||
// both read the same GITEA_CONTENTS_API value. 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.GITEA_TOKEN || process.env.GITEA_TOKEN
|
||||
if (token) proxyReq.setHeader('Authorization', `token ${token}`)
|
||||
})
|
||||
},
|
||||
},
|
||||
}
|
||||
: undefined,
|
||||
},
|
||||
}
|
||||
})
|
||||
Reference in new issue
Block a user