Compare commits
2 Commits
03ceb3de7f
...
64c257f050
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
64c257f050 | ||
|
|
b021f9aaa7 |
36
Dockerfile
36
Dockerfile
@@ -1,25 +1,41 @@
|
|||||||
# Build-Phase
|
# STAGE 1: Dependencies & Build
|
||||||
FROM node:20-slim AS builder
|
FROM node:20-alpine AS builder
|
||||||
WORKDIR /app
|
WORKDIR /app
|
||||||
|
|
||||||
COPY package*.json ./
|
COPY package*.json ./
|
||||||
RUN npm install --legacy-peer-deps
|
RUN npm ci
|
||||||
|
|
||||||
COPY . .
|
COPY . .
|
||||||
|
ENV NODE_ENV=production
|
||||||
RUN npm run build
|
RUN npm run build
|
||||||
|
|
||||||
# Production-Phase (Node SSR Runner)
|
# STAGE 2: Production Runner
|
||||||
FROM node:20-slim AS runner
|
FROM node:20-alpine AS runner
|
||||||
WORKDIR /app
|
WORKDIR /app
|
||||||
|
|
||||||
ENV NODE_ENV=production
|
ENV NODE_ENV=production
|
||||||
ENV HOST=0.0.0.0
|
ENV HOST=0.0.0.0
|
||||||
ENV PORT=4321
|
ENV PORT=3000
|
||||||
ENV DATA_DIR=/app/data
|
ENV DATA_DIR=/app/data
|
||||||
|
|
||||||
COPY --from=builder /app/package*.json ./
|
# Ordner anlegen & Schreibrechte vorbereiten
|
||||||
COPY --from=builder /app/node_modules ./node_modules
|
RUN mkdir -p /app/data
|
||||||
|
|
||||||
|
COPY package*.json ./
|
||||||
|
RUN npm ci --only=production
|
||||||
|
|
||||||
COPY --from=builder /app/dist ./dist
|
COPY --from=builder /app/dist ./dist
|
||||||
COPY --from=builder /app/data_template ./data_template
|
COPY --from=builder /app/public ./public
|
||||||
|
COPY docker-entrypoint.sh /app/docker-entrypoint.sh
|
||||||
|
|
||||||
EXPOSE 4321
|
# Ausführungsrechte für das Entrypoint-Skript setzen
|
||||||
|
RUN chmod +x /app/docker-entrypoint.sh
|
||||||
|
|
||||||
|
EXPOSE 3000
|
||||||
|
|
||||||
|
# Healthcheck für Docker / Nginx Proxy
|
||||||
|
HEALTHCHECK --interval=30s --timeout=3s --start-period=5s --retries=3 \
|
||||||
|
CMD wget --no-verbose --tries=1 --spider http://localhost:3000/api/health || exit 1
|
||||||
|
|
||||||
|
ENTRYPOINT ["/app/docker-entrypoint.sh"]
|
||||||
CMD ["node", "./dist/server/entry.mjs"]
|
CMD ["node", "./dist/server/entry.mjs"]
|
||||||
|
|||||||
@@ -1,15 +1,27 @@
|
|||||||
|
version: '3.8'
|
||||||
|
|
||||||
services:
|
services:
|
||||||
website:
|
app:
|
||||||
build: .
|
image: nd-waas-engine:latest
|
||||||
image: gitea.hephex.de/daniel/websitedummy:latest
|
container_name: waas_${CUSTOMER_SLUG:-kunden_app}
|
||||||
container_name: websitedummy_app
|
|
||||||
restart: always
|
restart: always
|
||||||
ports:
|
|
||||||
- "8080:4321"
|
|
||||||
environment:
|
environment:
|
||||||
- HOST=0.0.0.0
|
- NODE_ENV=production
|
||||||
- PORT=4321
|
- PORT=3000
|
||||||
- DATA_DIR=/app/data
|
- DATA_DIR=/app/data
|
||||||
volumes:
|
volumes:
|
||||||
- ./app/data:/app/data
|
# Hier werden site.config.json, sqlite.db, uploads etc. automatisch vom Container angelegt
|
||||||
|
- ./data:/app/data
|
||||||
|
ports:
|
||||||
|
# Anbindung an deinen händischen Nginx Reverse Proxy auf dem Host
|
||||||
|
- "127.0.0.1:${PORT:-8080}:3000"
|
||||||
|
healthcheck:
|
||||||
|
test: ["CMD", "wget", "--spider", "http://localhost:3000/api/health"]
|
||||||
|
interval: 10s
|
||||||
|
timeout: 3s
|
||||||
|
retries: 3
|
||||||
|
logging:
|
||||||
|
driver: "json-file"
|
||||||
|
options:
|
||||||
|
max-size: "10m"
|
||||||
|
max-file: "3"
|
||||||
|
|||||||
73
docker-entrypoint.sh
Normal file
73
docker-entrypoint.sh
Normal file
@@ -0,0 +1,73 @@
|
|||||||
|
#!/bin/sh
|
||||||
|
set -e
|
||||||
|
|
||||||
|
DATA_DIR=${DATA_DIR:-/app/data}
|
||||||
|
|
||||||
|
echo "🚀 [WaaS Container Entrypoint] Prüfe Daten-Volume unter ${DATA_DIR}..."
|
||||||
|
|
||||||
|
# 1. Sicherstellen, dass das Volume-Verzeichnis existiert
|
||||||
|
mkdir -p "$DATA_DIR"
|
||||||
|
|
||||||
|
# 2. site.config.json Seeding
|
||||||
|
if [ ! -f "$DATA_DIR/site.config.json" ]; then
|
||||||
|
echo "📄 Keine site.config.json gefunden. Erstelle Standard-Konfiguration..."
|
||||||
|
cat <<EOF > "$DATA_DIR/site.config.json"
|
||||||
|
{
|
||||||
|
"site_info": {
|
||||||
|
"title": "N&D IT Solutions Kunden-Website",
|
||||||
|
"company_name": "Mein Unternehmen",
|
||||||
|
"homepage_id": "page_home_01"
|
||||||
|
},
|
||||||
|
"navigation": [
|
||||||
|
{ "label": "Startseite", "page_id": "page_home_01" }
|
||||||
|
],
|
||||||
|
"pages": [
|
||||||
|
{
|
||||||
|
"id": "page_home_01",
|
||||||
|
"slug": "/",
|
||||||
|
"title": "Startseite",
|
||||||
|
"is_published": true,
|
||||||
|
"sections": [
|
||||||
|
{
|
||||||
|
"id": "sec_hero_init",
|
||||||
|
"type": "HeroSection",
|
||||||
|
"settings": {
|
||||||
|
"title": "Herzlich Willkommen",
|
||||||
|
"subtitle": "Ihre neue Website ist erfolgreich gestartet."
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
EOF
|
||||||
|
fi
|
||||||
|
|
||||||
|
# 3. theme.config.json Seeding
|
||||||
|
if [ ! -f "$DATA_DIR/theme.config.json" ]; then
|
||||||
|
echo "🎨 Keine theme.config.json gefunden. Erstelle Standard-Theme..."
|
||||||
|
cat <<EOF > "$DATA_DIR/theme.config.json"
|
||||||
|
{
|
||||||
|
"presetKey": "corporate-dark",
|
||||||
|
"mode": "dark"
|
||||||
|
}
|
||||||
|
EOF
|
||||||
|
fi
|
||||||
|
|
||||||
|
# 4. smtp.config.json Seeding
|
||||||
|
if [ ! -f "$DATA_DIR/smtp.config.json" ]; then
|
||||||
|
echo "✉️ Keine smtp.config.json gefunden. Erstelle Standard-SMTP Config..."
|
||||||
|
cat <<EOF > "$DATA_DIR/smtp.config.json"
|
||||||
|
{
|
||||||
|
"host": "localhost",
|
||||||
|
"port": 1025,
|
||||||
|
"from": "noreply@kunden-domain.de",
|
||||||
|
"recipient": "info@kunden-domain.de"
|
||||||
|
}
|
||||||
|
EOF
|
||||||
|
fi
|
||||||
|
|
||||||
|
echo "✅ All-in-One Initialisierung abgeschlossen. Starte Astro SSR Node Server..."
|
||||||
|
|
||||||
|
# Führe den eigentlichen Befehl aus (CMD aus Dockerfile)
|
||||||
|
exec "$@"
|
||||||
37
src/pages/api/health.ts
Normal file
37
src/pages/api/health.ts
Normal file
@@ -0,0 +1,37 @@
|
|||||||
|
import type { APIRoute } from 'astro';
|
||||||
|
import fs from 'node:fs/promises';
|
||||||
|
import path from 'node:path';
|
||||||
|
|
||||||
|
export const prerender = false;
|
||||||
|
|
||||||
|
const DATA_DIR = process.env.DATA_DIR || path.join(process.cwd(), 'app', 'data');
|
||||||
|
|
||||||
|
export const GET: APIRoute = async () => {
|
||||||
|
let volumeStatus = 'ok';
|
||||||
|
|
||||||
|
try {
|
||||||
|
// Prüfe Schreib- und Lesezugriff auf /app/data/
|
||||||
|
await fs.mkdir(DATA_DIR, { recursive: true });
|
||||||
|
const testFile = path.join(DATA_DIR, '.healthcheck');
|
||||||
|
await fs.writeFile(testFile, 'ok', 'utf-8');
|
||||||
|
await fs.unlink(testFile);
|
||||||
|
} catch {
|
||||||
|
volumeStatus = 'error_data_volume_unwritable';
|
||||||
|
}
|
||||||
|
|
||||||
|
const isHealthy = volumeStatus === 'ok';
|
||||||
|
|
||||||
|
return new Response(
|
||||||
|
JSON.stringify({
|
||||||
|
status: isHealthy ? 'healthy' : 'unhealthy',
|
||||||
|
uptime: process.uptime(),
|
||||||
|
timestamp: new Date().toISOString(),
|
||||||
|
volume_status: volumeStatus,
|
||||||
|
node_version: process.version,
|
||||||
|
}),
|
||||||
|
{
|
||||||
|
status: isHealthy ? 200 : 503,
|
||||||
|
headers: { 'Content-Type': 'application/json' },
|
||||||
|
}
|
||||||
|
);
|
||||||
|
};
|
||||||
18
tests/health.test.ts
Normal file
18
tests/health.test.ts
Normal file
@@ -0,0 +1,18 @@
|
|||||||
|
import { describe, it, expect } from 'vitest';
|
||||||
|
import fs from 'node:fs/promises';
|
||||||
|
import path from 'node:path';
|
||||||
|
|
||||||
|
const DATA_DIR = path.join(process.cwd(), 'app', 'test_data_health');
|
||||||
|
|
||||||
|
describe('Healthcheck API Test', () => {
|
||||||
|
it('soll Volume-Ordner erfolgreich erstellen und beschreiben können', async () => {
|
||||||
|
await fs.mkdir(DATA_DIR, { recursive: true });
|
||||||
|
const testFile = path.join(DATA_DIR, '.vitest_health');
|
||||||
|
|
||||||
|
await fs.writeFile(testFile, 'test', 'utf-8');
|
||||||
|
const content = await fs.readFile(testFile, 'utf-8');
|
||||||
|
await fs.unlink(testFile);
|
||||||
|
|
||||||
|
expect(content).toBe('test');
|
||||||
|
});
|
||||||
|
});
|
||||||
Reference in New Issue
Block a user