Files
TechradarDev/Dockerfile.business
syoul 56f227e939 fix: simplification modification Navigation.tsx avec sed + Python inline
- Utilisation de sed en premier (plus simple)
- Fallback avec Python en une seule ligne si sed échoue
- Pas de heredoc complexe qui cause des problèmes d'échappement
2025-12-07 08:15:08 +01:00

166 lines
9.0 KiB
Docker
Raw Blame History

This file contains invisible Unicode characters
This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# Utiliser une image Node.js légère
FROM node:20-alpine
# Build arguments pour invalider le cache si nécessaire
ARG BUILD_DATE=unknown
ARG BUILD_VERSION=unknown
ARG CACHE_BUST=1
LABEL build.date="${BUILD_DATE}" \
build.version="${BUILD_VERSION}" \
cache.bust="${CACHE_BUST}"
# Invalider le cache en utilisant CACHE_BUST dans une instruction RUN
# Cela force Docker à reconstruire à partir de cette ligne si CACHE_BUST change
# Utiliser CACHE_BUST dans une variable d'environnement pour forcer l'invalidation
RUN echo "Cache bust: ${CACHE_BUST}" && \
echo "Build date: ${BUILD_DATE}" && \
date && \
echo "${CACHE_BUST}" > /tmp/cache_bust.txt
WORKDIR /app
# Variables d'environnement à définir AVANT npm install
ENV HUSKY=0
ENV HUSKY_SKIP_INSTALL=1
ENV NODE_PATH=/app/node_modules
ENV NODE_ENV=production
# Installation des dépendances système
RUN apk add --no-cache git python3
# Copie des fichiers de dépendances
COPY package.json package-lock.json* ./
# Installation des dépendances Node
RUN npm install --legacy-peer-deps --ignore-scripts
# Patch du package aoe_technology_radar pour inclure gray-matter dans les dépendances runtime
RUN node -e "const fs=require('fs');const pkgPath='./node_modules/aoe_technology_radar/package.json';const pkg=JSON.parse(fs.readFileSync(pkgPath,'utf8'));pkg.dependencies=pkg.dependencies||{};pkg.dependencies['gray-matter']='^4.0.3';pkg.dependencies['postcss']='^8.4.47';pkg.scripts=pkg.scripts||{};pkg.scripts.prepare='';fs.writeFileSync(pkgPath,JSON.stringify(pkg,null,2));"
# Copie du reste du projet
COPY . .
RUN chmod +x scripts/start-business.sh
# Préparer .techradar une fois pour toutes (évite les réinstallations au runtime)
# Le script techradar.js crée automatiquement .techradar lors de l'exécution
# Création manuelle de .techradar en copiant depuis node_modules
RUN mkdir -p .techradar && \
cp -r node_modules/aoe_technology_radar/* .techradar/
# Créer le fichier hash pour éviter la recréation (calculé séparément pour éviter les problèmes d'échappement)
RUN node -e "const crypto=require('crypto');const fs=require('fs');const hash=crypto.createHash('sha256').update(fs.readFileSync('package.json')).digest('hex');fs.writeFileSync('.techradar/hash',hash);"
RUN node -e "const fs=require('fs');const p='.techradar/package.json';if(!fs.existsSync(p)){console.error('.techradar/package.json not found');process.exit(1);}const pkg=JSON.parse(fs.readFileSync(p,'utf8'));pkg.scripts=pkg.scripts||{};pkg.scripts.prepare='';fs.writeFileSync(p,JSON.stringify(pkg,null,2));"
# Installer les dépendances dans .techradar (y compris devDependencies pour tsx nécessaire à build:data)
RUN cd .techradar && npm install --legacy-peer-deps --include=dev
RUN cd .techradar && npm run build:icons
# --- CONFIGURATION BUSINESS ---
# Application de la logique Business (remplacement de la config et des données)
# Préserver la structure de dossiers par date pour que le framework puisse parser les dates
RUN cp radar-business/config-business.json config.json && \
rm -rf radar/* && \
mkdir -p radar/2025-01-15 && \
cp -r radar-business/2025-01-15/* radar/2025-01-15/
# Copier les fichiers nécessaires dans .techradar avant le build (comme le fait techradar.js)
RUN mkdir -p .techradar/data && \
cp -r radar .techradar/data/radar && \
cp -r public .techradar/public && \
cp config.json .techradar/data/config.json && \
cp about.md .techradar/data/about.md 2>/dev/null || echo "about.md not found, skipping" && \
cp custom.css .techradar/src/styles/custom.css 2>/dev/null || echo "custom.css not found, skipping" && \
echo "Fichiers public copiés" && \
echo "📁 Vérification des fichiers team dans .techradar/public/:" && \
ls -la .techradar/public/ | grep -E "(team\.html|team-visualization)" && echo "✅ Fichiers team trouvés" || (echo "⚠️ Fichiers team non trouvés dans .techradar/public/" && echo "📁 Contenu de public/ source:" && ls -la public/ | head -10) && \
echo "📁 Vérification que team.html existe dans public/ source:" && \
test -f public/team.html && echo "✅ public/team.html existe" || echo "❌ public/team.html n'existe pas"
# Créer la page Next.js /team
RUN mkdir -p .techradar/src/pages && \
cat > .techradar/src/pages/team.tsx << 'EOF'
import Head from "next/head";
import { CustomPage } from "@/pages/_app";
const TeamPage: CustomPage = () => {
return (
<>
<Head>
<title>Équipe & Technologies - Laplank</title>
</Head>
<div style={{ width: '100%', height: '100vh', border: 'none', margin: 0, padding: 0 }}>
<iframe
src="/team.html"
style={{
width: '100%',
height: '100%',
border: 'none',
margin: 0,
padding: 0
}}
title="Équipe & Technologies"
/>
</div>
</>
);
};
export default TeamPage;
EOF
RUN echo "✅ Page team.tsx créée"
# Modifier Navigation.tsx pour ajouter le lien Équipe
RUN if ! grep -q 'href="/team"' .techradar/src/components/Navigation/Navigation.tsx; then \
echo " Ajout du lien Équipe dans Navigation.tsx..." && \
sed -i '/href="\/overview"/,/<\/Link>/ { /<\/Link>/a\ <li className={styles.item}>\ <Link href="/team">\ <span className={styles.label}>👥 Équipe</span>\ </Link>\ </li> }' .techradar/src/components/Navigation/Navigation.tsx && \
grep -q 'href="/team"' .techradar/src/components/Navigation/Navigation.tsx && echo "✅ Lien Équipe ajouté" || (echo "❌ Lien Équipe non trouvé après modification avec sed, tentative avec Python..." && \
python3 -c "import re; content = open('.techradar/src/components/Navigation/Navigation.tsx').read(); lines = content.split('\n'); insert_idx = -1; [setattr(locals(), 'insert_idx', j+2) or None for i, line in enumerate(lines) if 'href=\"/overview\"' in line for j in range(i, min(i+10, len(lines))) if '</Link>' in lines[j] and j+1 < len(lines) and '</li>' in lines[j+1]]; new_lines = lines[:insert_idx] + [' <li className={styles.item}>', ' <Link href=\"/team\">', ' <span className={styles.label}>👥 Équipe</span>', ' </Link>', ' </li>'] + lines[insert_idx:] if insert_idx > 0 else lines; open('.techradar/src/components/Navigation/Navigation.tsx', 'w').write('\n'.join(new_lines)) if insert_idx > 0 else None; print('✅ Navigation.tsx modifié' if insert_idx > 0 else '❌ Échec')" && \
grep -q 'href="/team"' .techradar/src/components/Navigation/Navigation.tsx && echo "✅ Lien Équipe ajouté avec Python" || (echo "❌ Lien Équipe toujours non trouvé" && cat .techradar/src/components/Navigation/Navigation.tsx && exit 1)); \
else \
echo " Lien Équipe déjà présent dans Navigation.tsx"; \
fi
# Builder l'application en mode production pour éviter Fast Refresh
# Utiliser WORKDIR pour changer de répertoire de manière fiable
WORKDIR /app/.techradar
RUN npm run build:data
RUN npm run build
# S'assurer que team.html et team-visualization-data.json sont copiés dans out/
# Next.js en mode export copie automatiquement les fichiers de public/, mais vérifions quand même
RUN if [ -d "out" ]; then \
echo "📁 Contenu de out/ avant copie:" && \
ls -la out/ | head -10 && \
echo "" && \
echo "🔍 Recherche de team.html..." && \
if [ -f "public/team.html" ]; then \
cp -v public/team.html out/team.html && echo "✅ team.html copié depuis public/ vers out/"; \
elif [ -f "/app/public/team.html" ]; then \
cp -v /app/public/team.html out/team.html && echo "✅ team.html copié depuis /app/public/ vers out/"; \
else \
echo "⚠️ team.html introuvable dans public/ ou /app/public/"; \
echo "📁 Contenu de public/:" && \
ls -la public/ 2>/dev/null | head -10 || echo "public/ non accessible"; \
echo "📁 Contenu de /app/public/:" && \
ls -la /app/public/ 2>/dev/null | head -10 || echo "/app/public/ non accessible"; \
fi && \
if [ -f "public/team-visualization-data.json" ]; then \
cp -v public/team-visualization-data.json out/team-visualization-data.json && echo "✅ team-visualization-data.json copié dans out/"; \
else \
echo "⚠️ public/team-visualization-data.json introuvable"; \
fi && \
echo "" && \
echo "📁 Vérification finale dans out/:" && \
ls -la out/ | grep -E "(team\.html|team-visualization)" && echo "✅ Fichiers team présents dans out/" || echo "⚠️ Fichiers team non trouvés dans out/"; \
else \
echo "❌ Dossier out/ introuvable après build"; \
ls -la . | head -20; \
fi && \
echo "" && \
echo "📋 Vérification finale de Navigation.tsx après build:" && \
grep -q 'href="/team"' src/components/Navigation/Navigation.tsx && echo "✅ Lien Équipe toujours présent dans Navigation.tsx après build" || echo "❌ Lien Équipe absent de Navigation.tsx après build"
WORKDIR /app
# Exposition du port interne
EXPOSE 3000
# Démarrage du serveur via script (exporte les variables avant npm run serve)
CMD ["./scripts/start-business.sh"]