add docker files

This commit is contained in:
Marcus Almert
2025-10-28 12:18:48 +01:00
parent d793462ace
commit dbf54f59ef
6 changed files with 74 additions and 4 deletions

6
.gitignore vendored
View File

@@ -72,9 +72,9 @@ backend/.benchmarks/
# =========================
# Docker
# =========================
**/Dockerfile*
**/docker-compose.yml
**/docker-compose.override.yml
# **/Dockerfile*
# **/docker-compose.yml
# **/docker-compose.override.yml
**/.dockerignore
# Docker artifacts

16
backend/Dockerfile Normal file
View File

@@ -0,0 +1,16 @@
FROM python:3.11-slim
WORKDIR /app
# Dependencies installieren
COPY requirements.txt .
RUN pip install --no-cache-dir -r requirements.txt
# Source-Code kopieren
COPY src/ ./src
# Port öffnen
EXPOSE 8000
# FastAPI starten (Uvicorn)
CMD ["uvicorn", "src.main:app", "--host", "0.0.0.0", "--port", "8000"]

View File

@@ -1,5 +1,6 @@
from fastapi import FastAPI
from fastapi.middleware.cors import CORSMiddleware
import os
app = FastAPI()
@@ -14,3 +15,9 @@ app.add_middleware(
@app.get("/api/hello")
def read_root():
return {"message": "Hallo von FastAPI 🎉"}
@app.get("/api/versions")
def read_root():
message = os.popen("python --version").read().strip()
return {"message": message}

0
docker-compose.prod.yml Normal file
View File

23
docker-compose.yml Normal file
View File

@@ -0,0 +1,23 @@
version: "3.8"
services:
backend:
build:
context: ./backend
container_name: fastapi-backend
ports:
- "8000:8000"
volumes:
- ./backend/src:/app/src:Z
environment:
- PYTHONUNBUFFERED=1
command: uvicorn src.main:app --host 0.0.0.0 --port 8000 --reload
frontend:
build:
context: ./frontend
container_name: react-frontend
ports:
- "3000:80"
depends_on:
- backend

24
frontend/Dockerfile Normal file
View File

@@ -0,0 +1,24 @@
# --- Build Stage ---
FROM node:20 AS build
WORKDIR /app
# 1. Nur package.json zuerst kopieren → Cache für Dependencies
COPY package*.json ./
# 2. Abhängigkeiten installieren
RUN npm ci
# 3. Restlichen Code kopieren
COPY . .
# 4. Sicherstellen, dass vite ausführbar ist (Windows-Berechtigungsfix)
RUN chmod +x node_modules/.bin/vite
# 5. Frontend bauen
RUN npm run build
# --- Serve Stage ---
FROM nginx:alpine
COPY --from=build /app/dist /usr/share/nginx/html
EXPOSE 3000
CMD ["nginx", "-g", "daemon off;"]