feat: Enhance Dockerfile with verification for standalone output and update n8n status route to handle missing webhook URL
Some checks failed
CI/CD Pipeline (Dev/Staging) / staging (push) Failing after 7m56s
Some checks failed
CI/CD Pipeline (Dev/Staging) / staging (push) Failing after 7m56s
This commit is contained in:
149
DOCKER_BUILD_FIX.md
Normal file
149
DOCKER_BUILD_FIX.md
Normal file
@@ -0,0 +1,149 @@
|
||||
# Docker Build Fix - Standalone Output Issue
|
||||
|
||||
## Problem
|
||||
|
||||
Der Docker Build schlägt fehl mit:
|
||||
```
|
||||
ERROR: failed to calculate checksum of ref ... "/app/.next/standalone/app": not found
|
||||
```
|
||||
|
||||
## Ursache
|
||||
|
||||
Next.js erstellt das `standalone` Output nur, wenn:
|
||||
1. `output: "standalone"` in `next.config.ts` gesetzt ist ✅ (bereits konfiguriert)
|
||||
2. Der Build erfolgreich abgeschlossen wird
|
||||
3. Alle Abhängigkeiten korrekt aufgelöst werden
|
||||
|
||||
## Lösung
|
||||
|
||||
### 1. n8n Status Route Fix
|
||||
|
||||
Die Route wurde angepasst, um während des Builds nicht zu fehlschlagen, wenn `N8N_WEBHOOK_URL` nicht gesetzt ist:
|
||||
|
||||
```typescript
|
||||
// Prüft jetzt, ob N8N_WEBHOOK_URL gesetzt ist
|
||||
if (!n8nWebhookUrl) {
|
||||
return NextResponse.json({ /* fallback */ });
|
||||
}
|
||||
```
|
||||
|
||||
### 2. Dockerfile Verbesserungen
|
||||
|
||||
- **Verification Step**: Prüft, ob das standalone Verzeichnis existiert
|
||||
- **Debug Output**: Zeigt die Verzeichnisstruktur, falls Probleme auftreten
|
||||
- **Robustere Fehlerbehandlung**: Bessere Fehlermeldungen
|
||||
|
||||
### 3. Mögliche Ursachen und Lösungen
|
||||
|
||||
#### Problem: Standalone Output wird nicht erstellt
|
||||
|
||||
**Lösung 1: Prüfe next.config.ts**
|
||||
```typescript
|
||||
// Stelle sicher, dass dies gesetzt ist:
|
||||
output: "standalone",
|
||||
outputFileTracingRoot: path.join(process.cwd()),
|
||||
```
|
||||
|
||||
**Lösung 2: Prüfe Build-Logs**
|
||||
```bash
|
||||
# Schaue in die Build-Logs, ob es Fehler gibt
|
||||
docker build . 2>&1 | grep -i "standalone\|error"
|
||||
```
|
||||
|
||||
**Lösung 3: Lokaler Test**
|
||||
```bash
|
||||
# Teste lokal, ob standalone erstellt wird
|
||||
npm run build
|
||||
ls -la .next/standalone/
|
||||
```
|
||||
|
||||
#### Problem: Falsche Verzeichnisstruktur
|
||||
|
||||
Next.js 15 könnte eine andere Struktur haben. Prüfe:
|
||||
```bash
|
||||
# Nach dem Build
|
||||
find .next/standalone -name "server.js"
|
||||
```
|
||||
|
||||
Falls `server.js` in `.next/standalone/app/server.js` ist, ist das Dockerfile korrekt.
|
||||
Falls es in `.next/standalone/server.js` ist, muss das Dockerfile angepasst werden.
|
||||
|
||||
## Debugging
|
||||
|
||||
### 1. Lokaler Build Test
|
||||
|
||||
```bash
|
||||
# Baue lokal
|
||||
npm run build
|
||||
|
||||
# Prüfe ob standalone existiert
|
||||
test -d .next/standalone && echo "✅ Standalone exists" || echo "❌ Standalone missing"
|
||||
|
||||
# Zeige Struktur
|
||||
ls -la .next/standalone/
|
||||
find .next/standalone -name "server.js"
|
||||
```
|
||||
|
||||
### 2. Docker Build mit Debug
|
||||
|
||||
```bash
|
||||
# Baue mit mehr Output
|
||||
docker build --progress=plain -t portfolio-app:test .
|
||||
|
||||
# Oder baue nur bis zum Builder Stage
|
||||
docker build --target builder -t portfolio-builder:test .
|
||||
docker run --rm portfolio-builder:test ls -la .next/standalone/
|
||||
```
|
||||
|
||||
### 3. Prüfe Build-Logs
|
||||
|
||||
Der aktualisierte Dockerfile gibt jetzt Debug-Informationen aus:
|
||||
- Zeigt `.next/` Verzeichnisstruktur
|
||||
- Sucht nach `standalone` Verzeichnis
|
||||
- Zeigt `server.js` Location
|
||||
|
||||
## Alternative: Fallback ohne Standalone
|
||||
|
||||
Falls das standalone Output weiterhin Probleme macht, kann man auf ein vollständiges Image zurückgreifen:
|
||||
|
||||
```dockerfile
|
||||
# Statt standalone zu kopieren, kopiere alles
|
||||
COPY --from=builder --chown=nextjs:nodejs /app/node_modules ./node_modules
|
||||
COPY --from=builder --chown=nextjs:nodejs /app/.next ./.next
|
||||
COPY --from=builder --chown=nextjs:nodejs /app/public ./public
|
||||
COPY --from=builder --chown=nextjs:nodejs /app/package.json ./package.json
|
||||
COPY --from=builder --chown=nextjs:nodejs /app/prisma ./prisma
|
||||
|
||||
CMD ["npm", "start"]
|
||||
```
|
||||
|
||||
**Nachteil**: Größeres Image, aber funktioniert immer.
|
||||
|
||||
## Nächste Schritte
|
||||
|
||||
1. ✅ n8n Status Route Fix (bereits gemacht)
|
||||
2. ✅ Dockerfile Debug-Verbesserungen (bereits gemacht)
|
||||
3. 🔄 Push zum dev Branch und Build testen
|
||||
4. 📊 Build-Logs analysieren
|
||||
5. 🔧 Falls nötig: Dockerfile weiter anpassen
|
||||
|
||||
## Workflow Test
|
||||
|
||||
```bash
|
||||
# 1. Committe Änderungen
|
||||
git add .
|
||||
git commit -m "Fix: Docker build standalone output issue"
|
||||
|
||||
# 2. Push zum dev Branch
|
||||
git push origin dev
|
||||
|
||||
# 3. Überwache Gitea Actions
|
||||
# Gehe zu Repository → Actions → CI/CD Pipeline (Dev/Staging)
|
||||
|
||||
# 4. Prüfe Build-Logs
|
||||
# Schaue nach den Debug-Ausgaben im Build-Step
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
**Hinweis**: Falls das Problem weiterhin besteht, schaue in die Build-Logs nach den Debug-Ausgaben, die der aktualisierte Dockerfile jetzt ausgibt. Diese zeigen genau, wo das Problem liegt.
|
||||
Reference in New Issue
Block a user