4 Commits

Author SHA1 Message Date
denshooter
de0f3f1e66 fix: Update Dockerfile to correctly copy Next.js 15 standalone output structure
Some checks failed
CI/CD Pipeline (Dev/Staging) / staging (push) Failing after 8m11s
2026-01-09 03:03:33 +01:00
denshooter
393e8c01cd 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
2026-01-09 02:36:21 +01:00
denshooter
0e578dd833 feat: Add Dev Branch Testing Guide and CI/CD Pipeline for Staging Deployment
Some checks failed
CI/CD Pipeline (Dev/Staging) / staging (push) Failing after 9m0s
2026-01-09 02:02:08 +01:00
denshooter
5cbe95dc24 Merge branch 'dev_n8n' into dev 2026-01-09 00:24:21 +01:00
6 changed files with 630 additions and 2 deletions

View File

@@ -0,0 +1,209 @@
name: CI/CD Pipeline (Dev/Staging)
on:
push:
branches: [dev, main]
env:
NODE_VERSION: '20'
DOCKER_IMAGE: portfolio-app
CONTAINER_NAME: portfolio-app-staging
jobs:
staging:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v3
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: ${{ env.NODE_VERSION }}
cache: 'npm'
- name: Install dependencies
run: npm ci
- name: Run linting
run: npm run lint
- name: Run tests
run: npm run test:production
- name: Build application
run: npm run build
- name: Run security scan
run: |
echo "🔍 Running npm audit..."
npm audit --audit-level=high || echo "⚠️ Some vulnerabilities found, but continuing..."
- name: Verify Gitea Variables and Secrets
run: |
echo "🔍 Verifying Gitea Variables and Secrets..."
# Check Variables
if [ -z "${{ vars.NEXT_PUBLIC_BASE_URL }}" ]; then
echo "❌ NEXT_PUBLIC_BASE_URL variable is missing!"
echo "Please set this variable in Gitea repository settings"
exit 1
fi
if [ -z "${{ vars.MY_EMAIL }}" ]; then
echo "❌ MY_EMAIL variable is missing!"
echo "Please set this variable in Gitea repository settings"
exit 1
fi
if [ -z "${{ vars.MY_INFO_EMAIL }}" ]; then
echo "❌ MY_INFO_EMAIL variable is missing!"
echo "Please set this variable in Gitea repository settings"
exit 1
fi
# Check Secrets
if [ -z "${{ secrets.MY_PASSWORD }}" ]; then
echo "❌ MY_PASSWORD secret is missing!"
echo "Please set this secret in Gitea repository settings"
exit 1
fi
if [ -z "${{ secrets.MY_INFO_PASSWORD }}" ]; then
echo "❌ MY_INFO_PASSWORD secret is missing!"
echo "Please set this secret in Gitea repository settings"
exit 1
fi
if [ -z "${{ secrets.ADMIN_BASIC_AUTH }}" ]; then
echo "❌ ADMIN_BASIC_AUTH secret is missing!"
echo "Please set this secret in Gitea repository settings"
exit 1
fi
echo "✅ All required Gitea variables and secrets are present"
echo "📝 Variables found:"
echo " - NEXT_PUBLIC_BASE_URL: ${{ vars.NEXT_PUBLIC_BASE_URL }}"
echo " - MY_EMAIL: ${{ vars.MY_EMAIL }}"
echo " - MY_INFO_EMAIL: ${{ vars.MY_INFO_EMAIL }}"
echo " - NODE_ENV: staging"
echo " - LOG_LEVEL: ${{ vars.LOG_LEVEL }}"
- name: Build Docker image
run: |
echo "🏗️ Building Docker image..."
docker build -t ${{ env.DOCKER_IMAGE }}:staging .
docker tag ${{ env.DOCKER_IMAGE }}:staging ${{ env.DOCKER_IMAGE }}:staging-$(date +%Y%m%d-%H%M%S)
echo "✅ Docker image built successfully"
- name: Deploy Staging using Gitea Variables and Secrets
run: |
echo "🚀 Deploying Staging using Gitea Variables and Secrets..."
echo "📝 Using Gitea Variables and Secrets:"
echo " - NODE_ENV: staging"
echo " - LOG_LEVEL: ${LOG_LEVEL}"
echo " - NEXT_PUBLIC_BASE_URL: ${NEXT_PUBLIC_BASE_URL}"
echo " - MY_EMAIL: ${MY_EMAIL}"
echo " - MY_INFO_EMAIL: ${MY_INFO_EMAIL}"
echo " - MY_PASSWORD: [SET FROM GITEA SECRET]"
echo " - MY_INFO_PASSWORD: [SET FROM GITEA SECRET]"
echo " - ADMIN_BASIC_AUTH: [SET FROM GITEA SECRET]"
echo " - N8N_WEBHOOK_URL: ${N8N_WEBHOOK_URL}"
# Stop old staging containers
echo "🛑 Stopping old staging containers..."
docker compose -f docker-compose.staging.yml down || true
# Clean up orphaned containers
echo "🧹 Cleaning up orphaned containers..."
docker compose -f docker-compose.staging.yml down --remove-orphans || true
# Start new staging containers
echo "🚀 Starting new staging containers..."
docker compose -f docker-compose.staging.yml up -d
# Wait a moment for containers to start
echo "⏳ Waiting for containers to start..."
sleep 10
# Check container logs for debugging
echo "📋 Container logs (first 20 lines):"
docker compose -f docker-compose.staging.yml logs --tail=20
echo "✅ Staging deployment completed!"
env:
NODE_ENV: staging
LOG_LEVEL: ${{ vars.LOG_LEVEL }}
NEXT_PUBLIC_BASE_URL: ${{ vars.NEXT_PUBLIC_BASE_URL }}
NEXT_PUBLIC_UMAMI_URL: ${{ vars.NEXT_PUBLIC_UMAMI_URL }}
NEXT_PUBLIC_UMAMI_WEBSITE_ID: ${{ vars.NEXT_PUBLIC_UMAMI_WEBSITE_ID }}
MY_EMAIL: ${{ vars.MY_EMAIL }}
MY_INFO_EMAIL: ${{ vars.MY_INFO_EMAIL }}
MY_PASSWORD: ${{ secrets.MY_PASSWORD }}
MY_INFO_PASSWORD: ${{ secrets.MY_INFO_PASSWORD }}
ADMIN_BASIC_AUTH: ${{ secrets.ADMIN_BASIC_AUTH }}
N8N_WEBHOOK_URL: ${{ vars.N8N_WEBHOOK_URL }}
N8N_API_KEY: ${{ secrets.N8N_API_KEY }}
- name: Wait for containers to be ready
run: |
echo "⏳ Waiting for containers to be ready..."
sleep 45
# Check if all containers are running
echo "📊 Checking container status..."
docker compose -f docker-compose.staging.yml ps
# Wait for application container to be healthy
echo "🏥 Waiting for application container to be healthy..."
for i in {1..60}; do
if docker exec portfolio-app-staging curl -f http://localhost:3000/api/health > /dev/null 2>&1; then
echo "✅ Application container is healthy!"
break
fi
echo "⏳ Waiting for application container... ($i/60)"
sleep 5
done
# Additional wait for main page to be accessible
echo "🌐 Waiting for main page to be accessible..."
for i in {1..30}; do
if curl -f http://localhost:3001/ > /dev/null 2>&1; then
echo "✅ Main page is accessible!"
break
fi
echo "⏳ Waiting for main page... ($i/30)"
sleep 3
done
- name: Health check
run: |
echo "🔍 Running comprehensive health checks..."
# Check container status
echo "📊 Container status:"
docker compose -f docker-compose.staging.yml ps
# Check application container
echo "🏥 Checking application container..."
if docker exec portfolio-app-staging curl -f http://localhost:3000/api/health; then
echo "✅ Application health check passed!"
else
echo "❌ Application health check failed!"
docker logs portfolio-app-staging --tail=50
exit 1
fi
# Check main page
if curl -f http://localhost:3001/ > /dev/null; then
echo "✅ Main page is accessible!"
else
echo "❌ Main page is not accessible!"
exit 1
fi
echo "✅ All health checks passed! Staging deployment successful!"
- name: Cleanup old images
run: |
echo "🧹 Cleaning up old images..."
docker image prune -f
docker system prune -f
echo "✅ Cleanup completed"

236
DEV_TESTING.md Normal file
View File

@@ -0,0 +1,236 @@
# 🧪 Dev Branch Testing Guide
## Übersicht
Dieses Dokument erklärt, wie du dein Portfolio-Projekt auf dem `dev` Branch testen kannst, bevor du es in Production deployst.
## Voraussetzungen
1. ✅ n8n läuft bereits auf `n8n.dk0.dev`
2. ✅ Gitea Repository ist eingerichtet
3. ✅ Docker und Docker Compose sind installiert
## Setup für lokales Testen mit n8n
### 1. Environment Variables konfigurieren
Erstelle eine `.env.local` Datei (oder aktualisiere deine bestehende `.env`):
```bash
# n8n Integration
N8N_WEBHOOK_URL=https://n8n.dk0.dev
N8N_API_KEY=dein-n8n-api-key
N8N_SECRET_TOKEN=dein-n8n-secret-token
# Application
NODE_ENV=development
NEXT_PUBLIC_BASE_URL=http://localhost:3000
# Database (wird automatisch von docker-compose.dev.minimal.yml gesetzt)
# DATABASE_URL=postgresql://portfolio_user:portfolio_dev_pass@localhost:5432/portfolio_dev?schema=public
# Redis (wird automatisch von docker-compose.dev.minimal.yml gesetzt)
# REDIS_URL=redis://localhost:6379
# Email Configuration
MY_EMAIL=contact@dk0.dev
MY_INFO_EMAIL=info@dk0.dev
MY_PASSWORD=dein-email-passwort
MY_INFO_PASSWORD=dein-info-email-passwort
# Analytics
NEXT_PUBLIC_UMAMI_URL=https://analytics.dk0.dev
NEXT_PUBLIC_UMAMI_WEBSITE_ID=b3665829-927a-4ada-b9bb-fcf24171061e
# Security
ADMIN_BASIC_AUTH=admin:dein-sicheres-passwort
LOG_LEVEL=debug
```
### 2. Lokal testen
```bash
# 1. Starte Datenbank und Redis
npm run dev:minimal
# 2. In einem neuen Terminal: Starte die Next.js App
npm run dev
# 3. Öffne http://localhost:3000
```
### 3. n8n Webhook testen
Teste die Verbindung zu deinem n8n Server:
```bash
# Teste den Status Endpoint
curl https://n8n.dk0.dev/webhook/denshooter-71242/status
# Teste den Chat Endpoint (wenn konfiguriert)
curl -X POST https://n8n.dk0.dev/webhook/chat \
-H "Content-Type: application/json" \
-H "Authorization: Bearer DEIN_N8N_SECRET_TOKEN" \
-d '{"message": "Hallo", "history": []}'
```
## Staging Deployment auf dem Server
### 1. Gitea Variables und Secrets konfigurieren
Gehe zu deinem Gitea Repository → Settings → Secrets/Variables und füge hinzu:
**Variables:**
- `NEXT_PUBLIC_BASE_URL` = `https://staging.dk0.dev` (oder deine Staging URL)
- `MY_EMAIL` = `contact@dk0.dev`
- `MY_INFO_EMAIL` = `info@dk0.dev`
- `NEXT_PUBLIC_UMAMI_URL` = `https://analytics.dk0.dev`
- `NEXT_PUBLIC_UMAMI_WEBSITE_ID` = `b3665829-927a-4ada-b9bb-fcf24171061e`
- `N8N_WEBHOOK_URL` = `https://n8n.dk0.dev`
- `LOG_LEVEL` = `debug`
**Secrets:**
- `MY_PASSWORD` = Dein Email Passwort
- `MY_INFO_PASSWORD` = Dein Info Email Passwort
- `ADMIN_BASIC_AUTH` = `admin:dein-sicheres-passwort`
- `N8N_API_KEY` = Dein n8n API Key (optional)
- `N8N_SECRET_TOKEN` = Dein n8n Secret Token (optional)
### 2. Push zum dev Branch
```bash
# Stelle sicher, dass du auf dem dev Branch bist
git checkout dev
# Committe deine Änderungen
git add .
git commit -m "Test: Dev deployment"
# Push zum dev Branch (triggert automatisch Staging Deployment)
git push origin dev
```
### 3. Deployment überwachen
Nach dem Push:
1. Gehe zu deinem Gitea Repository → Actions
2. Überwache den Workflow `CI/CD Pipeline (Dev/Staging)`
3. Der Workflow wird:
- Tests ausführen
- Docker Image bauen
- Staging Container auf Port 3001 deployen
### 4. Staging testen
```bash
# Auf deinem Server: Prüfe Container Status
docker ps | grep staging
# Prüfe Health Endpoint
curl http://localhost:3001/api/health
# Prüfe n8n Status Endpoint
curl http://localhost:3001/api/n8n/status
# Logs ansehen
docker logs portfolio-app-staging -f
```
### 5. Staging URL konfigurieren
Falls du eine Subdomain für Staging hast (z.B. `staging.dk0.dev`):
- Konfiguriere deinen Reverse Proxy (Nginx/Traefik) um auf Port 3001 zu zeigen
- Oder verwende direkt `http://dein-server-ip:3001`
## Troubleshooting
### Dev Container wird nicht erstellt
1. **Prüfe Gitea Workflow:**
- Gehe zu Repository → Actions
- Prüfe ob der Workflow `ci-cd-dev-staging.yml` existiert
- Prüfe ob der Workflow auf `dev` Branch Push reagiert
2. **Prüfe Gitea Variables:**
- Stelle sicher, dass alle erforderlichen Variables und Secrets gesetzt sind
- Prüfe die Workflow Logs für fehlende Variablen
3. **Prüfe Docker:**
```bash
# Auf deinem Server
docker ps -a
docker images | grep portfolio-app
```
### n8n Verbindungsfehler
1. **Prüfe n8n URL:**
```bash
# Teste ob n8n erreichbar ist
curl https://n8n.dk0.dev/webhook/denshooter-71242/status
```
2. **Prüfe Environment Variables:**
```bash
# Im Container
docker exec portfolio-app-staging env | grep N8N
```
3. **Prüfe n8n Webhook Konfiguration:**
- Stelle sicher, dass der Webhook in n8n aktiviert ist
- Prüfe ob der Webhook-Pfad korrekt ist (`/webhook/denshooter-71242/status`)
### Datenbank Fehler
```bash
# Prüfe ob die Datenbank läuft
docker ps | grep postgres-staging
# Prüfe Datenbank Logs
docker logs portfolio-postgres-staging
# Prüfe Verbindung
docker exec portfolio-postgres-staging pg_isready -U portfolio_user -d portfolio_staging_db
```
## Workflow Übersicht
```
┌─────────────────┐
│ Push to dev │
└────────┬────────┘
┌─────────────────┐
│ Run Tests │
└────────┬────────┘
┌─────────────────┐
│ Build Docker │
│ Image (staging) │
└────────┬────────┘
┌─────────────────┐
│ Deploy Staging │
│ (Port 3001) │
└────────┬────────┘
┌─────────────────┐
│ Health Check │
└─────────────────┘
```
## Nächste Schritte
1. ✅ Teste lokal mit `npm run dev`
2. ✅ Konfiguriere Gitea Variables und Secrets
3. ✅ Push zum `dev` Branch
4. ✅ Teste Staging auf Port 3001
5. ✅ Wenn alles funktioniert: Merge zu `production` Branch
---
**Tipp:** Verwende `LOG_LEVEL=debug` in Staging um mehr Informationen zu sehen!

150
DOCKER_BUILD_FIX.md Normal file
View File

@@ -0,0 +1,150 @@
# 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.

View File

@@ -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,7 +69,10 @@ RUN chown nextjs:nodejs .next
# Automatically leverage output traces to reduce image size
# https://nextjs.org/docs/advanced-features/output-file-tracing
COPY --from=builder --chown=nextjs:nodejs /app/.next/standalone/app ./
# Copy standalone output (contains server.js and all dependencies)
# The standalone output structure is: .next/standalone/ (not .next/standalone/app/)
# Next.js creates: .next/standalone/server.js, .next/standalone/.next/, .next/standalone/node_modules/
COPY --from=builder --chown=nextjs:nodejs /app/.next/standalone ./
COPY --from=builder --chown=nextjs:nodejs /app/.next/static ./.next/static
# Copy Prisma files

View File

@@ -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: {

View File

@@ -22,6 +22,9 @@ services:
- MY_INFO_PASSWORD=${MY_INFO_PASSWORD}
- ADMIN_BASIC_AUTH=${ADMIN_BASIC_AUTH:-admin:staging_password}
- LOG_LEVEL=debug
- N8N_WEBHOOK_URL=${N8N_WEBHOOK_URL:-https://n8n.dk0.dev}
- N8N_API_KEY=${N8N_API_KEY}
- N8N_SECRET_TOKEN=${N8N_SECRET_TOKEN}
volumes:
- portfolio_staging_data:/app/.next/cache
networks: