duqing2026 commited on
Commit
acb846e
·
1 Parent(s): 9bac8d0

Optimize Dockerfile and add .dockerignore for Hugging Face Spaces

Browse files
Files changed (2) hide show
  1. .dockerignore +9 -0
  2. Dockerfile +12 -9
.dockerignore ADDED
@@ -0,0 +1,9 @@
 
 
 
 
 
 
 
 
 
 
1
+ .git
2
+ .gitignore
3
+ __pycache__
4
+ venv
5
+ .env
6
+ .DS_Store
7
+ *.pyc
8
+ *.pyo
9
+ *.pyd
Dockerfile CHANGED
@@ -16,19 +16,22 @@ ENV HOME=/home/user \
16
  # Set the working directory to the user's home directory
17
  WORKDIR $HOME/app
18
 
19
- # Copy the current directory contents into the container at $HOME/app setting the owner to the user
 
 
 
 
 
 
20
  COPY --chown=user . $HOME/app
21
 
22
  # Create the webfonts directory and download fonts
23
- # We do this here to avoid storing binary files in the git repo, but ensure they are available locally in the container.
24
  RUN mkdir -p static/webfonts && \
25
- curl -o static/webfonts/fa-solid-900.woff2 https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.0.0/webfonts/fa-solid-900.woff2 && \
26
- curl -o static/webfonts/fa-solid-900.ttf https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.0.0/webfonts/fa-solid-900.ttf && \
27
- curl -o static/webfonts/fa-regular-400.woff2 https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.0.0/webfonts/fa-regular-400.woff2 && \
28
- curl -o static/webfonts/fa-regular-400.ttf https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.0.0/webfonts/fa-regular-400.ttf
29
-
30
- # Install requirements
31
- RUN pip install --no-cache-dir --upgrade -r requirements.txt
32
 
33
  # Expose port 7860
34
  EXPOSE 7860
 
16
  # Set the working directory to the user's home directory
17
  WORKDIR $HOME/app
18
 
19
+ # Copy requirements.txt first to leverage Docker cache
20
+ COPY --chown=user requirements.txt $HOME/app/requirements.txt
21
+
22
+ # Install requirements
23
+ RUN pip install --no-cache-dir --upgrade -r requirements.txt
24
+
25
+ # Copy the rest of the application
26
  COPY --chown=user . $HOME/app
27
 
28
  # Create the webfonts directory and download fonts
29
+ # Use -f to fail on error, -L to follow redirects
30
  RUN mkdir -p static/webfonts && \
31
+ curl -fLo static/webfonts/fa-solid-900.woff2 https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.0.0/webfonts/fa-solid-900.woff2 && \
32
+ curl -fLo static/webfonts/fa-solid-900.ttf https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.0.0/webfonts/fa-solid-900.ttf && \
33
+ curl -fLo static/webfonts/fa-regular-400.woff2 https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.0.0/webfonts/fa-regular-400.woff2 && \
34
+ curl -fLo static/webfonts/fa-regular-400.ttf https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.0.0/webfonts/fa-regular-400.ttf
 
 
 
35
 
36
  # Expose port 7860
37
  EXPOSE 7860