add docker files
This commit is contained in:
6
.gitignore
vendored
6
.gitignore
vendored
@@ -72,9 +72,9 @@ backend/.benchmarks/
|
|||||||
# =========================
|
# =========================
|
||||||
# Docker
|
# Docker
|
||||||
# =========================
|
# =========================
|
||||||
**/Dockerfile*
|
# **/Dockerfile*
|
||||||
**/docker-compose.yml
|
# **/docker-compose.yml
|
||||||
**/docker-compose.override.yml
|
# **/docker-compose.override.yml
|
||||||
**/.dockerignore
|
**/.dockerignore
|
||||||
|
|
||||||
# Docker artifacts
|
# Docker artifacts
|
||||||
|
|||||||
16
backend/Dockerfile
Normal file
16
backend/Dockerfile
Normal 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"]
|
||||||
@@ -1,5 +1,6 @@
|
|||||||
from fastapi import FastAPI
|
from fastapi import FastAPI
|
||||||
from fastapi.middleware.cors import CORSMiddleware
|
from fastapi.middleware.cors import CORSMiddleware
|
||||||
|
import os
|
||||||
|
|
||||||
app = FastAPI()
|
app = FastAPI()
|
||||||
|
|
||||||
@@ -14,3 +15,9 @@ app.add_middleware(
|
|||||||
@app.get("/api/hello")
|
@app.get("/api/hello")
|
||||||
def read_root():
|
def read_root():
|
||||||
return {"message": "Hallo von FastAPI 🎉"}
|
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
0
docker-compose.prod.yml
Normal file
23
docker-compose.yml
Normal file
23
docker-compose.yml
Normal 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
24
frontend/Dockerfile
Normal 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;"]
|
||||||
Reference in New Issue
Block a user