Fred808 commited on
Commit
8f8c2f2
·
verified ·
1 Parent(s): 5386d70

Update Dockerfile

Browse files
Files changed (1) hide show
  1. Dockerfile +18 -19
Dockerfile CHANGED
@@ -1,43 +1,41 @@
1
- # Use the Bullseye-based image from the start to have access to apt-get
2
  FROM python:3.11-slim-bullseye
3
 
4
- # Create app directory
5
  WORKDIR /app
6
 
7
- # Create necessary directories
8
  RUN mkdir -p /app/downloads /app/extracted /app/state
9
 
10
- # Copy requirements files
11
  COPY requirements.txt .
12
- COPY system-requirements.txt . # Assuming you might use this file, otherwise it can be removed
13
 
14
- # Install system dependencies
 
15
  RUN apt-get update && \
16
- apt-get install -y unrar && \
 
 
17
  rm -rf /var/lib/apt/lists/*
18
 
19
- # Install Python dependencies
20
- RUN pip install --no-cache-dir -r requirements.txt
21
-
22
- # Copy the application code
23
  COPY main.py .
24
  COPY docker-entrypoint.sh .
25
 
26
- # Make entrypoint executable
27
  RUN chmod +x docker-entrypoint.sh
28
 
29
- # Expose volume for extracted files
30
  VOLUME ["/app/extracted", "/app/state"]
31
 
32
- # Set proper permissions
33
- # Running chmod before creating the user ensures the directories are writable
34
- RUN chmod -R 777 /app
 
35
 
36
- # Create and switch to a non-root user
37
- RUN useradd -m -u 1000 user
38
  USER user
39
 
40
- # Set environment variables
41
  ENV PYTHONUNBUFFERED=1
42
  ENV HF_TOKEN=""
43
  ENV SOURCE_REPO="Fred808/BG1"
@@ -45,5 +43,6 @@ ENV DOWNLOAD_FOLDER=/app/downloads
45
  ENV EXTRACT_FOLDER=/app/extracted
46
  ENV STATE_FOLDER=/app/state
47
 
 
48
  ENTRYPOINT ["./docker-entrypoint.sh"]
49
  CMD ["python", "main.py"]
 
1
+ # Use the Bullseye-based image to have access to apt-get
2
  FROM python:3.11-slim-bullseye
3
 
4
+ # Set the working directory
5
  WORKDIR /app
6
 
7
+ # Create necessary directories for the application
8
  RUN mkdir -p /app/downloads /app/extracted /app/state
9
 
10
+ # Copy the Python requirements file
11
  COPY requirements.txt .
 
12
 
13
+ # Install system dependencies from apt
14
+ # and Python dependencies from pip in a single layer to save space
15
  RUN apt-get update && \
16
+ apt-get install -y --no-install-recommends unrar && \
17
+ pip install --no-cache-dir -r requirements.txt && \
18
+ apt-get clean && \
19
  rm -rf /var/lib/apt/lists/*
20
 
21
+ # Copy the rest of the application code
 
 
 
22
  COPY main.py .
23
  COPY docker-entrypoint.sh .
24
 
25
+ # Make the entrypoint script executable
26
  RUN chmod +x docker-entrypoint.sh
27
 
28
+ # Expose volumes for persistent data
29
  VOLUME ["/app/extracted", "/app/state"]
30
 
31
+ # Create a non-root user and switch to it
32
+ # Note: Permissions are set before switching user
33
+ RUN useradd -m -s /bin/bash -u 1000 user && \
34
+ chown -R user:user /app
35
 
 
 
36
  USER user
37
 
38
+ # Set environment variables for the application
39
  ENV PYTHONUNBUFFERED=1
40
  ENV HF_TOKEN=""
41
  ENV SOURCE_REPO="Fred808/BG1"
 
43
  ENV EXTRACT_FOLDER=/app/extracted
44
  ENV STATE_FOLDER=/app/state
45
 
46
+ # Set the entrypoint and default command
47
  ENTRYPOINT ["./docker-entrypoint.sh"]
48
  CMD ["python", "main.py"]