Spaces:
Running
Running
File size: 3,576 Bytes
f35f8c5 466436b fa72e90 958f00f 26001bb 466436b c4a0a71 006b994 1f609d0 c4a0a71 172c3de b92158e 172c3de c4a0a71 fa72e90 c4a0a71 fa72e90 c4a0a71 fa72e90 c4a0a71 466436b 654dfbb 1f609d0 466436b c4a0a71 |
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 |
FROM node:20-slim
ENV DEBIAN_FRONTEND=noninteractive
# Build timestamp: 2026-01-27T22:56
# Note: ONNX files kept in LFS per HF policy, downloaded at startup via curl
WORKDIR /app
# Install curl for downloading LFS files at startup
RUN apt-get update && apt-get install -y curl ca-certificates && rm -rf /var/lib/apt/lists/*
# Copy backend package.json and install ALL deps (including dev for tsx)
COPY trigo-web/backend/package.json ./package.json
RUN npm install
# Copy backend source
COPY trigo-web/backend/src/ ./backend/src/
# Copy inc folder
COPY trigo-web/inc/ ./inc/
# Copy frontend dist (ONNX files will be LFS pointers, we'll download them at startup)
COPY trigo-web/app/dist/ ./app/dist/
# Copy env files (only .env, .env.local is for local development only)
COPY trigo-web/backend/.env ./backend/.env
# Create a Docker-specific entry point that sets correct paths
RUN echo 'import express from "express"; \
import { createServer } from "http"; \
import { Server } from "socket.io"; \
import cors from "cors"; \
import { GameManager } from "./backend/src/services/gameManager"; \
import { setupSocketHandlers } from "./backend/src/sockets/gameSocket"; \
const app = express(); \
const httpServer = createServer(app); \
const io = new Server(httpServer, { cors: { origin: true, methods: ["GET", "POST"], credentials: true } }); \
const gameManager = new GameManager(); \
const PORT = parseInt(process.env.PORT || "7860", 10); \
app.use(cors()); \
app.use(express.json()); \
app.use(express.static("app/dist")); \
app.get("/health", (req, res) => res.json({status: "ok", timestamp: new Date().toISOString()})); \
app.get("*", (req, res, next) => { if (req.path.startsWith("/health") || req.path.startsWith("/socket.io")) return next(); if (/\\.[a-zA-Z0-9]+$/.test(req.path)) return next(); res.sendFile("app/dist/index.html", {root: "/app"}); }); \
io.on("connection", (socket) => { console.log("Client connected:", socket.id); setupSocketHandlers(io, socket, gameManager); socket.on("disconnect", () => console.log("Client disconnected:", socket.id)); }); \
httpServer.listen(PORT, "0.0.0.0", () => console.log("Server running on port " + PORT));' > docker-entry.ts
# Create startup script that downloads LFS files before starting server
RUN cat <<'STARTUP' > start.sh
#!/bin/bash
set -e
echo "=== Container startup at $(date) ==="
echo "Working directory: $(pwd)"
echo "Node version: $(node --version)"
HF_BASE="https://huggingface.co/spaces/k-l-lambda/trigo/resolve/main/trigo-web/app/dist"
# List of ONNX files to download (relative to app/dist)
ONNX_FILES=(
"onnx/20251230-trigo-value-llama-l6-h64-it2_251221-value0.01-pretrain/LlamaCausalLM_ep0036_evaluation.onnx"
"onnx/20251230-trigo-value-llama-l6-h64-it2_251221-value0.01-pretrain/LlamaCausalLM_ep0036_tree.onnx"
)
echo "Downloading ONNX model files..."
for file in "${ONNX_FILES[@]}"; do
dir=$(dirname "app/dist/$file")
mkdir -p "$dir"
echo " Downloading $file..."
if curl -fsSL "$HF_BASE/$file" -o "app/dist/$file"; then
size=$(stat -c%s "app/dist/$file" 2>/dev/null || echo "unknown")
echo " Downloaded: $size bytes"
else
echo " WARNING: Failed to download $file"
fi
done
echo "=== Checking downloaded files ==="
ls -la app/dist/onnx/20251230-trigo-value-llama-l6-h64-it2_251221-value0.01-pretrain/ 2>/dev/null || echo "ONNX directory not found"
echo "=== Starting server ==="
exec npx tsx docker-entry.ts
STARTUP
RUN chmod +x start.sh
ENV PORT=7860
ENV HOST=0.0.0.0
ENV NODE_ENV=production
EXPOSE 7860
CMD ["./start.sh"]
|