How to cache "poetry install" for Gitlab CI?

Viewed 2034
1 Answers

GitLab can only cache things in the working directory and Poetry stores packages elsewhere by default:

Directory where virtual environments will be created. Defaults to {cache-dir}/virtualenvs ({cache-dir}\virtualenvs on Windows).

On my machine, cache-dir is /home/chris/.cache/pypoetry.

You can use the virtualenvs.in-project option to change this behaviour:

If set to true, the virtualenv wil be created and expected in a folder named .venv within the root directory of the project.

So, something like this should work in your gitlab-ci.yml:

before_script:
  - poetry config virtualenvs.in-project true

cache:
  paths:
    - .venv
Related