question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Simple instalation without cache

See original GitHub issue
  • I have searched the issues of this repo and believe that this is not a duplicate.
  • I have searched the documentation and believe that my question is not covered.

Feature Request

TL;DR

I’d like to use pyproject.toml for instaling dependencies for project with minimal impact on size where the docker container provides sufficient isolation. E.G.:

poetry install --no-root --no-cache --no-interaction

Details, blockers and other similar issues

I’d like to use poetry in docker as simple as pip install --no-cache-dir -r requirements.txt (with cleared cache), but have some trouble. I have a local dependency which is wanted to be editable in the same local folder.

...
[tool.poetry.dependencies]
python = "^3.8"
numpy = "^1.19.4"
pandas = "^1.1.4"
jupyterlab = "^2.2.9"

[tool.poetry.dev-dependencies]
# is installed as "python setup.py develop" and can be edited in mypackage folder
mypackage = {path = "./mypackage", develop = true}

Installation in docker:

FROM python:3.8-slim-buster

WORKDIR /lab

RUN pip install poetry --no-cache-dir && \
    poetry config virtualenvs.create false
COPY poetry.lock pyproject.toml .

# my local dependency
COPY ./mypackage ./mypackage

# too big
RUN poetry install --no-root --no-interaction

EXPOSE 9180
CMD ["jupyter", "lab", "--allow-root", "--ip=0.0.0.0", "--port=9180", "."]

I’ve tried also RUN poetry install --no-root --no-interaction && poetry cache clear --no-interaction --all pypi, but size is the same.

I found https://github.com/python-poetry/poetry/issues/1879#issuecomment-592133519, but there is too many rows and dockerfile is being complex.

I’ve also tried https://github.com/python-poetry/poetry/issues/1879#issuecomment-650384931:

RUN poetry export -f requirements.txt --dev --without-hashes | pip install --no-cache-dir -r /dev/stdin

This is fine workaround but its not suitable for mypackage (local package) dependency. Export row of package is mypackage @ /home/vh/test-docker/mypackage; python_version >= "3.8" and python_version < "4.0" and pip searching this package on pypi and fail.

When I remove the local dependency and run previous command without --dev param:

RUN poetry export -f requirements.txt -v --without-hashes | pip install --no-cache-dir -r /dev/stdin && \
         cd mypackage && \
         poetry install --develop mypackage && \
         cd ..

Also crashes with error that --develop param was removed with release poetry v1.0.0. But I found opened issue: https://github.com/python-poetry/poetry/issues/2572.

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:9
  • Comments:9 (6 by maintainers)

github_iconTop GitHub Comments

32reactions
cbrochtrupcommented, Feb 17, 2022

Another option to keep the cache out of the final image is to use docker BuildKit’s cache feature. I’ve used it with success.

Example

# syntax=docker/dockerfile:1.2

COPY poetry.lock /
RUN --mount=type=cache,target=/home/.cache/pypoetry/cache \
    --mount=type=cache,target=/home/.cache/pypoetry/artifacts \
    poetry install

This way, docker keeps your poetry cache around for quick builds, layer sharing, etc. but not in the final image.

13reactions
sinoroccommented, Nov 18, 2020

Personal opinion:

I see how it might be a helpful feature. On the other hand I can’t help but think that it should be quite easy to just delete the cache and other build artefacts and what not right after the installation:

RUN poetry install ... && rm -rf ~/.cache/pypoetry/{cache,artifacts}

We might spare us adding complexity into poetry’s code base. But maybe also it is not as simple as that and a --no-cache feature makes sense.

Read more comments on GitHub >

github_iconTop Results From Across the Web

pip uses incorrect cached package version, instead of the user ...
If you want to not use the pip cache for some reason (which is a bad idea, according the official docs), your options...
Read more >
Caching - pip documentation v22.3.1
pip provides an on-by-default caching, designed to reduce the amount of time spent on duplicate downloads and builds.
Read more >
Disable or move the package cache - Visual Studio (Windows)
Learn how to disable, enable, or move the package cache for Visual Studio deployments.
Read more >
Pip Clear Cache - Linux Hint
This tutorial taught you the fundamentals of working with the pip cache and the two methods to clear the pip cache depending on...
Read more >
How to Clear Cache in WordPress: 6 Simple Methods
3. Can I install both Litespeed Cache and WP rocket for the same website? Recommend or not? Thanks.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found