neuer build

This commit is contained in:
Andreas Knuth 2026-02-06 11:21:39 -06:00
parent 0b4e4207d1
commit ae12eb87f0
6 changed files with 113 additions and 74 deletions

View File

@ -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"]
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"]

View File

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

View File

@ -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"]

View File

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

58
docker-compose.yml Normal file
View File

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

21
update.sh Executable file
View File

@ -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."