Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to cache "poetry install" for Gitlab CI?

Is there a way to cache poetry install command in Gitlab CI (.gitlab-ci.yml)?

For example, in node yarn there is a way to cache yarn install (https://classic.yarnpkg.com/lang/en/docs/install-ci/ Gitlab section) this makes stages a lot faster.

like image 392
Angel Avatar asked Jan 25 '26 01:01

Angel


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
like image 94
Chris Avatar answered Jan 26 '26 16:01

Chris



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!