Commit
·
d995e98
1
Parent(s):
6f52efc
update: dockerfile
Browse files- Dockerfile +26 -7
Dockerfile
CHANGED
|
@@ -2,6 +2,7 @@ FROM python:3.12-slim
|
|
| 2 |
|
| 3 |
WORKDIR /app
|
| 4 |
|
|
|
|
| 5 |
RUN apt-get update && apt-get install -y \
|
| 6 |
build-essential \
|
| 7 |
curl \
|
|
@@ -10,20 +11,38 @@ RUN apt-get update && apt-get install -y \
|
|
| 10 |
wget \
|
| 11 |
&& rm -rf /var/lib/apt/lists/*
|
| 12 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 13 |
# Install UV
|
| 14 |
-
|
| 15 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 16 |
COPY requirements.txt ./
|
| 17 |
|
| 18 |
-
#
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
|
|
|
|
|
|
| 22 |
|
| 23 |
-
|
|
|
|
| 24 |
|
| 25 |
EXPOSE 8501
|
| 26 |
|
| 27 |
HEALTHCHECK CMD curl --fail http://localhost:8501/_stcore/health
|
| 28 |
|
| 29 |
-
|
|
|
|
|
|
| 2 |
|
| 3 |
WORKDIR /app
|
| 4 |
|
| 5 |
+
# Install system dependencies
|
| 6 |
RUN apt-get update && apt-get install -y \
|
| 7 |
build-essential \
|
| 8 |
curl \
|
|
|
|
| 11 |
wget \
|
| 12 |
&& rm -rf /var/lib/apt/lists/*
|
| 13 |
|
| 14 |
+
# Create a non-root user
|
| 15 |
+
RUN groupadd --gid 1000 appuser && \
|
| 16 |
+
useradd --uid 1000 --gid 1000 --create-home --shell /bin/bash appuser
|
| 17 |
+
|
| 18 |
+
# Set UV environment variables to use writable cache locations
|
| 19 |
+
ENV UV_CACHE_DIR=/tmp/uv-cache
|
| 20 |
+
ENV UV_TOOL_DIR=/tmp/uv-tools
|
| 21 |
+
ENV UV_PYTHON_INSTALL_DIR=/tmp/uv-python
|
| 22 |
+
|
| 23 |
# Install UV
|
| 24 |
+
RUN pip3 install uv
|
| 25 |
|
| 26 |
+
# Create cache directories with proper permissions
|
| 27 |
+
RUN mkdir -p /tmp/uv-cache /tmp/uv-tools /tmp/uv-python && \
|
| 28 |
+
chown -R appuser:appuser /tmp/uv-cache /tmp/uv-tools /tmp/uv-python
|
| 29 |
+
|
| 30 |
+
# Copy requirements first for better Docker layer caching
|
| 31 |
COPY requirements.txt ./
|
| 32 |
|
| 33 |
+
# Switch to non-root user
|
| 34 |
+
USER appuser
|
| 35 |
+
|
| 36 |
+
# Create virtual environment and install dependencies
|
| 37 |
+
RUN uv venv /home/appuser/.venv
|
| 38 |
+
RUN uv pip install -r requirements.txt
|
| 39 |
|
| 40 |
+
# Copy application code
|
| 41 |
+
COPY --chown=appuser:appuser src/ ./src/
|
| 42 |
|
| 43 |
EXPOSE 8501
|
| 44 |
|
| 45 |
HEALTHCHECK CMD curl --fail http://localhost:8501/_stcore/health
|
| 46 |
|
| 47 |
+
# Use the virtual environment directly
|
| 48 |
+
ENTRYPOINT ["/home/appuser/.venv/bin/python", "-m", "streamlit", "run", "src/streamlit_app.py", "--server.port=8501", "--server.address=0.0.0.0"]
|