From ae12eb87f02797876f3e4b51976ba1599bc10fac Mon Sep 17 00:00:00 2001 From: Andreas Knuth Date: Fri, 6 Feb 2026 11:21:39 -0600 Subject: [PATCH] neuer build --- bizmatch-server/Dockerfile | 28 +++++++++------ bizmatch-server/docker-compose.yml | 48 ------------------------- bizmatch/Dockerfile | 22 +++++++++--- bizmatch/docker-compose.yml | 10 ------ docker-compose.yml | 58 ++++++++++++++++++++++++++++++ update.sh | 21 +++++++++++ 6 files changed, 113 insertions(+), 74 deletions(-) delete mode 100644 bizmatch-server/docker-compose.yml delete mode 100644 bizmatch/docker-compose.yml create mode 100644 docker-compose.yml create mode 100755 update.sh diff --git a/bizmatch-server/Dockerfile b/bizmatch-server/Dockerfile index 985a1d3..a167bd1 100644 --- a/bizmatch-server/Dockerfile +++ b/bizmatch-server/Dockerfile @@ -1,19 +1,25 @@ -# Build Stage -FROM node:18-alpine AS build - +# --- STAGE 1: Build --- +FROM node:22-alpine AS builder WORKDIR /app +# HIER KEIN NODE_ENV=production setzen! Wir brauchen devDependencies zum Bauen. COPY package*.json ./ -RUN npm install +RUN npm ci COPY . . RUN npm run build -# Runtime Stage -FROM node:18-alpine - +# --- STAGE 2: Runtime --- +FROM node:22-alpine WORKDIR /app -COPY --from=build /app/dist /app/dist -COPY --from=build /app/package*.json /app/ -RUN npm install --production +# HIER ist es richtig! +ENV NODE_ENV=production -CMD ["node", "dist/main.js"] \ No newline at end of file +COPY --from=builder /app/dist /app/dist +COPY --from=builder /app/package*.json /app/ + +# Installiert nur "dependencies" (Nest core, TypeORM, Helmet, Sharp etc.) +# "devDependencies" (TypeScript, Jest, ESLint) werden weggelassen. +RUN npm ci --omit=dev + +# WICHTIG: Pfad prüfen (siehe Punkt 2 unten) +CMD ["node", "dist/src/main.js"] \ No newline at end of file diff --git a/bizmatch-server/docker-compose.yml b/bizmatch-server/docker-compose.yml deleted file mode 100644 index 9d4d2d5..0000000 --- a/bizmatch-server/docker-compose.yml +++ /dev/null @@ -1,48 +0,0 @@ -services: - app: - image: node:22-alpine - container_name: bizmatch-app - working_dir: /app - volumes: - - ./:/app - - node_modules:/app/node_modules - ports: - - '3001:3001' - env_file: - - .env - environment: - - NODE_ENV=development - - DATABASE_URL - command: sh -c "if [ ! -f node_modules/.installed ]; then npm ci && touch node_modules/.installed; fi && npm run build && node dist/src/main.js" - restart: unless-stopped - depends_on: - - postgres - networks: - - bizmatch - - postgres: - container_name: bizmatchdb - image: postgres:17-alpine - restart: unless-stopped - volumes: - - bizmatch-db-data:/var/lib/postgresql/data - env_file: - - .env - environment: - POSTGRES_DB: ${POSTGRES_DB} - POSTGRES_USER: ${POSTGRES_USER} - POSTGRES_PASSWORD: ${POSTGRES_PASSWORD} - ports: - - '5434:5432' - networks: - - bizmatch - -volumes: - bizmatch-db-data: - driver: local - node_modules: - driver: local - -networks: - bizmatch: - external: true diff --git a/bizmatch/Dockerfile b/bizmatch/Dockerfile index 70d106c..31f55d2 100644 --- a/bizmatch/Dockerfile +++ b/bizmatch/Dockerfile @@ -1,13 +1,25 @@ -FROM node:22-alpine +# STAGE 1: Build +FROM node:22-alpine AS builder +WORKDIR /app +COPY package*.json ./ +RUN npm ci +COPY . . +# Wir bauen die SSR Version +RUN npm run build:ssr +# STAGE 2: Run +FROM node:22-alpine WORKDIR /app -# GANZEN dist-Ordner kopieren, nicht nur bizmatch -COPY dist ./dist -COPY package*.json ./ +# Kopiere den gebauten 'dist' Ordner aus Stage 1 +COPY --from=builder /app/dist /app/dist +COPY --from=builder /app/package*.json /app/ +# Installiere nur Dependencies für die Laufzeit (Express, etc.) RUN npm ci --omit=dev -EXPOSE 4200 +# Standard SSR Port ist oft 4000, wir setzen ihn explizit +ENV PORT=4000 +EXPOSE 4000 CMD ["node", "dist/bizmatch/server/server.mjs"] diff --git a/bizmatch/docker-compose.yml b/bizmatch/docker-compose.yml deleted file mode 100644 index c216dfe..0000000 --- a/bizmatch/docker-compose.yml +++ /dev/null @@ -1,10 +0,0 @@ -services: - bizmatch-ssr: - build: . - image: bizmatch-ssr - container_name: bizmatch-ssr - restart: unless-stopped - ports: - - '4200:4200' - environment: - NODE_ENV: DEVELOPMENT diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..1de60a1 --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,58 @@ +services: + # --- FRONTEND --- + bizmatch-ssr: + build: + context: ./bizmatch # Pfad zum Angular Ordner + dockerfile: Dockerfile + image: bizmatch-ssr:latest + container_name: bizmatch-ssr + restart: unless-stopped + ports: + - '4200:4000' # Extern 4200 -> Intern 4000 (SSR) + environment: + NODE_ENV: production + + # --- BACKEND --- + app: + build: + context: ./bizmatch-server # Pfad zum NestJS Ordner + dockerfile: Dockerfile + image: bizmatch-server:latest + container_name: bizmatch-app + restart: unless-stopped + ports: + - '3001:3001' + env_file: + - ./bizmatch-server/.env # Pfad zur .env Datei + depends_on: + - postgres + networks: + - bizmatch + # WICHTIG: Kein Volume Mapping für node_modules im Prod-Modus! + # Das Image bringt alles fertig mit. + + # --- DATABASE --- + postgres: + container_name: bizmatchdb + image: postgres:17-alpine + restart: unless-stopped + volumes: + - bizmatch-db-data:/var/lib/postgresql/data + env_file: + - ./bizmatch-server/.env + environment: + POSTGRES_DB: ${POSTGRES_DB} + POSTGRES_USER: ${POSTGRES_USER} + POSTGRES_PASSWORD: ${POSTGRES_PASSWORD} + ports: + - '5434:5432' + networks: + - bizmatch + +volumes: + bizmatch-db-data: + driver: local + +networks: + bizmatch: + external: false # Oder true, falls du es manuell erstellt hast \ No newline at end of file diff --git a/update.sh b/update.sh new file mode 100755 index 0000000..11ff900 --- /dev/null +++ b/update.sh @@ -0,0 +1,21 @@ +#!/bin/bash + +echo "🚀 Starte Update Prozess..." + +# 1. Neuesten Code holen +echo "📥 Git Pull..." +git pull + +# 2. Docker Images neu bauen und Container neu starten +# --build: Zwingt Docker, die Images neu zu bauen (nutzt Multi-Stage) +# -d: Detached mode (im Hintergrund) +# --remove-orphans: Räumt alte Container auf, falls Services umbenannt wurden +echo "🐳 Baue und starte Container..." +docker compose up -d --build --remove-orphans + +# 3. Aufräumen (Optional) +# Löscht alte Images ("dangling images"), die beim Build übrig geblieben sind, um Platz zu sparen +echo "🧹 Räume alte Images auf..." +docker image prune -f + +echo "✅ Fertig! Die App läuft in der neuesten Version." \ No newline at end of file