perf: preserve Docker npm cache - version bumps only touch version.txt, not package.json
continuous-integration/webhook Deploy concluído (VPS4)
continuous-integration/webhook Deploy concluído (VPS4)
This commit is contained in:
@@ -500,8 +500,13 @@ app.get('/login', (req, res) => {
|
|||||||
// Função utilitária de Cache Buster
|
// Função utilitária de Cache Buster
|
||||||
async function serveHtmlWithCacheBuster(res, filePath) {
|
async function serveHtmlWithCacheBuster(res, filePath) {
|
||||||
try {
|
try {
|
||||||
const pkg = require('./package.json');
|
// Lê version.txt (não package.json) para não ter cache-miss no Docker a cada deploy
|
||||||
const APP_VERSION = pkg.version || Date.now();
|
let APP_VERSION;
|
||||||
|
try {
|
||||||
|
APP_VERSION = (await fs.readFile(path.join(__dirname, 'version.txt'), 'utf8')).trim();
|
||||||
|
} catch (_) {
|
||||||
|
APP_VERSION = require('./package.json').version || Date.now();
|
||||||
|
}
|
||||||
let content = await fs.readFile(filePath, 'utf8');
|
let content = await fs.readFile(filePath, 'utf8');
|
||||||
|
|
||||||
// Injeta versão em tags de script e css
|
// Injeta versão em tags de script e css
|
||||||
|
|||||||
+2
-1
@@ -58,8 +58,9 @@ ssh -o BatchMode=yes -o StrictHostKeyChecking=no "${PROD_USER}@${PROD_VPS}" "
|
|||||||
"
|
"
|
||||||
|
|
||||||
# 5. Commit do bump de versão de volta ao Gitea (listener ignora → sem loop)
|
# 5. Commit do bump de versão de volta ao Gitea (listener ignora → sem loop)
|
||||||
|
# package.json não é incluído propositalmente: preserva o cache de npm install no Docker
|
||||||
log "💾 git commit + push do bump de versão..."
|
log "💾 git commit + push do bump de versão..."
|
||||||
git add dental-server/version.txt dental-server/package.json dental-server/public/index.html
|
git add dental-server/version.txt dental-server/public/index.html
|
||||||
git commit -m "chore(deploy): bump version" || true
|
git commit -m "chore(deploy): bump version" || true
|
||||||
git push origin main || true
|
git push origin main || true
|
||||||
|
|
||||||
|
|||||||
+3
-8
@@ -6,7 +6,6 @@ const fs = require('fs');
|
|||||||
const path = require('path');
|
const path = require('path');
|
||||||
|
|
||||||
const versionFile = path.join(__dirname, 'dental-server', 'version.txt');
|
const versionFile = path.join(__dirname, 'dental-server', 'version.txt');
|
||||||
const packageFile = path.join(__dirname, 'dental-server', 'package.json');
|
|
||||||
const indexFile = path.join(__dirname, 'dental-server', 'public', 'index.html');
|
const indexFile = path.join(__dirname, 'dental-server', 'public', 'index.html');
|
||||||
|
|
||||||
const current = fs.readFileSync(versionFile, 'utf8').trim();
|
const current = fs.readFileSync(versionFile, 'utf8').trim();
|
||||||
@@ -14,15 +13,11 @@ const parts = current.split('.').map(Number);
|
|||||||
parts[2]++; // bump PATCH
|
parts[2]++; // bump PATCH
|
||||||
const next = parts.join('.');
|
const next = parts.join('.');
|
||||||
|
|
||||||
// version.txt
|
// version.txt — fonte de verdade do número de versão
|
||||||
fs.writeFileSync(versionFile, next + '\n');
|
fs.writeFileSync(versionFile, next + '\n');
|
||||||
|
|
||||||
// package.json
|
// index.html — substitui v{X.Y.Z} dentro do <span> da sidebar
|
||||||
const pkg = JSON.parse(fs.readFileSync(packageFile, 'utf8'));
|
// (package.json NÃO é alterado para preservar o cache de npm install no Docker)
|
||||||
pkg.version = next;
|
|
||||||
fs.writeFileSync(packageFile, JSON.stringify(pkg, null, 2) + '\n');
|
|
||||||
|
|
||||||
// index.html — substitui qualquer v{X.Y.Z} dentro do <span> da sidebar
|
|
||||||
let html = fs.readFileSync(indexFile, 'utf8');
|
let html = fs.readFileSync(indexFile, 'utf8');
|
||||||
html = html.replace(
|
html = html.replace(
|
||||||
/(RF Dental.*?<span[^>]*>)\s*v[\d.]+\s*(<\/span>)/s,
|
/(RF Dental.*?<span[^>]*>)\s*v[\d.]+\s*(<\/span>)/s,
|
||||||
|
|||||||
Reference in New Issue
Block a user