|
4 | 4 | # This source code is licensed under the BSD-style license found in the |
5 | 5 | # LICENSE file in the root directory of this source tree. |
6 | 6 |
|
7 | | -# Use the standard openenv base image |
8 | | -# Built from: docker build -t openenv-base:latest -f src/core/containers/images/Dockerfile . |
9 | | -# In GitHub Actions, this is overridden to use the GHCR base image |
| 7 | +# Multi-stage build using openenv-base |
| 8 | +# 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 | + |
10 | 13 | ARG BASE_IMAGE=openenv-base:latest |
| 14 | +FROM ${BASE_IMAGE} AS builder |
| 15 | + |
| 16 | +WORKDIR /app |
| 17 | + |
| 18 | +# Build argument to control whether we're building standalone or in-repo |
| 19 | +ARG BUILD_MODE=in-repo |
| 20 | +ARG ENV_NAME=echo_env |
| 21 | + |
| 22 | +# Copy environment code (always at root of build context) |
| 23 | +COPY . /app/env |
| 24 | + |
| 25 | +# For in-repo builds, openenv-core is already in the pyproject.toml dependencies |
| 26 | +# For standalone builds, openenv-core will be installed from pip via pyproject.toml |
| 27 | +WORKDIR /app/env |
| 28 | + |
| 29 | +# Install dependencies using uv sync |
| 30 | +# If uv.lock exists, use it; otherwise resolve on the fly |
| 31 | +RUN --mount=type=cache,target=/root/.cache/uv \ |
| 32 | + if [ -f uv.lock ]; then \ |
| 33 | + uv sync --frozen --no-install-project --no-editable; \ |
| 34 | + else \ |
| 35 | + uv sync --no-install-project --no-editable; \ |
| 36 | + fi |
| 37 | + |
| 38 | +RUN --mount=type=cache,target=/root/.cache/uv \ |
| 39 | + if [ -f uv.lock ]; then \ |
| 40 | + uv sync --frozen --no-editable; \ |
| 41 | + else \ |
| 42 | + uv sync --no-editable; \ |
| 43 | + fi |
| 44 | + |
| 45 | +# Final runtime stage |
11 | 46 | FROM ${BASE_IMAGE} |
12 | 47 |
|
13 | | -# Copy only what's needed for this environment |
14 | | -COPY src/core/ /app/src/core/ |
15 | | -COPY src/envs/echo_env/ /app/src/envs/echo_env/ |
| 48 | +WORKDIR /app |
| 49 | + |
| 50 | +# Copy the virtual environment from builder |
| 51 | +COPY --from=builder /app/env/.venv /app/.venv |
| 52 | + |
| 53 | +# Copy the environment code |
| 54 | +COPY --from=builder /app/env /app/env |
| 55 | + |
| 56 | +# Set PATH to use the virtual environment |
| 57 | +ENV PATH="/app/.venv/bin:$PATH" |
16 | 58 |
|
17 | | -# Copy README for web interface documentation |
18 | | -COPY src/envs/echo_env/README.md /app/README.md |
| 59 | +# Set PYTHONPATH so imports work correctly |
| 60 | +ENV PYTHONPATH="/app/env:$PYTHONPATH" |
19 | 61 |
|
20 | 62 | # Health check |
21 | 63 | HEALTHCHECK --interval=30s --timeout=3s --start-period=5s --retries=3 \ |
22 | 64 | CMD curl -f http://localhost:8000/health || exit 1 |
23 | 65 |
|
24 | 66 | # Run the FastAPI server |
25 | | -CMD ["uvicorn", "envs.echo_env.server.app:app", "--host", "0.0.0.0", "--port", "8000"] |
| 67 | +# The module path is constructed to work with the /app/env structure |
| 68 | +CMD ["sh", "-c", "cd /app/env && uvicorn server.app:app --host 0.0.0.0 --port 8000"] |
0 commit comments