Some checks failed
CI/CD Pipeline (Dev/Staging) / staging (push) Failing after 8m11s
151 lines
4.0 KiB
Markdown
151 lines
4.0 KiB
Markdown
# 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
|
|
|
|
**✅ GELÖST**: Die Debug-Ausgabe zeigt, dass Next.js 15 die Struktur `.next/standalone/` direkt verwendet:
|
|
- `.next/standalone/server.js` ✅
|
|
- `.next/standalone/.next/` ✅
|
|
- `.next/standalone/node_modules/` ✅
|
|
- `.next/standalone/package.json` ✅
|
|
|
|
**NICHT**: `.next/standalone/app/server.js` ❌
|
|
|
|
Das Dockerfile wurde korrigiert, um `.next/standalone/` direkt zu kopieren.
|
|
|
|
## 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.
|