forked from 2024-Winter-Bootcamp-Team-G/backend
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDockerfile
48 lines (37 loc) · 1.18 KB
/
Dockerfile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# Stage 1: Build stage
FROM python:3.12-slim as builder
# Set environment variables
ENV PYTHONDONTWRITEBYTECODE=1 \
PYTHONUNBUFFERED=1 \
PATH="/root/.local/bin:$PATH"
# Set working directory
WORKDIR /app
# Install build dependencies
RUN apt-get update && apt-get install -y --no-install-recommends \
build-essential libpq-dev && \
apt-get clean && \
rm -rf /var/lib/apt/lists/*
# Install Python dependencies
COPY requirements.txt /app/
RUN pip install --no-cache-dir --upgrade pip && \
pip install --no-cache-dir --user -r requirements.txt && \
ln -s /root/.local/bin/celery /usr/local/bin/celery
# Add celery user
RUN useradd -ms /bin/bash celeryuser
USER celeryuser
WORKDIR /home/celeryuser
# Stage 2: Runtime stage
FROM python:3.12-slim
# Set environment variables
ENV PYTHONDONTWRITEBYTECODE=1 \
PYTHONUNBUFFERED=1 \
PATH="/root/.local/bin:$PATH"
# Set working directory
WORKDIR /app
# Copy only necessary files from the builder stage
COPY --from=builder /root/.local /root/.local
COPY . /app/
# Expose the FastAPI default port
EXPOSE 8000
# Command to run the FastAPI app
CMD ["uvicorn", "app.main:app", "--host", "0.0.0.0", "--port", "8000", "--reload"]