mgbam commited on
Commit
392f2f7
·
verified ·
1 Parent(s): 0f0f717

Update Dockerfile

Browse files
Files changed (1) hide show
  1. Dockerfile +16 -23
Dockerfile CHANGED
@@ -1,12 +1,11 @@
1
  FROM python:3.10-slim
2
 
3
  # Set environment variables
4
- ENV PYTHONUNBUFFERED=1
5
- ENV DEBIAN_FRONTEND=noninteractive
6
- # Add the default user local bin to PATH. This is where pip often installs executables.
7
- ENV PATH="/home/appuser/.local/bin:${PATH}"
8
 
9
- # Install system dependencies (ffmpeg, fontconfig for managing copied fonts)
10
  RUN apt-get update && \
11
  apt-get install -y --no-install-recommends \
12
  ffmpeg \
@@ -16,38 +15,32 @@ RUN apt-get update && \
16
  apt-get clean && \
17
  rm -rf /var/lib/apt/lists/*
18
 
19
- # Create directory for custom fonts and copy your font file(s)
20
  RUN mkdir -p /usr/local/share/fonts/truetype/mycustomfonts
21
  COPY assets/fonts/arial.ttf /usr/local/share/fonts/truetype/mycustomfonts/arial.ttf
22
-
23
- # Rebuild font cache
24
  RUN fc-cache -f -s -v
25
 
26
- # Create a non-root user and group
27
  ARG APP_USER_UID=1000
28
  ARG APP_USER_GID=1000
29
  RUN groupadd --gid $APP_USER_GID appgroup && \
30
  useradd --uid $APP_USER_UID --gid appgroup --shell /bin/bash --create-home appuser
31
- # The --create-home flag for useradd usually sets up a basic .profile or .bashrc
32
- # which should configure PATH to include ~/.local/bin, but we make it explicit with ENV PATH.
33
 
34
- WORKDIR /home/appuser/app # This is appuser's home and working directory
 
35
 
36
- # Copy requirements.txt and install Python dependencies AS APPUSER
37
  COPY --chown=appuser:appgroup requirements.txt ./
38
- USER appuser # Switch to appuser BEFORE pip install
39
 
40
- # Upgrade pip and install Python dependencies
41
- # Use python -m pip and specify --user if installing into user's site-packages
42
- # However, since WORKDIR is home and we switched user, pip should install to user's .local by default.
43
- RUN python -m pip install --no-cache-dir --upgrade pip
44
- RUN python -m pip install --no-cache-dir -r requirements.txt --verbose # Add --verbose for more output
45
 
46
- # Verify streamlit installation location after pip install
47
- RUN which streamlit || echo "streamlit not found in PATH after pip install"
48
- RUN ls -l /home/appuser/.local/bin || echo "/home/appuser/.local/bin does not exist or is empty"
49
 
50
- # Copy the rest of the application code as the appuser
51
  COPY --chown=appuser:appgroup . .
52
 
53
  EXPOSE 8501
 
1
  FROM python:3.10-slim
2
 
3
  # Set environment variables
4
+ ENV PYTHONUNBUFFERED=1 \
5
+ DEBIAN_FRONTEND=noninteractive \
6
+ PATH="/home/appuser/.local/bin:${PATH}"
 
7
 
8
+ # Install system dependencies
9
  RUN apt-get update && \
10
  apt-get install -y --no-install-recommends \
11
  ffmpeg \
 
15
  apt-get clean && \
16
  rm -rf /var/lib/apt/lists/*
17
 
18
+ # Set up custom fonts
19
  RUN mkdir -p /usr/local/share/fonts/truetype/mycustomfonts
20
  COPY assets/fonts/arial.ttf /usr/local/share/fonts/truetype/mycustomfonts/arial.ttf
 
 
21
  RUN fc-cache -f -s -v
22
 
23
+ # Create non-root user
24
  ARG APP_USER_UID=1000
25
  ARG APP_USER_GID=1000
26
  RUN groupadd --gid $APP_USER_GID appgroup && \
27
  useradd --uid $APP_USER_UID --gid appgroup --shell /bin/bash --create-home appuser
 
 
28
 
29
+ # Set working directory
30
+ WORKDIR /home/appuser/app
31
 
32
+ # Install Python dependencies
33
  COPY --chown=appuser:appgroup requirements.txt ./
34
+ USER appuser
35
 
36
+ RUN python -m pip install --no-cache-dir --upgrade pip && \
37
+ python -m pip install --no-cache-dir -r requirements.txt --verbose
 
 
 
38
 
39
+ # Verify installation
40
+ RUN which streamlit || echo "streamlit not found in PATH" && \
41
+ ls -l /home/appuser/.local/bin || echo "Local bin directory not found"
42
 
43
+ # Copy application code
44
  COPY --chown=appuser:appgroup . .
45
 
46
  EXPOSE 8501