让Gitlab Runner使用node_modules作为工件而不是在缓存中 [英] Having Gitlab Runner use node_modules as an artifact instead of in cache

查看:307
本文介绍了让Gitlab Runner使用node_modules作为工件而不是在缓存中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

根据关于缓存与工件的GitLab文档 node_modules 应该存储为缓存而不是工件.问题在于,如果有多个运行者,而与创建构建"项目的人不同.拿起一个工作,然后缓存( node_modules )将不存在,这将使GitLab CI随机失败(如果同一运行者碰巧完成了其余工作,那么它将成功).

According to the GitLab Documentation for cache vs artifacts the node_modules should be stored as cache instead of an artifact. The issue with this is if there are multiple runners and a different runner from what created the "build" picks up a job then the cache (node_modules) won't exist which will fail the GitLab CI randomly (if the same runner happens to do the rest of the jobs then it will succeed).

我可以做到,所有事情都可以在一个工作中完成,但是一旦不得不部署,这个问题就会再次发生.另一种选择是标记它,以便只有一个特定的跑步者才能完成工作,但我觉得那很慢.

I could make it so everything is done in one job but once I have to put in deployment this issue will reoccur. Another option is to tag it so only one specific runner completes the job but I feel like that is slow.

研究之后,我意识到我可以将 node_modules 放入工件而不是缓存中,无论哪个运行者运行它都会被拾取,但是我找不到关于这是好是坏.

After researching I realized I could just put in node_modules as an artifact instead of the cache and it will be picked up no matter which runner runs the job but I can't find any documentation on if this is bad or not.

那么可以将 node_modules 作为工件放置吗?如果是这样,人们为什么不正常地将其作为人工制品(假设他们添加了过期期限)?

So is it okay to put node_modules as an artifact? If so, why wouldn't people put it as an artifact normally (assuming they add an expiration)?

推荐答案

此处的简短答案是,您可以根据需要使用该工具.您绝对可以对node_modules使用工件.但是,有一种方法也可以使缓存正常工作.

The short answer here is that you can use the tool however you want to. You absolutely can use artifacts for node_modules. However, there's a way to make the cache work too.

默认情况下,当运行程序缓存文件或目录时,它将本地存储在运行该运行程序的主机上(这就是为什么其他运行程序上不可用的原因).但是,在runner配置中,您可以更改此设置以将缓存的对象存储在AWS S3或类似S3的存储库(例如Minio)中.如果以这种方式配置了所有运行程序,或者至少配置了2个,那么这些运行程序也可以使用相同的缓存项目.

By default, when a runner caches a file or directory, it stores it locally on the host running that runner (which is why it's not available on other runners). In the runner config however, you can change this to store cached objects in AWS S3 or an S3-like repo (like Minio). If all runners are configured this way, or at least 2 are, then those runners can also use the same cached items.

您可以在此处阅读有关跑步者的缓存配置选项的信息:​​

You can read about the runner's cache config options here: https://docs.gitlab.com/runner/configuration/advanced-configuration.html#the-runnerscache-section

您可以在此处阅读有关Minio(提供S3 API接口的开源存储解决方案)的信息: https://docs.min.io/

You can read about Minio (an open source storage solution that provides an S3 API interface) here: https://docs.min.io/

这篇关于让Gitlab Runner使用node_modules作为工件而不是在缓存中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆