Replies: 4 comments 7 replies
-
AFAIK, the only real thing you can do is ensure all the steps in the dockerfile that can be cached occur first and run the Also, a little trick I learned is I didn't need to copy my whole project into the dockerfile (thus incurring a new cache layer with every change). I use a volume mapping to point to the local directory where my project resides. I still have to copy the pyproject.toml & lock but everything else sits outside the image. The image is only the runtime environment. YMMV of course. I use docker compose, but you could accomplish the same thing with commandline when running the image. services:
name_of_your_service:
build:
context: .
dockerfile: wherever_you_keep_your_dockerfiles/Dockerfile
image: name_of_your_image
volumes:
# This is the mapping. localhost_path:image_path
# ./ is the root of the project on the localhost
# /localfolder is an alias of the directory within the image.
- ./:/localfolder COPY pyproject.toml poetry.lock* ./
RUN poetry install
WORKDIR /localfolder/tests
# from here you can still execute scripts in the ./tests without ever having to copy them into the image |
Beta Was this translation helpful? Give feedback.
-
You could use mounted caches?
|
Beta Was this translation helpful? Give feedback.
-
I think that this thread also provides some good recommendations: |
Beta Was this translation helpful? Give feedback.
-
Hi everyone, I'm facing a situation where I have a
Dockerfile
that is quite well optimized regarding layers.My only problem is this line
It works fine and all but every time I'm bumping the version of my project in
pyproject.toml
this whole layer is getting invalidated and being re-run.This is really annoying since most of the work is downloading packages. I don't want to use global installs (I'm using in-project virtualenv for staged-builds).
My question is that if is there a good practice of versioning poetry-managed packages outside of
pyproject.toml
file, or even managing the dependencies in a different way.All I want to have is a sanely versioned project and an expensive layer cached and invalidated only when really necessary.
Beta Was this translation helpful? Give feedback.
All reactions