Spaces:
Running
Running
DeFactOfficial
commited on
Commit
•
db88c10
1
Parent(s):
fba77c8
Try new claude-generated docukerfile :P
Browse files- Dockerfile +121 -15
Dockerfile
CHANGED
@@ -1,28 +1,134 @@
|
|
1 |
-
#
|
2 |
-
FROM
|
3 |
-
|
4 |
-
# Switch to the "node" user
|
5 |
-
USER node
|
6 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
7 |
# Set home to the user's home directory
|
8 |
-
ENV HOME=/home/
|
9 |
-
PATH=/home/
|
10 |
-
STATIC_SITE_ROOT=$HOME/
|
11 |
|
12 |
-
#
|
13 |
-
|
|
|
|
|
|
|
14 |
|
15 |
-
#
|
16 |
-
|
17 |
|
|
|
|
|
18 |
# Copy the current directory contents into the container at $HOME/app setting the owner to the user
|
19 |
-
|
|
|
20 |
|
|
|
|
|
|
|
21 |
# Loading Dependencies
|
22 |
RUN npm install
|
23 |
-
RUN $HOME/
|
24 |
# Expose application's default port
|
25 |
EXPOSE 7860
|
26 |
|
27 |
-
#
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
28 |
ENTRYPOINT ["nodejs", "./api.js"]
|
|
|
1 |
+
# Use HF's recommended base image
|
2 |
+
FROM huggingface/docker-build:latest
|
|
|
|
|
|
|
3 |
|
4 |
+
# Install system packages (using apt-get since we're still in a Debian-based environment)
|
5 |
+
USER root
|
6 |
+
RUN apt-get update && apt-get install -y \
|
7 |
+
nginx \
|
8 |
+
curl \
|
9 |
+
wget \
|
10 |
+
git \
|
11 |
+
net-tools \
|
12 |
+
python3 \
|
13 |
+
python3-pip \
|
14 |
+
&& apt-get clean \
|
15 |
+
&& rm -rf /var/lib/apt/lists/*
|
16 |
+
|
17 |
# Set home to the user's home directory
|
18 |
+
ENV HOME=/home/root \
|
19 |
+
PATH=/home/root/.local/bin:$PATH \
|
20 |
+
STATIC_SITE_ROOT=$HOME/code/public
|
21 |
|
22 |
+
# Install Node.js 20 (using n instead of nodesource for better HF compatibility)
|
23 |
+
RUN curl -L https://raw.githubusercontent.com/tj/n/master/bin/n -o n \
|
24 |
+
&& bash n 20 \
|
25 |
+
&& rm n \
|
26 |
+
&& npm install -g npm@latest
|
27 |
|
28 |
+
# Create working directory that matches HF Spaces expectations
|
29 |
+
WORKDIR $HOME/code
|
30 |
|
31 |
+
# Clone your repository (replace with your actual repo URL)
|
32 |
+
#RUN git clone https://your-repo-url.git .
|
33 |
# Copy the current directory contents into the container at $HOME/app setting the owner to the user
|
34 |
+
ADD . $HOME/code
|
35 |
+
COPY --chown=root . $HOME/code
|
36 |
|
37 |
+
# INSTALL NPM PACKAGES
|
38 |
+
# INSTALL FFMPEG TOOLING
|
39 |
+
# FIRE UP API
|
40 |
# Loading Dependencies
|
41 |
RUN npm install
|
42 |
+
RUN $HOME/code/ffmpeg_install.sh
|
43 |
# Expose application's default port
|
44 |
EXPOSE 7860
|
45 |
|
46 |
+
# Configure nginx
|
47 |
+
RUN rm -f /etc/nginx/sites-enabled/default
|
48 |
+
COPY <<-'EOF' /etc/nginx/sites-available/reverse-proxy.conf
|
49 |
+
server {
|
50 |
+
listen 7860;
|
51 |
+
server_name localhost;
|
52 |
+
|
53 |
+
# Specific to HF Spaces: Allow larger headers for their proxy setup
|
54 |
+
large_client_header_buffers 4 32k;
|
55 |
+
|
56 |
+
proxy_connect_timeout 600;
|
57 |
+
proxy_send_timeout 600;
|
58 |
+
proxy_read_timeout 600;
|
59 |
+
send_timeout 600;
|
60 |
+
|
61 |
+
# Additional headers specific to running behind HF Spaces proxy
|
62 |
+
proxy_set_header Host $host;
|
63 |
+
proxy_set_header X-Real-IP $remote_addr;
|
64 |
+
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
65 |
+
proxy_set_header X-Forwarded-Proto $scheme;
|
66 |
+
proxy_set_header X-Forwarded-Host $host;
|
67 |
+
|
68 |
+
client_max_body_size 50M;
|
69 |
+
|
70 |
+
# the node.js api runs on localhost:6666
|
71 |
+
# here we tell nginx that requests to /API should forward there
|
72 |
+
location /API/ {
|
73 |
+
#rewrite ^/API/images/(.*) /$1 break;
|
74 |
+
proxy_pass http://localhost:6666;
|
75 |
+
proxy_buffering on;
|
76 |
+
proxy_buffer_size 128k;
|
77 |
+
proxy_buffers 4 256k;
|
78 |
+
proxy_busy_buffers_size 256k;
|
79 |
+
}
|
80 |
+
|
81 |
+
#location /API/tts/ {
|
82 |
+
# rewrite ^/API/tts/(.*) /$1 break;
|
83 |
+
# proxy_pass http://localhost:5555;
|
84 |
+
# proxy_http_version 1.1;
|
85 |
+
# proxy_set_header Upgrade $http_upgrade;
|
86 |
+
# proxy_set_header Connection "upgrade";
|
87 |
+
#}
|
88 |
+
|
89 |
+
# Required for HF Spaces health checks
|
90 |
+
location / {
|
91 |
+
return 200 'OK';
|
92 |
+
add_header Content-Type text/plain;
|
93 |
+
}
|
94 |
+
}
|
95 |
+
EOF
|
96 |
+
|
97 |
+
RUN ln -s /etc/nginx/sites-available/reverse-proxy.conf /etc/nginx/sites-enabled/
|
98 |
+
|
99 |
+
# Create startup script with HF Spaces specific considerations
|
100 |
+
COPY <<-'EOF' $HOME/code/start.sh
|
101 |
+
#!/bin/bash
|
102 |
+
|
103 |
+
# Print environment info for debugging
|
104 |
+
echo "Container Environment:"
|
105 |
+
echo "====================="
|
106 |
+
env | grep -i HF_ || true
|
107 |
+
echo "====================="
|
108 |
+
|
109 |
+
#cd $HOME/code && node api.js
|
110 |
+
|
111 |
+
# Start all services in background with logging
|
112 |
+
#cd /code/service1 && ./run.sh > /var/log/service1.log 2>&1 &
|
113 |
+
#cd /code/service2 && ./run.sh > /var/log/service2.log 2>&1 &
|
114 |
+
#cd /code/service3 && ./run.sh > /var/log/service3.log 2>&1 &
|
115 |
+
|
116 |
+
# Wait for services to start
|
117 |
+
sleep 5
|
118 |
+
|
119 |
+
# Check service status
|
120 |
+
echo "Running services:"
|
121 |
+
netstat -tulpn
|
122 |
+
|
123 |
+
# Tail the logs in background
|
124 |
+
tail -f /var/log/*.log &
|
125 |
+
|
126 |
+
# Start nginx in foreground
|
127 |
+
nginx -g 'daemon off;'
|
128 |
+
EOF
|
129 |
+
|
130 |
+
#RUN chmod +x $/code/start.sh
|
131 |
+
|
132 |
+
# Start everything
|
133 |
+
#CMD ["/code/start.sh"]
|
134 |
ENTRYPOINT ["nodejs", "./api.js"]
|