File size: 1,651 Bytes
5005caf
 
 
 
 
 
af1985c
5005caf
 
 
 
 
af1985c
 
 
5005caf
af1985c
5005caf
 
 
 
 
af1985c
5005caf
 
 
af1985c
 
 
 
 
 
 
 
 
b4fb898
af1985c
5005caf
 
 
af1985c
5005caf
 
 
b4fb898
 
 
af1985c
5005caf
 
af1985c
e3c5342
 
 
 
 
 
 
 
 
 
 
 
 
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
# syntax=docker/dockerfile:1
ARG PYTHON_VERSION=3.12

FROM python:${PYTHON_VERSION}-slim AS python-base
ARG TEST_ENV

# Set environment variables
ENV PYTHONUNBUFFERED=1 \
    PYTHONDONTWRITEBYTECODE=1 \
    PORT=${PORT:-9090} \
    PIP_CACHE_DIR=/.cache \
    WORKERS=1 \
    THREADS=8 \
    PATH="/home/user/.local/bin:$PATH" \
    HF_CHECKPOINT_DIR=/data/checkpoints

# Update the base OS (must run as root)
RUN --mount=type=cache,target="/var/cache/apt",sharing=locked \
    --mount=type=cache,target="/var/lib/apt/lists",sharing=locked \
    set -eux; \
    apt-get update; \
    apt-get upgrade -y; \
    apt install --no-install-recommends -y \
        git; \
    apt-get autoremove -y

# Create user and set up directories
RUN useradd -m -u 1000 user && \
    mkdir -p /data/checkpoints /data/cache && \
    chown -R user:user /data

# Switch to non-root user
USER user
WORKDIR /home/user/app

# Copy and install requirements
COPY --chown=user requirements-base.txt .
RUN --mount=type=cache,target=${PIP_CACHE_DIR},sharing=locked \
    pip install -r requirements-base.txt

COPY --chown=user requirements.txt .
RUN --mount=type=cache,target=${PIP_CACHE_DIR},sharing=locked \
    pip install -r requirements.txt

# Copy remaining application files
COPY --chown=user . .

# Expose the service port
EXPOSE 9090

# Command to run the application
CMD PYTHONPATH=/home/user/app \
    gunicorn \
    --preload \
    --bind :$PORT \
    --workers $WORKERS \
    --threads $THREADS \
    --timeout 120 \
    --worker-connections 100 \
    --worker-class gthread \
    --log-level warning \
    --access-logfile - \
    --error-logfile - \
    _wsgi:app