Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

build only dependencies for a docker layer #1813

Open
sean-abbott opened this issue Nov 17, 2024 · 0 comments
Open

build only dependencies for a docker layer #1813

sean-abbott opened this issue Nov 17, 2024 · 0 comments

Comments

@sean-abbott
Copy link

Is there a way to build only my dependencies for a multi-stage docker build, without needing my code, and using pyproject.toml only?

I'm managing this with

FROM python:3.12-slim as builder

RUN apt-get update \
    && apt-get -y install build-essential libpq-dev

RUN pip install --upgrade pip --root-user-action=ignore && \
    pip install hatch --root-user-action=ignore

WORKDIR /deps

COPY pyproject.toml /deps
RUN mkdir -p /deps/src && \
    touch /deps/README.md && \
    hatch dep show requirements > requirements.txt

RUN pip install -t dist -r requirements.txt --root-user-action=ignore

# Final Layer
FROM python:3.12-slim

RUN apt-get update \
    && apt-get install -y libpq5 \
    && rm -rf /var/lib/apt/lists/*

WORKDIR /app
COPY --from=builder /deps/dist/ /usr/local/lib/python3.12/site-packages/
COPY --from=builder /deps/dist/bin /usr/local/bin
COPY . /app/

RUN pip install --upgrade pip --root-user-action=ignore && \
    pip install -e . --root-user-action=ignore

ENV PYTHONDONTWRITEBYTECODE=1
ENV PYTHONUNBUFFERED=1

But it would be nice to just be able to do this directly with hatch, and be able to build a wheel that I can explicitly pull from my build stage and just install as a single file.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant