Spaces:
Build error
Build error
# Stage 1: Build the frontend (Node.js) | |
FROM node:21.7.2-bookworm-slim AS frontend-builder | |
WORKDIR /app | |
# Copy frontend package files and install dependencies | |
COPY ./frontend/package.json ./frontend/package-lock.json ./ | |
RUN npm install -g [email protected] && npm ci | |
# Copy frontend source code and build | |
COPY ./frontend ./ | |
RUN npm run build | |
# Stage 2: Build the backend dependencies (Python) | |
FROM python:3.12.3-slim AS backend-builder | |
WORKDIR /app | |
ENV PYTHONPATH='/app' | |
# Set Poetry environment variables for dependency management | |
ENV POETRY_NO_INTERACTION=1 \ | |
POETRY_VIRTUALENVS_IN_PROJECT=1 \ | |
POETRY_VIRTUALENVS_CREATE=1 \ | |
POETRY_CACHE_DIR=/tmp/poetry_cache | |
# Install system dependencies and Poetry | |
RUN apt-get update -y && \ | |
apt-get install -y curl make git build-essential && \ | |
python3 -m pip install poetry==1.8.2 --break-system-packages | |
# Copy Poetry files and install dependencies | |
COPY ./pyproject.toml ./poetry.lock ./ | |
RUN touch README.md | |
RUN poetry install --without evaluation,llama-index --no-root && rm -rf $POETRY_CACHE_DIR | |
# Stage 3: Final runtime image | |
FROM python:3.12.3-slim AS openhands-app | |
WORKDIR /app | |
# Define build argument and environment variables | |
ARG OPENHANDS_BUILD_VERSION=dev | |
ENV RUN_AS_OPENHANDS=true \ | |
OPENHANDS_USER_ID=42420 \ | |
SANDBOX_LOCAL_RUNTIME_URL=http://host.docker.internal \ | |
USE_HOST_NETWORK=false \ | |
WORKSPACE_BASE=/opt/workspace_base \ | |
OPENHANDS_BUILD_VERSION=$OPENHANDS_BUILD_VERSION \ | |
SANDBOX_USER_ID=0 \ | |
FILE_STORE=local \ | |
FILE_STORE_PATH=/.openhands-state | |
# Create necessary directories | |
RUN mkdir -p $FILE_STORE_PATH $WORKSPACE_BASE | |
# Install runtime dependencies | |
RUN apt-get update -y && \ | |
apt-get install -y curl ssh sudo && \ | |
apt-get clean | |
# Adjust UID range in login.defs to avoid conflicts | |
RUN sed -i 's/^UID_MIN.*/UID_MIN 499/' /etc/login.defs && \ | |
sed -i 's/^UID_MAX.*/UID_MAX 1000000/' /etc/login.defs | |
# Create user and group for OpenHands | |
RUN groupadd app && \ | |
useradd -l -m -u $OPENHANDS_USER_ID -s /bin/bash openhands && \ | |
usermod -aG app openhands && \ | |
usermod -aG sudo openhands && \ | |
echo '%sudo ALL=(ALL) NOPASSWD:ALL' >> /etc/sudoers | |
# Copy backend dependencies from backend-builder | |
COPY --from=backend-builder /app/.venv ./.venv | |
# Copy frontend build artifacts from frontend-builder | |
COPY --from=frontend-builder /app/dist ./frontend/dist | |
# Copy the rest of the application code | |
COPY . . | |
# Expose port for the application | |
EXPOSE 3000 | |
# Command to run the application | |
CMD ["./.venv/bin/python", "-m", "openhands.server.listen"] |