From 75cf22f7e54da7613ef3731ea2494dac321b13f4 Mon Sep 17 00:00:00 2001 From: Chris Date: Fri, 3 Apr 2026 03:11:28 +0800 Subject: [PATCH] Add production Dockerfile for backend deployment --- .dockerignore | 13 +++++++++++++ Dockerfile | 19 +++++++++++++++++++ README.md | 23 +++++++++++++++++++++++ 3 files changed, 55 insertions(+) create mode 100644 .dockerignore create mode 100644 Dockerfile diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..4dd4df8 --- /dev/null +++ b/.dockerignore @@ -0,0 +1,13 @@ +.git +.gitignore +.venv +__pycache__ +*.pyc +*.pyo +*.pyd +.pytest_cache +.ruff_cache +tests +.env +.env.development +*.log diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..09af022 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,19 @@ +FROM python:3.12-slim + +ENV PYTHONDONTWRITEBYTECODE=1 \ + PYTHONUNBUFFERED=1 + +WORKDIR /app + +# Install runtime dependencies from local package metadata. +COPY pyproject.toml /app/pyproject.toml +COPY app /app/app +COPY scripts /app/scripts +COPY README.md /app/README.md + +RUN pip install --no-cache-dir --upgrade pip && \ + pip install --no-cache-dir . + +EXPOSE 8000 + +CMD ["uvicorn", "app.main:app", "--host", "0.0.0.0", "--port", "8000"] diff --git a/README.md b/README.md index b61dee6..671ed23 100644 --- a/README.md +++ b/README.md @@ -12,6 +12,29 @@ psql "$DATABASE_URL" -f scripts/init_schema.sql ./scripts/start_dev.sh ``` +## Docker (VPS / Production) + +Build image: +```bash +cd backend +docker build -t memberapi-backend:latest . +``` + +Run container: +```bash +docker run -d \ + --name memberapi-backend \ + --restart unless-stopped \ + -p 127.0.0.1:8000:8000 \ + --env-file .env \ + memberapi-backend:latest +``` + +Health check: +```bash +curl http://127.0.0.1:8000/healthz +``` + ## Keycloak env - Required: