File size: 1,685 Bytes
8ab8289
 
 
 
 
 
fb4e6b7
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
8ab8289
 
 
67a5ae3
 
 
 
 
 
 
 
fb4e6b7
8ab8289
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# 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