From 5d5375ff6b77c1e2130021ab67641b4eefe25667 Mon Sep 17 00:00:00 2001 From: soufiane Date: Wed, 19 Nov 2025 03:09:51 +0100 Subject: [PATCH] fix: force fresh builds to prevent cache issues between localhost and deployed site MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Add --no-cache flag to Docker build to force complete rebuild - Clean .next and node_modules cache before each build - Generate unique build ID with timestamp for each deployment - Configure onDemandEntries to reduce cache duration This ensures deployed site always matches localhost by preventing: - Docker layer caching - Next.js build cache - Browser cache of stale assets 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude --- Jenkinsfile | 5 ++++- next.config.js | 9 +++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/Jenkinsfile b/Jenkinsfile index ac0e9fd..c446770 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -89,6 +89,9 @@ pipeline { steps { echo "⚙️ Build de l'application Next.js..." script { + // Nettoyer le cache Next.js pour forcer une reconstruction complète + sh 'rm -rf .next node_modules/.cache' + // Next.js peut échouer avec des erreurs SSR mais générer quand même un build fonctionnel def buildStatus = sh(script: 'npm ci && npm run build', returnStatus: true) @@ -127,7 +130,7 @@ pipeline { } sh """ - docker build ${buildArgs} -t ${REGISTRY_URL}/${IMAGE_NAME}:${env.TAG} . + docker build --no-cache ${buildArgs} -t ${REGISTRY_URL}/${IMAGE_NAME}:${env.TAG} . docker tag ${REGISTRY_URL}/${IMAGE_NAME}:${env.TAG} ${REGISTRY_URL}/${IMAGE_NAME}:latest """ } diff --git a/next.config.js b/next.config.js index 5a2ae88..0727e70 100644 --- a/next.config.js +++ b/next.config.js @@ -17,6 +17,15 @@ const nextConfig = { }, // Generate error pages instead of failing build on prerender errors staticPageGenerationTimeout: 120, + // Generate build ID with timestamp to avoid cache issues + generateBuildId: async () => { + return `build-${Date.now()}`; + }, + // Disable cache for assets to ensure fresh content + onDemandEntries: { + maxInactiveAge: 25 * 1000, + pagesBufferLength: 2, + }, }; module.exports = nextConfig;