1+ FROM python:3.13-slim as builder
2+
3+ ENV PYTHONUNBUFFERED=1 \
4+ PYTHONDONTWRITEBYTECODE=1 \
5+ PIP_NO_CACHE_DIR=1 \
6+ PIP_DISABLE_PIP_VERSION_CHECK=1 \
7+ POETRY_VERSION=1.8.2 \
8+ POETRY_HOME="/opt/poetry" \
9+ POETRY_NO_INTERACTION=1 \
10+ POETRY_VIRTUALENVS_IN_PROJECT=true \
11+ POETRY_VIRTUALENVS_CREATE=true
12+
13+ RUN apt-get update && apt-get install -y --no-install-recommends \
14+ build-essential \
15+ curl \
16+ && rm -rf /var/lib/apt/lists/*
17+
18+ RUN curl -sSL https://install.python-poetry.org | python3 - \
19+ && ln -s /opt/poetry/bin/poetry /usr/local/bin/poetry
20+
21+ WORKDIR /app
22+
23+ COPY pyproject.toml poetry.lock ./
24+
25+ RUN poetry install --no-dev --no-root --no-interaction --no-ansi
26+
27+ FROM python:3.13-slim as runtime
28+
29+ ENV PYTHONUNBUFFERED=1 \
30+ PYTHONDONTWRITEBYTECODE=1 \
31+ PATH="/app/.venv/bin:$PATH" \
32+ ENCRYPTED_NOTES_CONFIG_DIR="/data/config" \
33+ ENCRYPTED_NOTES_STORAGE_DIR="/data/storage"
34+
35+ RUN apt-get update && apt-get install -y --no-install-recommends \
36+ libpq5 \
37+ && rm -rf /var/lib/apt/lists/*
38+
39+ RUN groupadd -r appuser && useradd -r -g appuser appuser
40+
41+ WORKDIR /app
42+
43+ COPY --from=builder /app/.venv /app/.venv
44+
45+ COPY encrypted_notes ./encrypted_notes
46+ COPY pyproject.toml poetry.lock README.md ./
47+
48+ RUN mkdir -p /data/config /data/storage && \
49+ chown -R appuser:appuser /app /data
50+
51+ USER appuser
52+
53+ HEALTHCHECK --interval=30s --timeout=10s --start-period=5s --retries=3 \
54+ CMD python -c "import requests; requests.get('http://localhost:8000/health', timeout=5)" || exit 1
55+
56+ # Expose port
57+ EXPOSE 8000
58+
59+ # Default command - Run API server
60+ CMD ["python" , "-m" , "encrypted_notes.api" ]
0 commit comments