LeRobot-Arena / Dockerfile
blanchon's picture
Fix HF Spaces
de6f5a0
raw
history blame
2.1 kB
# Multi-stage Dockerfile for LeRobot Arena
# Stage 1: Build Svelte frontend with Bun
FROM oven/bun:1-alpine AS frontend-builder
WORKDIR /app
# Install git for dependencies that might need it
RUN apk add --no-cache git
# Copy package files
COPY package.json bun.lockb* ./
# Install dependencies with bun
RUN bun install
# Copy source code
COPY . .
# Build the Svelte app
RUN bun run build
# Stage 2: Python backend with official uv image
FROM ghcr.io/astral-sh/uv:python3.12-bookworm-slim
# Set up a new user named "user" with user ID 1000 (required for HF Spaces)
RUN useradd -m -u 1000 user
# Switch to the "user" user
USER user
# Set home to the user's home directory
ENV HOME=/home/user \
PATH=/home/user/.local/bin:$PATH
# Set the working directory to the user's home directory
WORKDIR $HOME/app
# Copy Python project files for dependency resolution
COPY --chown=user src-python/pyproject.toml src-python/uv.lock ./src-python/
# Install dependencies first (better caching)
WORKDIR $HOME/app/src-python
RUN uv sync --no-install-project
# Copy the rest of the Python backend
COPY --chown=user src-python/ ./
# Install the project itself
RUN uv sync
# Copy built frontend from previous stage with proper ownership
COPY --chown=user --from=frontend-builder /app/build $HOME/app/static-frontend
# Create a startup script that runs both services
WORKDIR $HOME/app
RUN echo '#!/bin/bash\n\
echo "Starting LeRobot Arena services..."\n\
echo "πŸš€ Starting Python backend on port 8080..."\n\
cd $HOME/app/src-python && uv run python start_server.py &\n\
echo "🌐 Starting static file server on port 7860..."\n\
cd $HOME/app/static-frontend && python -m http.server 7860 --bind 0.0.0.0 &\n\
echo "βœ… Both services started!"\n\
echo "Backend: http://localhost:8080"\n\
echo "Frontend: http://localhost:7860"\n\
if [ ! -z "$SPACE_HOST" ]; then\n\
echo "🌐 Hugging Face Space: https://$SPACE_HOST"\n\
fi\n\
wait' > start_services.sh && chmod +x start_services.sh
# Expose both ports (7860 is default for HF Spaces)
EXPOSE 7860 8080
# Start both services
CMD ["./start_services.sh"]