File size: 1,907 Bytes
841615f
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# Use the exact same base image from the log
FROM docker.io/nvidia/cuda:12.3.2-cudnn9-devel-ubuntu22.04@sha256:fb1ad20f2552f5b3aafb2c9c478ed57da95e2bb027d15218d7a55b3a0e4b4413

# Set environment variables for non-interactive installation
ENV DEBIAN_FRONTEND=noninteractive
ENV TZ=UTC

# Install system dependencies including Python and pip
RUN apt-get update && apt-get install -y \
	python3 python3-pip python3-dev \
	&& rm -rf /var/lib/apt/lists/* 

# Setup fakeroot and user 
RUN apt-get update && apt-get install -y fakeroot && \
    mv /usr/bin/apt-get /usr/bin/.apt-get && \
    echo '#!/usr/bin/env sh\nfakeroot /usr/bin/.apt-get $@' > /usr/bin/apt-get && \
    chmod +x /usr/bin/apt-get && \
	rm -rf /var/lib/apt/lists/* && \
	useradd -m -u 1000 user

# Set working directory
WORKDIR /home/user/app

# Copy requirements.txt and install Python dependencies
COPY requirements.txt /tmp/requirements.txt
RUN pip install --no-cache-dir -r /tmp/requirements.txt

# Install additional packages
RUN pip install --no-cache-dir spaces

# Install huggingface_hub 
RUN pip install --no-cache-dir huggingface_hub

# Set HF_TOKEN from secret and make it available as environment variable
RUN --mount=type=secret,id=HF_TOKEN,mode=0444,required=true \
    echo "export HF_TOKEN=$(cat /run/secrets/HF_TOKEN)" > /etc/hf_env && \
    chmod +x /etc/hf_env

# Create a startup script that sources the environment and runs the app
RUN echo '#!/bin/bash\nsource /etc/hf_env\nexec "$@"' > /usr/local/bin/entrypoint.sh && \
    chmod +x /usr/local/bin/entrypoint.sh

# Copy only specific project files
COPY --chown=1000:1000 app.py /home/user/app/
COPY --chown=1000:1000 pipeline_difix.py /home/user/app/
COPY --chown=1000:1000 assets/ /home/user/app/assets/

# Switch to user
USER user

# Expose port for Gradio
EXPOSE 7860

# Use the entrypoint script
ENTRYPOINT ["/usr/local/bin/entrypoint.sh"]
CMD ["python3", "app.py"]