如何缓存“诗歌安装”对于 Gitlab CI?
有没有办法在 Gitlab CI (.gitlab-ci.yml
) 中缓存 poetry install
命令?
例如,在 node
yarn
中,有一种方法可以缓存 yarn install
(https://classic.yarnpkg.com/lang/en/docs/install-ci/ Gitlab
部分)这使得阶段变得更快。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
GitLab 只能缓存工作目录中的内容 和 Poetry 默认将包存储在其他地方:
在我的机器上,
cache-dir
是/home/chris/.cache/pypoetry
。您可以使用
virtualenvs.in-project
选项 改变这种行为:所以,类似这样的东西应该在你的 gitlab-ci.yml 中工作:
GitLab can only cache things in the working directory and Poetry stores packages elsewhere by default:
On my machine,
cache-dir
is/home/chris/.cache/pypoetry
.You can use the
virtualenvs.in-project
option to change this behaviour:So, something like this should work in your
gitlab-ci.yml
:您可以将 Poetry virtualenv 缓存目录 设置为 GitLab 项目空间中的某个目录,例如:
然后像平常一样缓存它:
You can set the Poetry virtualenv cache directory to something within the GitLab project space, e.g.:
and then cache it like normal:
结合 @Chris 和 @Sean Connolly 的答案帮助我转移了 Python 虚拟环境以及诗歌二进制文件夹的依赖关系。
我使用 POETRY_VIRTUALENVS_PATH 来指定虚拟环境的实例化位置。 诗歌文档在
第 2 步安装中说明诗(高级)
来自使用官方安装程序
,可以定义自定义安装文件夹。然后我安装poetry
并指定它应该安装在%CI_PROJECT_DIR/poetry
中。现在我知道了 poetry 和 venv 文件夹的安装位置,因此我可以使用工件进入下一阶段。在此阶段,我导出诗歌二进制文件,以便可以在不直接引用文件夹的情况下使用它。下面的 yaml 文件应该可以工作:
Combining the answers of @Chris and @Sean Connolly helped me to transfer the dependencies of my Python virtual environment and also the poetry binary folder.
I used the
POETRY_VIRTUALENVS_PATH
to specify where the virtual environment will be instantiated. The poetry documentation states instep 2 Install Poetry (advanced)
from theWith the official installer
that it is possible to define a custom install folder. Then I installpoetry
and specify that it should be installed in%CI_PROJECT_DIR/poetry
. Now I know wherepoetry
and thevenv
folders are installed thus I can passed to the next stage using artifacts. In this stage I export the poetry binary so it can be used without referencing the folder directly.The yaml file below should work: