Skip to content

Commit 304a9dc

Browse files
committed
include postgres into k8s
1 parent d1df85e commit 304a9dc

File tree

3 files changed

+41
-31
lines changed

3 files changed

+41
-31
lines changed

backend/Dockerfile

Lines changed: 23 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,43 +1,36 @@
1-
FROM python:3.10
1+
FROM python:3.11-slim
22

33
ENV PYTHONUNBUFFERED=1
44

55
WORKDIR /app/
66

7-
# Install uv
8-
# Ref: https://docs.astral.sh/uv/guides/integration/docker/#installing-uv
9-
COPY --from=ghcr.io/astral-sh/uv:0.5.11 /uv /uvx /bin/
7+
# Install system dependencies
8+
RUN apt-get update && apt-get install -y \
9+
gcc \
10+
&& rm -rf /var/lib/apt/lists/*
1011

11-
# Place executables in the environment at the front of the path
12-
# Ref: https://docs.astral.sh/uv/guides/integration/docker/#using-the-environment
13-
ENV PATH="/app/.venv/bin:$PATH"
12+
# Install Python dependencies
13+
COPY requirements.txt .
14+
RUN pip install --no-cache-dir -r requirements.txt
1415

15-
# Compile bytecode
16-
# Ref: https://docs.astral.sh/uv/guides/integration/docker/#compiling-bytecode
17-
ENV UV_COMPILE_BYTECODE=1
16+
# Copy application code
17+
COPY ./scripts /app/scripts
18+
COPY ./alembic.ini /app/
19+
COPY ./app /app/app
1820

19-
# uv Cache
20-
# Ref: https://docs.astral.sh/uv/guides/integration/docker/#caching
21-
ENV UV_LINK_MODE=copy
21+
# Create a non-root user
22+
RUN useradd -m -u 1000 appuser && \
23+
chown -R appuser:appuser /app
2224

23-
# Install dependencies
24-
# Ref: https://docs.astral.sh/uv/guides/integration/docker/#intermediate-layers
25-
RUN --mount=type=cache,target=/root/.cache/uv \
26-
--mount=type=bind,source=uv.lock,target=uv.lock \
27-
--mount=type=bind,source=pyproject.toml,target=pyproject.toml \
28-
uv sync --frozen --no-install-project
25+
# Switch to non-root user
26+
USER appuser
2927

28+
# Set environment variables
3029
ENV PYTHONPATH=/app
30+
ENV ENVIRONMENT=production
3131

32-
COPY ./scripts /app/scripts
33-
34-
COPY ./pyproject.toml ./uv.lock ./alembic.ini /app/
35-
36-
COPY ./app /app/app
37-
38-
# Sync the project
39-
# Ref: https://docs.astral.sh/uv/guides/integration/docker/#intermediate-layers
40-
RUN --mount=type=cache,target=/root/.cache/uv \
41-
uv sync
32+
# Expose port
33+
EXPOSE 8000
4234

43-
CMD ["fastapi", "run", "--workers", "4", "app/main.py"]
35+
# Start the application
36+
CMD ["python3.11", "-m", "uvicorn", "app.main:app", "--host", "0.0.0.0", "--port", "8000", "--log-level", "debug"]

backend/app/core/db.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,4 +30,4 @@ def init_db(session: Session) -> None:
3030
password=settings.FIRST_SUPERUSER_PASSWORD,
3131
is_superuser=True,
3232
)
33-
user = crud.create_user(session=session, user_create=user_in)
33+
user = crud.create_user(session=session, user_create=user_in)

backend/requirements.txt

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
fastapi[standard]>=0.114.2,<1.0.0
2+
python-multipart>=0.0.7,<1.0.0
3+
email-validator>=2.1.0.post1,<3.0.0.0
4+
passlib[bcrypt]>=1.7.4,<2.0.0
5+
tenacity>=8.2.3,<9.0.0
6+
pydantic>2.0
7+
emails>=0.6,<1.0
8+
jinja2>=3.1.4,<4.0.0
9+
alembic<2.0.0,>=1.12.1
10+
httpx>=0.25.1,<1.0.0
11+
psycopg[binary]<4.0.0,>=3.1.13
12+
sqlmodel>=0.0.21,<1.0.0
13+
bcrypt==4.0.1
14+
pydantic-settings>=2.2.1,<3.0.0
15+
sentry-sdk[fastapi]>=1.40.6,<2.0.0
16+
PyJWT>=2.8.0,<3.0.0
17+
python-dotenv>=1.0.0

0 commit comments

Comments
 (0)