Spaces:
Runtime error
Runtime error
Update Dockerfile
Browse files- Dockerfile +14 -20
Dockerfile
CHANGED
|
@@ -1,33 +1,27 @@
|
|
| 1 |
# 1. Start with a stable base image
|
| 2 |
FROM python:3.10.13-slim-bullseye
|
| 3 |
|
| 4 |
-
# 2.
|
| 5 |
-
WORKDIR /code
|
| 6 |
-
|
| 7 |
-
# 3. Install git as the root user
|
| 8 |
RUN apt-get update && apt-get install -y --no-install-recommends git && \
|
| 9 |
apt-get clean && rm -rf /var/lib/apt/lists/*
|
| 10 |
|
| 11 |
-
#
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 12 |
COPY ./requirements.txt .
|
| 13 |
COPY ./mine_diffs.py .
|
| 14 |
-
|
| 15 |
-
# 5. Install Python dependencies
|
| 16 |
RUN pip install --no-cache-dir --upgrade -r requirements.txt
|
| 17 |
|
| 18 |
-
# 6.
|
| 19 |
-
# This
|
| 20 |
-
RUN
|
| 21 |
-
USER user
|
| 22 |
|
| 23 |
-
# 7.
|
| 24 |
-
|
| 25 |
-
WORKDIR /home/user/code
|
| 26 |
-
RUN chown -R user:user /home/user
|
| 27 |
-
|
| 28 |
-
# 8. Copy files again to the new WORKDIR
|
| 29 |
-
COPY ./requirements.txt .
|
| 30 |
-
COPY ./mine_diffs.py .
|
| 31 |
|
| 32 |
-
#
|
| 33 |
CMD ["python", "mine_diffs.py"]
|
|
|
|
| 1 |
# 1. Start with a stable base image
|
| 2 |
FROM python:3.10.13-slim-bullseye
|
| 3 |
|
| 4 |
+
# 2. Install git as the root user
|
|
|
|
|
|
|
|
|
|
| 5 |
RUN apt-get update && apt-get install -y --no-install-recommends git && \
|
| 6 |
apt-get clean && rm -rf /var/lib/apt/lists/*
|
| 7 |
|
| 8 |
+
# 3. Create a non-root user for security
|
| 9 |
+
RUN useradd --create-home --shell /bin/bash --uid 1000 user
|
| 10 |
+
|
| 11 |
+
# 4. Set the working directory in the new user's home
|
| 12 |
+
WORKDIR /home/user/app
|
| 13 |
+
|
| 14 |
+
# 5. Copy files and install dependencies
|
| 15 |
COPY ./requirements.txt .
|
| 16 |
COPY ./mine_diffs.py .
|
|
|
|
|
|
|
| 17 |
RUN pip install --no-cache-dir --upgrade -r requirements.txt
|
| 18 |
|
| 19 |
+
# 6. Change ownership of the app directory to the non-root user.
|
| 20 |
+
# This is the critical step to grant write permissions.
|
| 21 |
+
RUN chown -R user:user /home/user/app
|
|
|
|
| 22 |
|
| 23 |
+
# 7. Switch to the non-root user
|
| 24 |
+
USER user
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 25 |
|
| 26 |
+
# 8. Run the script automatically on startup
|
| 27 |
CMD ["python", "mine_diffs.py"]
|