问题描述
在设置gitlab-runner中模式选为docker
问题出现的平台版本
yarn -v
v1.22.5
node -v
v16.3.0
docker -v
Docker version 20.10.7, build f0df350
gitlab-runner -v
Version: 13.12.0
Git revision: 7a6612da
Git branch: 13-12-stable
GO version: go1.16.3
Built: 2021-05-20T23:59:54+01:00
OS/Arch: darwin/amd64
相关代码
这个是我的gitlab-runner config
/usr/local/share/.cache/为镜像中yarn的全局缓存目录
concurrent = 1
check_interval = 0
[session_server]
session_timeout = 1800
[[runners]]
name = "xxxx"
url = "http://xxxxx"
token = "xxxxxx"
executor = "docker"
[runners.custom_build_dir]
[runners.cache]
[runners.cache.s3]
[runners.docker]
tls_verify = false
image = "node"
privileged = false
disable_entrypoint_overwrite = false
oom_kill_disable = false
disable_cache = false
volumes = ["/Users/xxxx/home/cache:/usr/local/share/.cache/"]
这个是我.gitlab-ci.yml文件
image: node
stages:
- build
variables:
GIT_STRATEGY: clone
build:
stage: build
image: node
script:
- yarn install
only:
- feature/1.0.0
tags:
- fe
timeout: 10m
你期待的结果是什么?实际看到的错误信息又是什么?
在ci执行到script时,yarn会显示网络错误,我确保我挂靠到volumes的文件权限为777
在docker外部访问/Users/xxxx/home/cache目录能够看到yarn下载的依赖内容
$ yarn install --har
yarn install v1.22.5
[1/5] Resolving packages...
[2/5] Fetching packages...
info There appears to be trouble with your network connection. Retrying...
info There appears to be trouble with your network connection. Retrying...
我期待得到的结果是我的依赖安装完成。
确认几个点吧:
yarn cache dir
确认一下全局的缓存目录是否正确yarn cache list
查看当前缓存的依赖库由于评论不好写代码,我就补充一下我的回答吧!
我自己对你的环境做了一下模拟:
node:12
镜像运行的容器 A
中,创建了一个 demo 的项目,同时对容器内的缓存目录做了一下映射:容器 B
,并挂载同样的缓存目录:容器 A
拷贝到容器 B
:容器 B
内,先删除 demo 下的 node_modules,然后我们尝试一下yarn install --offline
,看看是否成功:这样看来是没什么问题的:通过向容器挂载缓存目录达到加快下载依赖速度的目的,甚至不用下载依赖。
回到你的问题,有几个疑问点:
所以可以考虑下:把容器内的缓存挂载到新的宿主机目录(比如
/tmp/cache2
),然后第一次先让容器下载缓存,再观察第二次是否需要下载缓存(第二次的时候可以尝试开启离线模式,即yarn install --offline
)