Debdeep123/capability_forge_codeops
0
1# Copyright (c) Meta Platforms, Inc. and affiliates.2# All rights reserved.3#4# This source code is licensed under the BSD-style license found in the5# LICENSE file in the root directory of this source tree.6 7# Multi-stage build using openenv-base8# This Dockerfile is flexible and works for both:9# - In-repo environments (with local OpenEnv sources)10# - Standalone environments (with openenv from PyPI/Git)11# The build script (openenv build) handles context detection and sets appropriate build args.12 13ARG BASE_IMAGE=ghcr.io/meta-pytorch/openenv-base:latest14FROM ${BASE_IMAGE} AS builder15 16WORKDIR /app17 18# Ensure git is available (required for installing dependencies from VCS)19RUN apt-get update && \20 apt-get install -y --no-install-recommends git && \21 rm -rf /var/lib/apt/lists/*22 23# Build argument to control whether we're building standalone or in-repo24ARG BUILD_MODE=in-repo25ARG ENV_NAME=capability_forge_codeops26 27# Copy environment code (always at root of build context)28COPY . /app/env29 30# For in-repo builds, openenv is already vendored in the build context31# For standalone builds, openenv will be installed via pyproject.toml32WORKDIR /app/env33 34# Ensure uv is available (for local builds where base image lacks it)35RUN if ! command -v uv >/dev/null 2>&1; then \36 curl -LsSf https://astral.sh/uv/install.sh | sh && \37 mv /root/.local/bin/uv /usr/local/bin/uv && \38 mv /root/.local/bin/uvx /usr/local/bin/uvx; \39 fi40 41# Install dependencies using uv sync42# If uv.lock exists, use it; otherwise resolve on the fly43RUN --mount=type=cache,target=/root/.cache/uv \44 if [ -f uv.lock ]; then \45 uv sync --frozen --no-install-project --no-editable; \46 else \47 uv sync --no-install-project --no-editable; \48 fi49 50RUN --mount=type=cache,target=/root/.cache/uv \51 if [ -f uv.lock ]; then \52 uv sync --frozen --no-editable; \53 else \54 uv sync --no-editable; \55 fi56 57# Final runtime stage58FROM ${BASE_IMAGE}59 60WORKDIR /app61 62# Copy the virtual environment from builder63COPY --from=builder /app/env/.venv /app/.venv64 65# Copy the environment code66COPY --from=builder /app/env /app/env67 68# Set PATH to use the virtual environment69ENV PATH="/app/.venv/bin:$PATH"70 71# Set PYTHONPATH so imports work correctly72ENV PYTHONPATH="/app/env:$PYTHONPATH"73 74# Health check75HEALTHCHECK --interval=30s --timeout=3s --start-period=5s --retries=3 \76 CMD curl -f http://localhost:8000/health || exit 177 78# Run the FastAPI server79# The module path is constructed to work with the /app/env structure80ENV ENABLE_WEB_INTERFACE=true81CMD ["sh", "-c", "cd /app/env && uvicorn server.app:app --host 0.0.0.0 --port 8000"]82 