ajaxwin commited on
Commit
a0858e7
·
1 Parent(s): 878ca5a

dockerfile update 3

Browse files
Files changed (1) hide show
  1. Dockerfile +16 -42
Dockerfile CHANGED
@@ -1,45 +1,23 @@
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 the
5
- # LICENSE file in the root directory of this source tree.
6
-
7
- # Multi-stage build using openenv-base
8
- # This Dockerfile is flexible and works for both:
9
- # - In-repo environments (with local OpenEnv sources)
10
- # - Standalone environments (with openenv from PyPI/Git)
11
- # The build script (openenv build) handles context detection and sets appropriate build args.
12
-
13
  ARG BASE_IMAGE=ghcr.io/meta-pytorch/openenv-base:latest
14
- FROM ${BASE_IMAGE} AS builder
 
 
15
 
16
  WORKDIR /app
17
 
18
- # Ensure git is available (required for installing dependencies from VCS)
19
  RUN apt-get update && \
20
- apt-get install -y --no-install-recommends git && \
21
  rm -rf /var/lib/apt/lists/*
22
 
23
- # Build argument to control whether we're building standalone or in-repo
24
- ARG BUILD_MODE=in-repo
25
- ARG ENV_NAME=smartcontractenv
26
-
27
- # Copy environment code (always at root of build context)
28
  COPY . /app/env
29
-
30
- # For in-repo builds, openenv is already vendored in the build context
31
- # For standalone builds, openenv will be installed via pyproject.toml
32
  WORKDIR /app/env
33
 
34
- # Ensure uv is available (for local builds where base image lacks it)
35
- RUN if ! command -v uv >/dev/null 2>&1; then \
36
- curl -LsSf https://astral.sh/uv/install.sh | sh && \
37
- mv /root/.local/bin/uv /usr/local/bin/uv && \
38
- mv /root/.local/bin/uvx /usr/local/bin/uvx; \
39
- fi
40
-
41
- # Install dependencies using uv sync
42
- # If uv.lock exists, use it; otherwise resolve on the fly
43
  RUN --mount=type=cache,target=/root/.cache/uv \
44
  if [ -f uv.lock ]; then \
45
  uv sync --frozen --no-install-project --no-editable; \
@@ -54,21 +32,18 @@ RUN --mount=type=cache,target=/root/.cache/uv \
54
  uv sync --no-editable; \
55
  fi
56
 
57
- # Final runtime stage
 
58
  FROM ${BASE_IMAGE}
59
 
60
  WORKDIR /app
61
 
62
- # Copy the virtual environment from builder
63
  COPY --from=builder /app/env/.venv /app/.venv
64
-
65
- # Copy the environment code
66
  COPY --from=builder /app/env /app/env
67
 
68
- # Set PATH to use the virtual environment
69
  ENV PATH="/app/.venv/bin:$PATH"
70
-
71
- # Set PYTHONPATH so imports work correctly
72
  ENV PYTHONPATH="/app/env:$PYTHONPATH"
73
 
74
  # Download NLTK data
@@ -78,6 +53,5 @@ RUN /app/.venv/bin/python -m nltk.downloader wordnet omw-1.4 stopwords punkt ave
78
  HEALTHCHECK --interval=30s --timeout=3s --start-period=5s --retries=3 \
79
  CMD curl -f http://localhost:7860/health || exit 1
80
 
81
- # Run the FastAPI server
82
- # The module path is constructed to work with the /app/env structure
83
- CMD ["sh", "-c", "cd /app/env && uvicorn server.app:app --host 0.0.0.0 --port 7860"]
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  ARG BASE_IMAGE=ghcr.io/meta-pytorch/openenv-base:latest
2
+
3
+ # -------- BUILDER STAGE (Python 3.11) --------
4
+ FROM python:3.11-slim AS builder
5
 
6
  WORKDIR /app
7
 
 
8
  RUN apt-get update && \
9
+ apt-get install -y --no-install-recommends git curl && \
10
  rm -rf /var/lib/apt/lists/*
11
 
 
 
 
 
 
12
  COPY . /app/env
 
 
 
13
  WORKDIR /app/env
14
 
15
+ # Install uv
16
+ RUN curl -LsSf https://astral.sh/uv/install.sh | sh && \
17
+ mv /root/.local/bin/uv /usr/local/bin/uv && \
18
+ mv /root/.local/bin/uvx /usr/local/bin/uvx
19
+
20
+ # Install dependencies
 
 
 
21
  RUN --mount=type=cache,target=/root/.cache/uv \
22
  if [ -f uv.lock ]; then \
23
  uv sync --frozen --no-install-project --no-editable; \
 
32
  uv sync --no-editable; \
33
  fi
34
 
35
+
36
+ # -------- RUNTIME STAGE --------
37
  FROM ${BASE_IMAGE}
38
 
39
  WORKDIR /app
40
 
41
+ # Copy venv + code
42
  COPY --from=builder /app/env/.venv /app/.venv
 
 
43
  COPY --from=builder /app/env /app/env
44
 
45
+ # Use venv
46
  ENV PATH="/app/.venv/bin:$PATH"
 
 
47
  ENV PYTHONPATH="/app/env:$PYTHONPATH"
48
 
49
  # Download NLTK data
 
53
  HEALTHCHECK --interval=30s --timeout=3s --start-period=5s --retries=3 \
54
  CMD curl -f http://localhost:7860/health || exit 1
55
 
56
+ # Start server
57
+ CMD ["sh", "-c", "cd /app/env && uvicorn server.app:app --host 0.0.0.0 --port 7860"]