Download Dockerfile from Spocklet/cobalt: direct link, hf CLI and curl.
- Browser
- Download file 4.03 kB
-
https://huggingface.co/spaces/Spocklet/cobalt/resolve/main/Dockerfile
- Command line
-
hf download hf://spaces/Spocklet/cobalt/Dockerfile
-
curl -L -o Dockerfile https://huggingface.co/spaces/Spocklet/cobalt/resolve/main/Dockerfile
4.03 kB
| # ========================================== | |
| # Stage 1: Builder | |
| # ========================================== | |
| FROM node:22-alpine AS builder | |
| # Install build dependencies | |
| RUN apk add --no-cache git python3 make g++ | |
| WORKDIR /app | |
| # Clone the repository | |
| RUN git clone --depth 1 https://github.com/imputnet/cobalt.git . | |
| # Install pnpm and dependencies | |
| RUN npm install -g pnpm | |
| RUN pnpm install | |
| # --- BUILD CONFIGURATION --- | |
| # The Web UI needs to know the API path during build time | |
| ENV WEB_DEFAULT_API=/api/ | |
| ENV VITE_API_URL=/api/ | |
| ENV VITE_Kobold_API_URL=/api/ | |
| # Run svelte-kit sync to fix build errors, then build everything | |
| RUN pnpm -r exec svelte-kit sync || true | |
| RUN pnpm -r build | |
| # ========================================== | |
| # Stage 2: Runner (Production) | |
| # ========================================== | |
| FROM node:22-alpine | |
| # 1. Install System Dependencies | |
| # - nginx: Reverse proxy | |
| # - ffmpeg: Media processing | |
| # - python3/pip: For yt-dlp | |
| # - netcat-openbsd: To check if ports are ready (fix for 502 error) | |
| RUN apk update && \ | |
| apk add --no-cache nginx ffmpeg python3 py3-pip curl netcat-openbsd && \ | |
| rm -rf /var/cache/apk/* | |
| # 2. Install yt-dlp | |
| RUN pip3 install yt-dlp --break-system-packages | |
| # 3. Setup Working Directory | |
| WORKDIR /app | |
| # 4. Install pnpm | |
| RUN npm install -g pnpm | |
| # 5. Copy built files from Builder | |
| COPY --from=builder /app /app | |
| # 6. Configure Nginx | |
| # - Proxy /api/ to localhost:9000 | |
| # - Proxy / to localhost:9001 | |
| RUN echo 'server { \ | |
| listen 7860; \ | |
| client_max_body_size 100M; \ | |
| \ | |
| location /api/ { \ | |
| rewrite ^/api/(.*) /$1 break; \ | |
| proxy_pass http://127.0.0.1:9000; \ | |
| proxy_http_version 1.1; \ | |
| proxy_set_header Upgrade $http_upgrade; \ | |
| proxy_set_header Connection "upgrade"; \ | |
| proxy_set_header Host $host; \ | |
| proxy_set_header X-Real-IP $remote_addr; \ | |
| proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; \ | |
| } \ | |
| \ | |
| location / { \ | |
| proxy_pass http://127.0.0.1:9001; \ | |
| proxy_http_version 1.1; \ | |
| proxy_set_header Upgrade $http_upgrade; \ | |
| proxy_set_header Connection "upgrade"; \ | |
| proxy_set_header Host $host; \ | |
| } \ | |
| }' > /etc/nginx/http.d/default.conf | |
| # 7. Create Startup Script (Robust Version) | |
| # This script waits for the apps to fully load before starting Nginx. | |
| RUN echo '#!/bin/sh' > /start.sh && \ | |
| # --- 1. Set Environment Variables --- \ | |
| echo 'export API_PORT=9000' >> /start.sh && \ | |
| echo 'export API_LISTEN_ADDRESS=0.0.0.0' >> /start.sh && \ | |
| echo 'export PORT=9001' >> /start.sh && \ | |
| echo 'export API_URL=http://localhost:7860/api' >> /start.sh && \ | |
| echo 'export WEB_URL=http://localhost:7860' >> /start.sh && \ | |
| echo 'export WEB_DEFAULT_API=/api/' >> /start.sh && \ | |
| \ | |
| # --- 2. Start Backend (API) --- \ | |
| echo 'echo "Starting Cobalt API..."' >> /start.sh && \ | |
| echo 'cd /app/apps/api && node dist/index.js > /app/api.log 2>&1 &' >> /start.sh && \ | |
| \ | |
| # --- 3. Start Frontend (Web) --- \ | |
| echo 'echo "Starting Cobalt Web..."' >> /start.sh && \ | |
| echo 'cd /app/apps/web && node build/index.js > /app/web.log 2>&1 &' >> /start.sh && \ | |
| \ | |
| # --- 4. Wait for Services to be Ready (Fixes 502) --- \ | |
| echo 'echo "Waiting for backend to launch on 9000..."' >> /start.sh && \ | |
| echo 'while ! nc -z 127.0.0.1 9000; do sleep 1; done' >> /start.sh && \ | |
| echo 'echo "Backend is ready!"' >> /start.sh && \ | |
| \ | |
| echo 'echo "Waiting for frontend to launch on 9001..."' >> /start.sh && \ | |
| echo 'while ! nc -z 127.0.0.1 9001; do sleep 1; done' >> /start.sh && \ | |
| echo 'echo "Frontend is ready!"' >> /start.sh && \ | |
| \ | |
| # --- 5. Start Nginx --- \ | |
| echo 'echo "Starting Nginx..."' >> /start.sh && \ | |
| echo 'nginx' >> /start.sh && \ | |
| \ | |
| # --- 6. Tail Logs (Keep container running and show errors) --- \ | |
| echo 'tail -f /app/api.log /app/web.log' >> /start.sh && \ | |
| chmod +x /start.sh | |
| # 8. Expose Ports | |
| EXPOSE 7860 | |
| EXPOSE 7871 | |
| # 9. Run | |
| CMD ["/start.sh"] |