gpt4 book ai didi

docker - Github Action docker 缓存

转载 作者:行者123 更新时间:2023-12-02 19:44:50 30 4
gpt4 key购买 nike

我认为这对其他人有用。
我正在使用 https://github.com/phips28/gh-action-bump-version在 Github Actions 中自动提升 NPM 版本。
有没有办法缓存这个 Action 的 docker 图像,这样它就不必每次都构建?它需要很长时间才能运行,并且它会在其余步骤之前预先运行。我确信这对于提取 docker 图像的类似类型的 Github Actions 来说很常见。
docker 镜像看起来很瘦,所以我不确定尝试优化镜像本身会有什么好处。更多关于如何配置 Github Actions。
有什么建议?

最佳答案

TLDR
有些!您可以将 GitHub 工作流文件更改为 pull来自存储库的图像而不是 building每次运行。虽然这不会缓存图像,但速度明显更快。这可以通过将您的流程编辑为如下所示来实现:

      - name: 'Automated Version Bump'
id: version-bump
uses: 'docker://phips28/gh-action-bump-version:master'
with:
tag-prefix: 'v'
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

请注意 docker:// uses: 的前缀声明,加上来自 @master 的更改至 :master以便将名称转换为有效的图像名称。
我开通了 PR在该存储库上有一个建议的修复:^)
原始回复
一个很好的问题,在官方文档中可以找到很少的信息(虽然 GitHub acknowledge the delay in their docs)。
GitHub 员工的回应
我搜索了您并设法找到了 article从 2019 年 9 月在 GitHub 社区论坛上关于这个确切的主题。它不可避免地与此相关 article从 2019 年 7 月开始。
关于每次构建仍将如何使用 docker 构建缓存,减少时间,同时允许在使用最新版本的基础镜像等方面的灵活性,有一个很好的解释。
如果您不担心更新的灵活性,并且只想尽可能缩短构建时间,则有一个建议的解决方案,尽管我不确定该语法目前是否仍然有效:

But let’s say that I don’t want my Action to even evaluate the Dockerfile every time the Action runs, because I want the absolute fastest runtime possible. I want a predefined Docker container to be spun up and get right to work. You can have that too! If you create a Docker image and upload it to Docker Hub or another public registry, you can instruct your Action to use that Docker image specifically using the docker:// form in the uses key. See the GitHub Actions documentation 72 for specifics. This requires a bit more up-front work and maintenance, but if you don’t need the flexibility that the above Dockerfile evaluation system provides, then it may be worth the tradeoff.


不幸的是 link Github 操作文档已损坏,但这确实表明操作的作者如果修改了他们的操作就可以允许这种行为
替代想法
如果您需要控制执行器主机上的缓存的能力(以真正缓存图像),那么您可能会考虑考虑 hosting your own GitHub runner ,因为您可以完全控制那里的图像。尽管我认为这可能是一种威慑,因为 GitHub 操作在很大程度上是一项免费服务(有限制,这可能就是其中之一!)
您可能需要考虑添加一个使用 file cache action 的任务。 ,并试图导出 gh-action-bump-version通过 docker commit 到文件内容或 docker save ,然后在下次运行时重新充气。但是,这会带来复杂性,从长远来看可能不会为您节省时间。 编辑 :这是一个可怕的想法,因为我们知道操作可以支持从注册表中提取图像。
我希望这对您和其他任何正在寻找更多信息的人有帮助👍

关于docker - Github Action docker 缓存,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64174918/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com