Spaces:
Paused
Paused
Update Dockerfile
Browse files- Dockerfile +17 -24
Dockerfile
CHANGED
|
@@ -1,28 +1,13 @@
|
|
| 1 |
# Use the official Python 3.9 image
|
| 2 |
FROM python:3.9
|
| 3 |
|
| 4 |
-
# Set up
|
| 5 |
-
# Hugging Face Spaces recommends running as a non-root user for security
|
| 6 |
-
RUN useradd -m -u 1000 user
|
| 7 |
-
|
| 8 |
-
# Switch to the "user" user
|
| 9 |
-
USER user
|
| 10 |
-
|
| 11 |
-
# Set environment variables
|
| 12 |
-
ENV HOME=/home/user \
|
| 13 |
-
PATH=/home/user/.local/bin:$PATH
|
| 14 |
-
|
| 15 |
-
# Set the working directory to the user's home folder
|
| 16 |
-
WORKDIR $HOME/app
|
| 17 |
-
|
| 18 |
-
# Install system dependencies
|
| 19 |
RUN apt-get update && apt-get install -y \
|
| 20 |
curl \
|
| 21 |
ca-certificates \
|
| 22 |
-
# lklklkl
|
| 23 |
&& rm -rf /var/lib/apt/lists/*
|
| 24 |
|
| 25 |
-
# Install cloudflared
|
| 26 |
RUN curl -fsSL https://pkg.cloudflare.com/cloudflare-public-v2.gpg \
|
| 27 |
| tee /usr/share/keyrings/cloudflare-public-v2.gpg >/dev/null && \
|
| 28 |
echo "deb [signed-by=/usr/share/keyrings/cloudflare-public-v2.gpg] https://pkg.cloudflare.com/cloudflared any main" \
|
|
@@ -31,16 +16,24 @@ RUN curl -fsSL https://pkg.cloudflare.com/cloudflare-public-v2.gpg \
|
|
| 31 |
apt-get install -y cloudflared && \
|
| 32 |
rm -rf /var/lib/apt/lists/*
|
| 33 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 34 |
|
| 35 |
-
|
| 36 |
-
# We use --chown=user to ensure the new user owns these files
|
| 37 |
-
COPY --chown=user . $HOME/app
|
| 38 |
|
| 39 |
-
#
|
|
|
|
|
|
|
|
|
|
|
|
|
| 40 |
RUN pip install --no-cache-dir --upgrade -r requirements.txt
|
| 41 |
|
| 42 |
-
# Expose
|
| 43 |
EXPOSE 7860
|
| 44 |
|
| 45 |
-
# Run the application
|
| 46 |
-
|
|
|
|
|
|
|
|
|
| 1 |
# Use the official Python 3.9 image
|
| 2 |
FROM python:3.9
|
| 3 |
|
| 4 |
+
# 1. Set up system dependencies as ROOT (default)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 5 |
RUN apt-get update && apt-get install -y \
|
| 6 |
curl \
|
| 7 |
ca-certificates \
|
|
|
|
| 8 |
&& rm -rf /var/lib/apt/lists/*
|
| 9 |
|
| 10 |
+
# 2. Install cloudflared as ROOT
|
| 11 |
RUN curl -fsSL https://pkg.cloudflare.com/cloudflare-public-v2.gpg \
|
| 12 |
| tee /usr/share/keyrings/cloudflare-public-v2.gpg >/dev/null && \
|
| 13 |
echo "deb [signed-by=/usr/share/keyrings/cloudflare-public-v2.gpg] https://pkg.cloudflare.com/cloudflared any main" \
|
|
|
|
| 16 |
apt-get install -y cloudflared && \
|
| 17 |
rm -rf /var/lib/apt/lists/*
|
| 18 |
|
| 19 |
+
# 3. Now create the user and set up the environment
|
| 20 |
+
RUN useradd -m -u 1000 user
|
| 21 |
+
ENV HOME=/home/user \
|
| 22 |
+
PATH=/home/user/.local/bin:$PATH
|
| 23 |
|
| 24 |
+
WORKDIR $HOME/app
|
|
|
|
|
|
|
| 25 |
|
| 26 |
+
# 4. Switch to the non-root user for app-specific tasks
|
| 27 |
+
USER user
|
| 28 |
+
|
| 29 |
+
# 5. Copy files and install Python requirements
|
| 30 |
+
COPY --chown=user . $HOME/app
|
| 31 |
RUN pip install --no-cache-dir --upgrade -r requirements.txt
|
| 32 |
|
| 33 |
+
# Expose port
|
| 34 |
EXPOSE 7860
|
| 35 |
|
| 36 |
+
# 6. Run the application
|
| 37 |
+
# Note: Using '&&' instead of '&' ensures the tunnel starts before the app,
|
| 38 |
+
# or use a shell script if you need them to run truly in parallel.
|
| 39 |
+
CMD cloudflared tunnel run --token $CLOUDFLARED_TOKEN & python app.py
|