Files
web/Dockerfile
2026-11-06 11:42:34 -05:00

33 lines
1.1 KiB
Docker

# One image for every host (Render, Fly.io, Railway, a VPS...).
# docker build -t mamadachi-web .
# docker run -p 8000:8000 -e DATABASE_URL=postgresql://... mamadachi-web
FROM python:3.13-slim
ENV PYTHONDONTWRITEBYTECODE=1 \
PYTHONUNBUFFERED=1 \
PIP_NO_CACHE_DIR=1 \
PIP_DISABLE_PIP_VERSION_CHECK=1 \
PORT=8000 \
APP_ENV=production
WORKDIR /app
COPY requirements.txt .
RUN pip install -r requirements.txt
COPY alembic.ini ./
COPY migrations ./migrations
COPY app ./app
COPY tools ./tools
# Don't run as root inside the container.
RUN useradd --create-home --uid 10001 mamadachi && chown -R mamadachi /app
USER mamadachi
EXPOSE 8000
HEALTHCHECK --interval=30s --timeout=5s --start-period=20s \
CMD python -c "import os, urllib.request; urllib.request.urlopen(f'http://127.0.0.1:{os.environ[\"PORT\"]}/healthz', timeout=4)"
# Migrations run inside the app at startup (AUTO_MIGRATE=true).
# --proxy-headers: trust the host's HTTPS proxy so URLs and cookies say https.
CMD ["sh", "-c", "exec uvicorn app.main:app --host 0.0.0.0 --port ${PORT} --proxy-headers --forwarded-allow-ips='*' --no-server-header"]