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.
|
||||
16
Dockerfile
16
Dockerfile
@@ -35,6 +35,20 @@ ENV NEXT_TELEMETRY_DISABLED=1
|
||||
ENV NODE_ENV=production
|
||||
RUN npm run build
|
||||
|
||||
# Verify standalone output was created and show structure for debugging
|
||||
RUN if [ ! -d .next/standalone ]; then \
|
||||
echo "ERROR: .next/standalone directory not found!"; \
|
||||
echo "Contents of .next directory:"; \
|
||||
ls -la .next/ || true; \
|
||||
echo "Checking if standalone exists in different location:"; \
|
||||
find .next -name "standalone" -type d || true; \
|
||||
exit 1; \
|
||||
fi && \
|
||||
echo "✅ Standalone output found" && \
|
||||
ls -la .next/standalone/ && \
|
||||
echo "Standalone structure:" && \
|
||||
find .next/standalone -type f -name "server.js" || echo "server.js not found in standalone"
|
||||
|
||||
# Production image, copy all the files and run next
|
||||
FROM base AS runner
|
||||
WORKDIR /app
|
||||
@@ -55,6 +69,8 @@ RUN chown nextjs:nodejs .next
|
||||
|
||||
# Automatically leverage output traces to reduce image size
|
||||
# https://nextjs.org/docs/advanced-features/output-file-tracing
|
||||
# Copy standalone output (contains server.js and all dependencies)
|
||||
# The standalone output structure is: .next/standalone/app/
|
||||
COPY --from=builder --chown=nextjs:nodejs /app/.next/standalone/app ./
|
||||
COPY --from=builder --chown=nextjs:nodejs /app/.next/static ./.next/static
|
||||
|
||||
|
||||
@@ -6,10 +6,23 @@ export const revalidate = 30;
|
||||
|
||||
export async function GET() {
|
||||
try {
|
||||
// Check if n8n webhook URL is configured
|
||||
const n8nWebhookUrl = process.env.N8N_WEBHOOK_URL;
|
||||
|
||||
if (!n8nWebhookUrl) {
|
||||
// Return fallback if n8n is not configured
|
||||
return NextResponse.json({
|
||||
status: { text: "offline", color: "gray" },
|
||||
music: null,
|
||||
gaming: null,
|
||||
coding: null,
|
||||
});
|
||||
}
|
||||
|
||||
// Rufe den n8n Webhook auf
|
||||
// Add timestamp to query to bypass Cloudflare cache
|
||||
const res = await fetch(
|
||||
`${process.env.N8N_WEBHOOK_URL}/webhook/denshooter-71242/status?t=${Date.now()}`,
|
||||
`${n8nWebhookUrl}/webhook/denshooter-71242/status?t=${Date.now()}`,
|
||||
{
|
||||
method: "GET",
|
||||
headers: {
|
||||
|
||||
Reference in New Issue
Block a user