chat_env / Dockerfile
Zach Wentz
🤖 Deploy chat_env environment - 2025-10-21 22:49:50
fb4e6b7
raw
history blame
1.69 kB
# Copyright (c) Meta Platforms, Inc. and affiliates.
# All rights reserved.
#
# This source code is licensed under the BSD-style license found in the
# LICENSE file in the root directory of this source tree.
# Multi-stage build: First stage builds the base image
FROM python:3.11-slim as base-builder
# Install system dependencies
RUN apt-get update && apt-get install -y --no-install-recommends \
curl \
&& rm -rf /var/lib/apt/lists/*
# Install Python dependencies that all environments need
RUN pip install --no-cache-dir \
fastapi>=0.104.0 \
"uvicorn[standard]>=0.24.0" \
requests>=2.25.0 \
wsproto>=1.0.0
# Set working directory
WORKDIR /app
# Default environment variables
ENV PYTHONPATH=/app/src
ENV PYTHONUNBUFFERED=1
# Second stage: Use the built base image and add environment-specific dependencies
FROM base-builder
# Install additional dependencies for ChatEnvironment
RUN pip install --no-cache-dir torch transformers
# Set up cache directory for Hugging Face models
RUN mkdir -p /.cache && chmod 777 /.cache
ENV HF_HOME=/.cache
ENV TRANSFORMERS_CACHE=/.cache
# Pre-download the GPT-2 model to avoid permission issues during runtime
RUN python -c "from transformers import GPT2Tokenizer; GPT2Tokenizer.from_pretrained('gpt2')"
# Copy only what's needed for this environment
COPY src/core/ /app/src/core/
COPY src/envs/chat_env/ /app/src/envs/chat_env/
# Health check
HEALTHCHECK --interval=30s --timeout=3s --start-period=5s --retries=3 \
CMD curl -f http://localhost:8000/health || exit 1
# Run the FastAPI server
CMD ["uvicorn", "envs.chat_env.server.app:app", "--host", "0.0.0.0", "--port", "8000"]
ENV ENABLE_WEB_INTERFACE=true