Spaces:
Running
Running
File size: 3,670 Bytes
db88c10 a830538 db88c10 a830538 db88c10 a830538 db88c10 a830538 db88c10 a830538 db88c10 a830538 db88c10 a830538 db88c10 a830538 db88c10 a830538 db88c10 a830538 |
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 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 |
# 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"] |