File size: 1,772 Bytes
ff72db3
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
# Build Stage
FROM python:3.11-slim as builder

# μ‚¬μš©μž ν™˜κ²½ λ³€μˆ˜ μ„€μ •
ENV HOME=/home/user \
    PATH=/home/user/.local/bin:$PATH

# μ‚¬μš©μž 생성 및 κΆŒν•œ μ„€μ •
RUN useradd -m -d $HOME -s /bin/bash user

# μž‘μ—… 디렉터리 μ„€μ •
WORKDIR $HOME/app

# μ‹œμŠ€ν…œ νŒ¨ν‚€μ§€ μ—…λ°μ΄νŠΈ 및 ν•„μˆ˜ νŒ¨ν‚€μ§€ μ„€μΉ˜
RUN apt-get update && apt-get install -y \
    build-essential \
    libmariadb-dev \
    git \
    && rm -rf /var/lib/apt/lists/*

# Python νŒ¨ν‚€μ§€ 관리
RUN pip install --upgrade pip

# μ˜μ‘΄μ„± 파일 볡사
COPY --chown=user:user requirements.txt ./

# Python νŒ¨ν‚€μ§€ μ„€μΉ˜
RUN pip install --no-cache-dir -r requirements.txt

# Runtime Stage
FROM python:3.11-slim

# μ‚¬μš©μž ν™˜κ²½ λ³€μˆ˜ μ„€μ •
ENV HOME=/home/user \
    PATH=/home/user/.local/bin:$PATH

# μ‚¬μš©μž 생성 및 κΆŒν•œ μ„€μ •
RUN useradd -m -d $HOME -s /bin/bash user

# μž‘μ—… 디렉터리 μ„€μ •
WORKDIR $HOME/app

# ν•„μš”ν•œ μ‹œμŠ€ν…œ νŒ¨ν‚€μ§€ μ„€μΉ˜
RUN apt-get update && apt-get install -y \
    libmariadb-dev \
    wget \
    git \
    && rm -rf /var/lib/apt/lists/*

# Build Stageμ—μ„œ μ„€μΉ˜λœ Python νŒ¨ν‚€μ§€ 볡사
COPY --from=builder /usr/local/lib/python3.11/site-packages /usr/local/lib/python3.11/site-packages
COPY --from=builder /usr/local/bin /usr/local/bin

# μ• ν”Œλ¦¬μΌ€μ΄μ…˜ μ½”λ“œ 볡사
COPY --chown=user:user . .

# 포트 λ…ΈμΆœ (FastAPI κΈ°λ³Έ 포트: 8000)
EXPOSE 8000

# μ—…λ‘œλ“œ 디렉터리 생성 및 κΆŒν•œ μ„€μ •
RUN mkdir -p $HOME/app/uploaded_files && \
    chown -R user:user $HOME/app/uploaded_files && \
    chmod -R 777 $HOME/app/uploaded_files

# μ• ν”Œλ¦¬μΌ€μ΄μ…˜ 싀행을 μ‚¬μš©μž κΆŒν•œμœΌλ‘œ μ‹€ν–‰
USER user

# FastAPI μ‹€ν–‰ λͺ…λ Ή
CMD ["uvicorn", "app.main:app", "--host", "0.0.0.0", "--port", "8000"]