|
1 |
| -FROM --platform=linux/amd64 ghcr.io/owl-corp/python-poetry-base:3.12-slim |
| 1 | +ARG python_version=3.12-slim |
| 2 | + |
| 3 | +FROM python:$python_version AS builder |
| 4 | +COPY --from=ghcr.io/astral-sh/uv:0.7 /uv /bin/ |
| 5 | + |
| 6 | +ENV UV_COMPILE_BYTECODE=1 \ |
| 7 | + UV_LINK_MODE=copy |
| 8 | + |
| 9 | +# Install project dependencies with build tools available |
| 10 | +WORKDIR /build |
| 11 | +RUN pip install --no-cache-dir --upgrade pip setuptools wheel virtualenv \ |
| 12 | + && python -m virtualenv .venv |
| 13 | + |
| 14 | +RUN --mount=type=cache,target=/root/.cache/uv \ |
| 15 | + --mount=type=bind,source=uv.lock,target=uv.lock \ |
| 16 | + --mount=type=bind,source=pyproject.toml,target=pyproject.toml \ |
| 17 | + uv sync --frozen --no-dev |
| 18 | + |
| 19 | +# ------------------------------------------------------------------------------- |
| 20 | + |
| 21 | +FROM python:$python_version |
2 | 22 |
|
3 | 23 | # Define Git SHA build argument for sentry
|
4 | 24 | ARG git_sha="development"
|
5 | 25 | ENV GIT_SHA=$git_sha
|
6 | 26 |
|
7 |
| -# Install project dependencies |
8 |
| -WORKDIR /bot |
9 |
| -COPY pyproject.toml poetry.lock ./ |
10 |
| -RUN poetry install --without dev |
| 27 | +# Install dependencies from build cache |
| 28 | +# .venv not put in /app so that it doesn't conflict with the dev |
| 29 | +# volume we use to avoid rebuilding image every code change locally |
| 30 | +COPY --from=builder /build /build |
| 31 | +ENV PATH="/build/.venv/bin:$PATH" |
11 | 32 |
|
12 | 33 | # Copy the source code in last to optimize rebuilding the image
|
| 34 | +WORKDIR /bot |
13 | 35 | COPY . .
|
14 | 36 |
|
15 |
| -ENTRYPOINT ["poetry"] |
16 |
| -CMD ["run", "python", "-m", "bot"] |
| 37 | +ENTRYPOINT ["python", "-m"] |
| 38 | +CMD ["bot"] |
0 commit comments