KChad/Prompt-Injection-RL-environment
1
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 src/core)10# - Standalone environments (with openenv-core from pip)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 ghcr.io/meta-pytorch/openenv-base:latest AS builder15 16WORKDIR /app17ARG BUILD_MODE=in-repo18 19COPY . /app/env20WORKDIR /app/env21 22# Ensure uv is available23RUN if ! command -v uv >/dev/null 2>&1; then \24 curl -LsSf https://astral.sh/uv/install.sh | sh && \25 mv /root/.local/bin/uv /usr/local/bin/uv && \26 mv /root/.local/bin/uvx /usr/local/bin/uvx; \27 fi28 29# Install git30RUN apt-get update && apt-get install -y --no-install-recommends \31 git \32 && rm -rf /var/lib/apt/lists/*33 34# Install uv properly35RUN curl -LsSf https://astral.sh/uv/install.sh | sh && \36 install -m 0755 /root/.local/bin/uv /usr/local/bin/uv && \37 install -m 0755 /root/.local/bin/uvx /usr/local/bin/uvx38 39# Two-pass install for better layer caching40RUN --mount=type=cache,target=/root/.cache/uv \41 uv sync --no-install-project --no-editable42 43RUN --mount=type=cache,target=/root/.cache/uv \44 uv sync --no-editable45 46# ── Runtime stage ──────────────────────────────────────────────────47FROM ghcr.io/meta-pytorch/openenv-base:latest48 49WORKDIR /app50 51# Copy venv and code from builder52COPY --from=builder /app/env/.venv /app/.venv53COPY --from=builder /app/env /app/env54 55# Environment56ENV PATH="/app/.venv/bin:$PATH"57ENV PYTHONPATH="/app/env:$PYTHONPATH"58ENV PYTHONUNBUFFERED=159ENV ENABLE_WEB_INTERFACE=true60 61# Expose port62EXPOSE 800063 64# Health check65HEALTHCHECK --interval=30s --timeout=3s --start-period=5s --retries=3 \66 CMD python -c "import urllib.request; urllib.request.urlopen('http://localhost:8000/health')" || exit 167 68# Default: start server69# Runtime inference credentials should be passed when needed via70# API_BASE_URL, MODEL_NAME, and HF_TOKEN.71CMD ["sh", "-c", "cd /app/env && uvicorn server.app:app --host 0.0.0.0 --port 8000"]72 