Spaces:
Running
Running
# Use HF's recommended base image | |
FROM huggingface/docker-build:latest | |
# Install system packages (using apt-get since we're still in a Debian-based environment) | |
USER root | |
RUN apt-get update && apt-get install -y \ | |
nginx \ | |
curl \ | |
wget \ | |
git \ | |
net-tools \ | |
python3 \ | |
python3-pip \ | |
&& apt-get clean \ | |
&& rm -rf /var/lib/apt/lists/* | |
# Set home to the user's home directory | |
ENV HOME=/home/root \ | |
PATH=/home/root/.local/bin:$PATH \ | |
STATIC_SITE_ROOT=$HOME/code/public | |
# Install Node.js 20 (using n instead of nodesource for better HF compatibility) | |
RUN curl -L https://raw.githubusercontent.com/tj/n/master/bin/n -o n \ | |
&& bash n 20 \ | |
&& rm n \ | |
&& npm install -g npm@latest | |
# Create working directory that matches HF Spaces expectations | |
WORKDIR $HOME/code | |
# Clone your repository (replace with your actual repo URL) | |
#RUN git clone https://your-repo-url.git . | |
# Copy the current directory contents into the container at $HOME/app setting the owner to the user | |
ADD . $HOME/code | |
COPY --chown=root . $HOME/code | |
# INSTALL NPM PACKAGES | |
# INSTALL FFMPEG TOOLING | |
# FIRE UP API | |
# Loading Dependencies | |
RUN npm install | |
RUN $HOME/code/ffmpeg_install.sh | |
# Expose application's default port | |
EXPOSE 7860 | |
# Configure nginx | |
RUN rm -f /etc/nginx/sites-enabled/default | |
COPY <<-'EOF' /etc/nginx/sites-available/reverse-proxy.conf | |
server { | |
listen 7860; | |
server_name localhost; | |
# Specific to HF Spaces: Allow larger headers for their proxy setup | |
large_client_header_buffers 4 32k; | |
proxy_connect_timeout 600; | |
proxy_send_timeout 600; | |
proxy_read_timeout 600; | |
send_timeout 600; | |
# Additional headers specific to running behind HF Spaces proxy | |
proxy_set_header Host $host; | |
proxy_set_header X-Real-IP $remote_addr; | |
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; | |
proxy_set_header X-Forwarded-Proto $scheme; | |
proxy_set_header X-Forwarded-Host $host; | |
client_max_body_size 50M; | |
# the node.js api runs on localhost:6666 | |
# here we tell nginx that requests to /API should forward there | |
location /API/ { | |
#rewrite ^/API/images/(.*) /$1 break; | |
proxy_pass http://localhost:6666; | |
proxy_buffering on; | |
proxy_buffer_size 128k; | |
proxy_buffers 4 256k; | |
proxy_busy_buffers_size 256k; | |
} | |
#location /API/tts/ { | |
# rewrite ^/API/tts/(.*) /$1 break; | |
# proxy_pass http://localhost:5555; | |
# proxy_http_version 1.1; | |
# proxy_set_header Upgrade $http_upgrade; | |
# proxy_set_header Connection "upgrade"; | |
#} | |
# Required for HF Spaces health checks | |
location / { | |
return 200 'OK'; | |
add_header Content-Type text/plain; | |
} | |
} | |
EOF | |
RUN ln -s /etc/nginx/sites-available/reverse-proxy.conf /etc/nginx/sites-enabled/ | |
# Create startup script with HF Spaces specific considerations | |
COPY <<-'EOF' $HOME/code/start.sh | |
#!/bin/bash | |
# Print environment info for debugging | |
echo "Container Environment:" | |
echo "=====================" | |
env | grep -i HF_ || true | |
echo "=====================" | |
#cd $HOME/code && node api.js | |
# Start all services in background with logging | |
#cd /code/service1 && ./run.sh > /var/log/service1.log 2>&1 & | |
#cd /code/service2 && ./run.sh > /var/log/service2.log 2>&1 & | |
#cd /code/service3 && ./run.sh > /var/log/service3.log 2>&1 & | |
# Wait for services to start | |
sleep 5 | |
# Check service status | |
echo "Running services:" | |
netstat -tulpn | |
# Tail the logs in background | |
tail -f /var/log/*.log & | |
# Start nginx in foreground | |
nginx -g 'daemon off;' | |
EOF | |
#RUN chmod +x $/code/start.sh | |
# Start everything | |
#CMD ["/code/start.sh"] | |
ENTRYPOINT ["nodejs", "./api.js"] |