Spaces:
				
			
			
	
			
			
		Build error
		
	
	
	
			
			
	
	
	
	
		
		
		Build error
		
	Update Dockerfile
Browse files- Dockerfile +100 -45
    	
        Dockerfile
    CHANGED
    
    | @@ -1,45 +1,63 @@ | |
| 1 | 
            -
            #  | 
| 2 | 
            -
             | 
|  | |
| 3 |  | 
| 4 | 
            -
             | 
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
| 5 |  | 
| 6 | 
            -
            # Copy frontend  | 
| 7 | 
            -
            COPY  | 
| 8 | 
            -
            RUN npm install -g [email protected] && npm ci
         | 
| 9 |  | 
| 10 | 
            -
            #  | 
| 11 | 
            -
            COPY ./frontend ./
         | 
| 12 | 
             
            RUN npm run build
         | 
| 13 |  | 
| 14 | 
            -
            #  | 
| 15 | 
            -
            FROM python:3.12. | 
| 16 |  | 
| 17 | 
             
            WORKDIR /app
         | 
| 18 | 
            -
            ENV PYTHONPATH='/app'
         | 
| 19 |  | 
| 20 | 
            -
            # Set Poetry environment variables | 
| 21 | 
             
            ENV POETRY_NO_INTERACTION=1 \
         | 
| 22 | 
             
                POETRY_VIRTUALENVS_IN_PROJECT=1 \
         | 
| 23 | 
             
                POETRY_VIRTUALENVS_CREATE=1 \
         | 
| 24 | 
             
                POETRY_CACHE_DIR=/tmp/poetry_cache
         | 
| 25 |  | 
| 26 | 
            -
            # Install system dependencies  | 
| 27 | 
            -
            RUN apt-get update -y  | 
| 28 | 
            -
                apt-get install -y  | 
| 29 | 
            -
             | 
|  | |
|  | |
|  | |
|  | |
| 30 |  | 
| 31 | 
            -
            #  | 
| 32 | 
            -
             | 
|  | |
|  | |
|  | |
| 33 | 
             
            RUN touch README.md
         | 
| 34 | 
            -
            RUN poetry install --without evaluation,llama-index --no-root && rm -rf $POETRY_CACHE_DIR
         | 
| 35 |  | 
| 36 | 
            -
            #  | 
| 37 | 
            -
             | 
|  | |
|  | |
|  | |
| 38 |  | 
| 39 | 
             
            WORKDIR /app
         | 
| 40 |  | 
| 41 | 
            -
            #  | 
| 42 | 
             
            ARG OPENHANDS_BUILD_VERSION=dev
         | 
|  | |
|  | |
| 43 | 
             
            ENV RUN_AS_OPENHANDS=true \
         | 
| 44 | 
             
                OPENHANDS_USER_ID=42420 \
         | 
| 45 | 
             
                SANDBOX_LOCAL_RUNTIME_URL=http://host.docker.internal \
         | 
| @@ -48,38 +66,75 @@ ENV RUN_AS_OPENHANDS=true \ | |
| 48 | 
             
                OPENHANDS_BUILD_VERSION=$OPENHANDS_BUILD_VERSION \
         | 
| 49 | 
             
                SANDBOX_USER_ID=0 \
         | 
| 50 | 
             
                FILE_STORE=local \
         | 
| 51 | 
            -
                FILE_STORE_PATH=/.openhands-state
         | 
|  | |
|  | |
|  | |
| 52 |  | 
| 53 | 
             
            # Create necessary directories
         | 
| 54 | 
             
            RUN mkdir -p $FILE_STORE_PATH $WORKSPACE_BASE
         | 
| 55 |  | 
| 56 | 
            -
            # Install runtime dependencies
         | 
| 57 | 
            -
            RUN apt-get update -y  | 
| 58 | 
            -
                apt-get install -y  | 
| 59 | 
            -
             | 
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
| 60 |  | 
| 61 | 
            -
            #  | 
| 62 | 
            -
             | 
| 63 | 
            -
                sed -i 's/^UID_MAX.*/UID_MAX 1000000/' /etc/login.defs
         | 
| 64 |  | 
| 65 | 
            -
            #  | 
| 66 | 
            -
             | 
| 67 | 
            -
                useradd -l -m -u $OPENHANDS_USER_ID -s /bin/bash openhands && \
         | 
| 68 | 
            -
                usermod -aG app openhands && \
         | 
| 69 | 
            -
                usermod -aG sudo openhands && \
         | 
| 70 | 
            -
                echo '%sudo ALL=(ALL) NOPASSWD:ALL' >> /etc/sudoers
         | 
| 71 |  | 
| 72 | 
            -
            #  | 
| 73 | 
            -
             | 
| 74 |  | 
| 75 | 
            -
            #  | 
| 76 | 
            -
             | 
| 77 |  | 
| 78 | 
            -
            #  | 
| 79 | 
            -
             | 
|  | |
| 80 |  | 
| 81 | 
            -
            # Expose  | 
| 82 | 
             
            EXPOSE 3000
         | 
| 83 |  | 
| 84 | 
            -
            #  | 
| 85 | 
            -
             | 
|  | 
|  | |
| 1 | 
            +
            # ===== MULTI-STAGE DOCKERFILE FOR OPENHANDS WEBAPP =====
         | 
| 2 | 
            +
            # This Dockerfile builds and runs the complete OpenHands application
         | 
| 3 | 
            +
            # including both the React frontend and Python FastAPI backend
         | 
| 4 |  | 
| 5 | 
            +
            # ===== FRONTEND BUILD STAGE =====
         | 
| 6 | 
            +
            FROM node:22.13.1-bookworm-slim AS frontend-builder
         | 
| 7 | 
            +
             | 
| 8 | 
            +
            WORKDIR /app/frontend
         | 
| 9 | 
            +
             | 
| 10 | 
            +
            # Copy package files first for better layer caching
         | 
| 11 | 
            +
            COPY frontend/package.json frontend/package-lock.json ./
         | 
| 12 | 
            +
             | 
| 13 | 
            +
            # Install frontend dependencies
         | 
| 14 | 
            +
            RUN npm ci --only=production
         | 
| 15 |  | 
| 16 | 
            +
            # Copy frontend source code
         | 
| 17 | 
            +
            COPY frontend/ ./
         | 
|  | |
| 18 |  | 
| 19 | 
            +
            # Build the React application
         | 
|  | |
| 20 | 
             
            RUN npm run build
         | 
| 21 |  | 
| 22 | 
            +
            # ===== BACKEND BUILD STAGE =====
         | 
| 23 | 
            +
            FROM python:3.12.8-slim AS backend-builder
         | 
| 24 |  | 
| 25 | 
             
            WORKDIR /app
         | 
|  | |
| 26 |  | 
| 27 | 
            +
            # Set Poetry environment variables
         | 
| 28 | 
             
            ENV POETRY_NO_INTERACTION=1 \
         | 
| 29 | 
             
                POETRY_VIRTUALENVS_IN_PROJECT=1 \
         | 
| 30 | 
             
                POETRY_VIRTUALENVS_CREATE=1 \
         | 
| 31 | 
             
                POETRY_CACHE_DIR=/tmp/poetry_cache
         | 
| 32 |  | 
| 33 | 
            +
            # Install system dependencies for building Python packages
         | 
| 34 | 
            +
            RUN apt-get update -y \
         | 
| 35 | 
            +
                && apt-get install -y --no-install-recommends \
         | 
| 36 | 
            +
                    curl \
         | 
| 37 | 
            +
                    make \
         | 
| 38 | 
            +
                    git \
         | 
| 39 | 
            +
                    build-essential \
         | 
| 40 | 
            +
                && rm -rf /var/lib/apt/lists/*
         | 
| 41 |  | 
| 42 | 
            +
            # Install Poetry
         | 
| 43 | 
            +
            RUN python3 -m pip install poetry==1.8.2 --break-system-packages
         | 
| 44 | 
            +
             | 
| 45 | 
            +
            # Copy Python dependency files first for better layer caching
         | 
| 46 | 
            +
            COPY pyproject.toml poetry.lock ./
         | 
| 47 | 
             
            RUN touch README.md
         | 
|  | |
| 48 |  | 
| 49 | 
            +
            # Install Python dependencies
         | 
| 50 | 
            +
            RUN poetry install --no-root --no-dev && rm -rf $POETRY_CACHE_DIR
         | 
| 51 | 
            +
             | 
| 52 | 
            +
            # ===== FINAL RUNTIME STAGE =====
         | 
| 53 | 
            +
            FROM python:3.12.8-slim AS runtime
         | 
| 54 |  | 
| 55 | 
             
            WORKDIR /app
         | 
| 56 |  | 
| 57 | 
            +
            # Build arguments
         | 
| 58 | 
             
            ARG OPENHANDS_BUILD_VERSION=dev
         | 
| 59 | 
            +
             | 
| 60 | 
            +
            # Environment variables for OpenHands
         | 
| 61 | 
             
            ENV RUN_AS_OPENHANDS=true \
         | 
| 62 | 
             
                OPENHANDS_USER_ID=42420 \
         | 
| 63 | 
             
                SANDBOX_LOCAL_RUNTIME_URL=http://host.docker.internal \
         | 
|  | |
| 66 | 
             
                OPENHANDS_BUILD_VERSION=$OPENHANDS_BUILD_VERSION \
         | 
| 67 | 
             
                SANDBOX_USER_ID=0 \
         | 
| 68 | 
             
                FILE_STORE=local \
         | 
| 69 | 
            +
                FILE_STORE_PATH=/.openhands-state \
         | 
| 70 | 
            +
                PYTHONPATH='/app' \
         | 
| 71 | 
            +
                VIRTUAL_ENV=/app/.venv \
         | 
| 72 | 
            +
                PATH="/app/.venv/bin:$PATH"
         | 
| 73 |  | 
| 74 | 
             
            # Create necessary directories
         | 
| 75 | 
             
            RUN mkdir -p $FILE_STORE_PATH $WORKSPACE_BASE
         | 
| 76 |  | 
| 77 | 
            +
            # Install runtime system dependencies
         | 
| 78 | 
            +
            RUN apt-get update -y \
         | 
| 79 | 
            +
                && apt-get install -y --no-install-recommends \
         | 
| 80 | 
            +
                    curl \
         | 
| 81 | 
            +
                    ssh \
         | 
| 82 | 
            +
                    sudo \
         | 
| 83 | 
            +
                    git \
         | 
| 84 | 
            +
                && rm -rf /var/lib/apt/lists/*
         | 
| 85 | 
            +
             | 
| 86 | 
            +
            # Configure user management for different UID ranges
         | 
| 87 | 
            +
            RUN sed -i 's/^UID_MIN.*/UID_MIN 499/' /etc/login.defs \
         | 
| 88 | 
            +
                && sed -i 's/^UID_MAX.*/UID_MAX 1000000/' /etc/login.defs
         | 
| 89 | 
            +
             | 
| 90 | 
            +
            # Create app group and openhands user
         | 
| 91 | 
            +
            RUN groupadd app \
         | 
| 92 | 
            +
                && useradd -l -m -u $OPENHANDS_USER_ID -s /bin/bash openhands \
         | 
| 93 | 
            +
                && usermod -aG app openhands \
         | 
| 94 | 
            +
                && usermod -aG sudo openhands \
         | 
| 95 | 
            +
                && echo '%sudo ALL=(ALL) NOPASSWD:ALL' >> /etc/sudoers
         | 
| 96 | 
            +
             | 
| 97 | 
            +
            # Set ownership and permissions
         | 
| 98 | 
            +
            RUN chown -R openhands:app /app && chmod -R 770 /app \
         | 
| 99 | 
            +
                && chown -R openhands:app $WORKSPACE_BASE && chmod -R 770 $WORKSPACE_BASE
         | 
| 100 | 
            +
             | 
| 101 | 
            +
            # Switch to openhands user for application setup
         | 
| 102 | 
            +
            USER openhands
         | 
| 103 | 
            +
             | 
| 104 | 
            +
            # Copy Python virtual environment from builder stage
         | 
| 105 | 
            +
            COPY --chown=openhands:app --chmod=770 --from=backend-builder /app/.venv /app/.venv
         | 
| 106 | 
            +
             | 
| 107 | 
            +
            # Copy Python application code
         | 
| 108 | 
            +
            COPY --chown=openhands:app --chmod=770 ./microagents ./microagents
         | 
| 109 | 
            +
            COPY --chown=openhands:app --chmod=770 ./openhands ./openhands
         | 
| 110 | 
            +
            COPY --chown=openhands:app --chmod=777 ./openhands/runtime/plugins ./openhands/runtime/plugins
         | 
| 111 | 
            +
            COPY --chown=openhands:app --chmod=770 ./openhands/agenthub ./openhands/agenthub
         | 
| 112 | 
            +
             | 
| 113 | 
            +
            # Copy configuration and metadata files
         | 
| 114 | 
            +
            COPY --chown=openhands:app ./pyproject.toml ./poetry.lock ./README.md ./MANIFEST.in ./LICENSE ./
         | 
| 115 | 
            +
             | 
| 116 | 
            +
            # Download assets (run as openhands user to set correct ownership)
         | 
| 117 | 
            +
            RUN python openhands/core/download.py
         | 
| 118 |  | 
| 119 | 
            +
            # Copy built frontend from frontend-builder stage
         | 
| 120 | 
            +
            COPY --chown=openhands:app --chmod=770 --from=frontend-builder /app/frontend/build ./frontend/build
         | 
|  | |
| 121 |  | 
| 122 | 
            +
            # Copy entrypoint script
         | 
| 123 | 
            +
            COPY --chown=openhands:app --chmod=770 ./containers/app/entrypoint.sh /app/entrypoint.sh
         | 
|  | |
|  | |
|  | |
|  | |
| 124 |  | 
| 125 | 
            +
            # Ensure all files are in the app group
         | 
| 126 | 
            +
            RUN find /app \! -group app -exec chgrp app {} + 2>/dev/null || true
         | 
| 127 |  | 
| 128 | 
            +
            # Switch back to root for entrypoint execution
         | 
| 129 | 
            +
            USER root
         | 
| 130 |  | 
| 131 | 
            +
            # Health check to ensure the application is running
         | 
| 132 | 
            +
            HEALTHCHECK --interval=30s --timeout=10s --start-period=60s --retries=3 \
         | 
| 133 | 
            +
                CMD curl -f http://localhost:3000/ || exit 1
         | 
| 134 |  | 
| 135 | 
            +
            # Expose the application port
         | 
| 136 | 
             
            EXPOSE 3000
         | 
| 137 |  | 
| 138 | 
            +
            # Set entrypoint and default command
         | 
| 139 | 
            +
            ENTRYPOINT ["/app/entrypoint.sh"]
         | 
| 140 | 
            +
            CMD ["uvicorn", "openhands.server.listen:app", "--host", "0.0.0.0", "--port", "3000"]
         |