razak123/code-migration-env
0
1# code_migration_env\server\Dockerfile2# Copyright (c) Meta Platforms, Inc. and affiliates.3# All rights reserved.4#5# This source code is licensed under the BSD-style license found in the6# LICENSE file in the root directory of this source tree.7 8# Multi-stage build using openenv-base9# This Dockerfile is flexible and works for both:10# - In-repo environments (with local OpenEnv sources)11# - Standalone environments (with openenv from PyPI/Git)12# The build script (openenv build) handles context detection and sets appropriate build args.13 14ARG BASE_IMAGE=ghcr.io/meta-pytorch/openenv-base:latest15FROM ${BASE_IMAGE} AS builder16 17WORKDIR /app18 19# Ensure git is available (required for installing dependencies from VCS)20RUN apt-get update && \21 apt-get install -y --no-install-recommends git nodejs npm && \22 rm -rf /var/lib/apt/lists/*23 24# Build argument to control whether we're building standalone or in-repo25ARG BUILD_MODE=in-repo26ARG ENV_NAME=code_migration_env27 28# Copy environment code (always at root of build context)29COPY . /app/env30 31# For in-repo builds, openenv is already vendored in the build context32# For standalone builds, openenv will be installed via pyproject.toml33WORKDIR /app/env34 35# Ensure uv is available (for local builds where base image lacks it)36RUN if ! command -v uv >/dev/null 2>&1; then \37 curl -LsSf https://astral.sh/uv/install.sh | sh && \38 mv /root/.local/bin/uv /usr/local/bin/uv && \39 mv /root/.local/bin/uvx /usr/local/bin/uvx; \40 fi41 42# Install dependencies using uv sync43# If uv.lock exists, use it; otherwise resolve on the fly44RUN --mount=type=cache,target=/root/.cache/uv \45 if [ -f uv.lock ]; then \46 uv sync --frozen --no-install-project --no-editable; \47 else \48 uv sync --no-install-project --no-editable; \49 fi50 51RUN --mount=type=cache,target=/root/.cache/uv \52 if [ -f uv.lock ]; then \53 uv sync --frozen --no-editable; \54 else \55 uv sync --no-editable; \56 fi57 58# Final runtime stage59FROM ${BASE_IMAGE}60 61WORKDIR /app62 63# The JS migration task executes Node-based graders at runtime, so Node must be64# available in the final image as well, not only in the build stage.65RUN apt-get update && \66 apt-get install -y --no-install-recommends nodejs npm && \67 rm -rf /var/lib/apt/lists/*68 69# Copy the virtual environment from builder70COPY --from=builder /app/env/.venv /app/.venv71 72# Copy the environment code73COPY --from=builder /app/env /app/env74 75# Set PATH to use the virtual environment76ENV PATH="/app/.venv/bin:$PATH"77 78# Set PYTHONPATH so imports work correctly79ENV PYTHONPATH="/app/env:$PYTHONPATH"80 81# Health check82HEALTHCHECK --interval=30s --timeout=3s --start-period=5s --retries=3 \83 CMD curl -f http://localhost:8000/health || exit 184 85# Run the FastAPI server86# The module path is constructed to work with the /app/env structure87CMD ["sh", "-c", "cd /app/env && uvicorn server.app:app --host 0.0.0.0 --port 8000"]88 