GitLab Pages CI 缓存似乎没有缓存和恢复任何内容。如何检查缓存?
GitLab Pages CI cache appears to cache and restore nothing. How do I inspect the cache?
我有一个 .gitlab-ci.yml
看起来像这样:
image: mcr.microsoft.com/playwright:latest
before_script:
- apt-get remove nodejs -y
- apt-get update
- apt-get install -y curl
- curl -fsSL https://deb.nodesource.com/setup_18.x | bash -
- apt-get install -y nodejs
- npm install
pages:
stage: build
script:
- npm run docsify ; npx next build ; npx next export
- rm -rf public
- mv out public
artifacts:
paths:
- public
cache:
key: default
paths:
- node_modules/
- ".next/cache/"
- public
untracked: true # unclear if needed
only:
- main
它 运行 看起来它做所有正确的事情:
Running with gitlab-runner 14.9.1 (bd40e3da)
on runner-gitlab-runner-7ff6fc5d7b-dc9sh 2bfx5V6B
Preparing the "kubernetes" executor
Using Kubernetes namespace: gitlab-managed-apps
Using Kubernetes executor with image mcr.microsoft.com/playwright:latest ...
Using attach strategy to execute scripts...
Preparing environment
Waiting for pod gitlab-managed-apps/runner-2bfx5v6b-project-3385-concurrent-06khk6 to be running, status is Pending
Waiting for pod gitlab-managed-apps/runner-2bfx5v6b-project-3385-concurrent-06khk6 to be running, status is Pending
ContainersNotInitialized: "containers with incomplete status: [init-permissions]"
ContainersNotReady: "containers with unready status: [build helper]"
ContainersNotReady: "containers with unready status: [build helper]"
Running on runner-2bfx5v6b-project-3385-concurrent-06khk6 via runner-gitlab-runner-7ff6fc5d7b-dc9sh...
Getting source from Git repository
Fetching changes with git depth set to 50...
Initialized empty Git repository in
Created fresh repository.
Checking out 456ffc27 as main...
Skipping Git submodules setup
Restoring cache
Checking cache for default-4...
No URL provided, cache will not be downloaded from shared cache server. Instead a local version of cache will be extracted.
Successfully extracted cache
Executing "step_script" stage of the job script
...
Saving cache for successful job
Creating cache default-4...
node_modules/: found 22078 matching files and directories
.next/cache/: found 18 matching files and directories
public: found 925 matching files and directories
untracked: found 21814 files
No URL provided, cache will be not uploaded to shared cache server. Cache will be stored only locally.
Created cache
所以应该是缓存:
node_modules/
.next/cache/
public
我的理解是,在下一个管道 运行 的下一个 git clone
之后,GitLab CI 应该在克隆的存储库之上恢复缓存。 (或者通过卷装载使缓存可用,但我无法在 /cache
或 ./cache
中找到它。)
在下一次提交中打印出 public
的内容表明情况并非如此。
但从表面上看,缓存已恢复:
Fetching changes with git depth set to 50...
Initialized empty Git repository in
Created fresh repository.
Checking out d7d84cd8 as main...
Skipping Git submodules setup
Restoring cache
Checking cache for default-4...
No URL provided, cache will not be downloaded from shared cache server. Instead a local version of cache will be extracted.
Successfully extracted cache
缓存应该在哪里?
我应该如何检查它是否正常工作?
附录:
从 Next.js 的角度来看,此消息表明 Next.js 也没有从缓存中受益:
warn - No build cache found. Please configure build caching for faster rebuilds. Read more: https://nextjs.org/docs/messages/no-cache
我 the lines that they suggest you merge into your .gitlab-ci.yml
可以利用缓存。
您尚未配置分布式缓存,因此您的缓存仅在上传缓存时本地存储在运行作业的特定运行器上。
跑步者之间不共享缓存。因此,如果您有多个跑步者,如果您的工作被与上次不同的跑步者接管,则缓存可能不可用。这是因为 GitLab 假设不同的运行器可能位于不同的平台和架构上,缓存文件可能取决于这些环境因素(例如,为了二进制兼容性)。如果您有多个运行器或正在使用自动缩放功能,则需要配置 distributed caching.
如果您只有一个跑步者但仍然遇到此问题,请确保您的配置没有 cache mismatching problem。
您作业中的日志消息表明正在成功创建和恢复缓存(从本地缓存)。
Is S3 required for shared runners?
如果您有多个运行器,或者如果您使用上述自动缩放配置,则需要分布式缓存。但是,您不必为此使用 AWS S3,只需使用 S3-compatible 对象存储即可。例如,您可以 self-host minio 它提供(除其他外)与 S3 兼容的对象存储服务器。
Or make the cache available via a volume mount, but I haven't been able to find it in /cache or ./cache.
这是从 runner pod 的角度来看的。 runner 会自动将压缩缓存(如果存在)从 /cache
(安装到 runner pod)中提取到构建目录。乔布斯不会直接访问 /cache
挂载!但是,如果您想手动检查 runner pod 上的缓存,了解这一点是很好的。
您可以通过登录运行器 pod 上的 shell(使用 kubectl exec -it <your-runner-pod-name> /bin/sh
)并检查 /cache
目录和其中的任何压缩存档来检查缓存。
确保您的运行器配置为使用分布式缓存 - https://docs.gitlab.com/runner/configuration/autoscale.html#distributed-runners-caching
如果要使用缓存,则必须设置分布式缓存。
如果要设置分布式缓存,则必须设置 S3 兼容的对象存储。
没有 out-of-the-box 不支持没有对象存储的缓存。
即使您为每个构建使用相同的运行器,它也不会持续存在。
我有一个 .gitlab-ci.yml
看起来像这样:
image: mcr.microsoft.com/playwright:latest
before_script:
- apt-get remove nodejs -y
- apt-get update
- apt-get install -y curl
- curl -fsSL https://deb.nodesource.com/setup_18.x | bash -
- apt-get install -y nodejs
- npm install
pages:
stage: build
script:
- npm run docsify ; npx next build ; npx next export
- rm -rf public
- mv out public
artifacts:
paths:
- public
cache:
key: default
paths:
- node_modules/
- ".next/cache/"
- public
untracked: true # unclear if needed
only:
- main
它 运行 看起来它做所有正确的事情:
Running with gitlab-runner 14.9.1 (bd40e3da)
on runner-gitlab-runner-7ff6fc5d7b-dc9sh 2bfx5V6B
Preparing the "kubernetes" executor
Using Kubernetes namespace: gitlab-managed-apps
Using Kubernetes executor with image mcr.microsoft.com/playwright:latest ...
Using attach strategy to execute scripts...
Preparing environment
Waiting for pod gitlab-managed-apps/runner-2bfx5v6b-project-3385-concurrent-06khk6 to be running, status is Pending
Waiting for pod gitlab-managed-apps/runner-2bfx5v6b-project-3385-concurrent-06khk6 to be running, status is Pending
ContainersNotInitialized: "containers with incomplete status: [init-permissions]"
ContainersNotReady: "containers with unready status: [build helper]"
ContainersNotReady: "containers with unready status: [build helper]"
Running on runner-2bfx5v6b-project-3385-concurrent-06khk6 via runner-gitlab-runner-7ff6fc5d7b-dc9sh...
Getting source from Git repository
Fetching changes with git depth set to 50...
Initialized empty Git repository in
Created fresh repository.
Checking out 456ffc27 as main...
Skipping Git submodules setup
Restoring cache
Checking cache for default-4...
No URL provided, cache will not be downloaded from shared cache server. Instead a local version of cache will be extracted.
Successfully extracted cache
Executing "step_script" stage of the job script
...
Saving cache for successful job
Creating cache default-4...
node_modules/: found 22078 matching files and directories
.next/cache/: found 18 matching files and directories
public: found 925 matching files and directories
untracked: found 21814 files
No URL provided, cache will be not uploaded to shared cache server. Cache will be stored only locally.
Created cache
所以应该是缓存:
node_modules/
.next/cache/
public
我的理解是,在下一个管道 运行 的下一个 git clone
之后,GitLab CI 应该在克隆的存储库之上恢复缓存。 (或者通过卷装载使缓存可用,但我无法在 /cache
或 ./cache
中找到它。)
在下一次提交中打印出 public
的内容表明情况并非如此。
但从表面上看,缓存已恢复:
Fetching changes with git depth set to 50...
Initialized empty Git repository in
Created fresh repository.
Checking out d7d84cd8 as main...
Skipping Git submodules setup
Restoring cache
Checking cache for default-4...
No URL provided, cache will not be downloaded from shared cache server. Instead a local version of cache will be extracted.
Successfully extracted cache
缓存应该在哪里?
我应该如何检查它是否正常工作?
附录:
从 Next.js 的角度来看,此消息表明 Next.js 也没有从缓存中受益:
warn - No build cache found. Please configure build caching for faster rebuilds. Read more: https://nextjs.org/docs/messages/no-cache
我 the lines that they suggest you merge into your .gitlab-ci.yml
可以利用缓存。
您尚未配置分布式缓存,因此您的缓存仅在上传缓存时本地存储在运行作业的特定运行器上。
跑步者之间不共享缓存。因此,如果您有多个跑步者,如果您的工作被与上次不同的跑步者接管,则缓存可能不可用。这是因为 GitLab 假设不同的运行器可能位于不同的平台和架构上,缓存文件可能取决于这些环境因素(例如,为了二进制兼容性)。如果您有多个运行器或正在使用自动缩放功能,则需要配置 distributed caching.
如果您只有一个跑步者但仍然遇到此问题,请确保您的配置没有 cache mismatching problem。
您作业中的日志消息表明正在成功创建和恢复缓存(从本地缓存)。
Is S3 required for shared runners?
如果您有多个运行器,或者如果您使用上述自动缩放配置,则需要分布式缓存。但是,您不必为此使用 AWS S3,只需使用 S3-compatible 对象存储即可。例如,您可以 self-host minio 它提供(除其他外)与 S3 兼容的对象存储服务器。
Or make the cache available via a volume mount, but I haven't been able to find it in /cache or ./cache.
这是从 runner pod 的角度来看的。 runner 会自动将压缩缓存(如果存在)从 /cache
(安装到 runner pod)中提取到构建目录。乔布斯不会直接访问 /cache
挂载!但是,如果您想手动检查 runner pod 上的缓存,了解这一点是很好的。
您可以通过登录运行器 pod 上的 shell(使用 kubectl exec -it <your-runner-pod-name> /bin/sh
)并检查 /cache
目录和其中的任何压缩存档来检查缓存。
确保您的运行器配置为使用分布式缓存 - https://docs.gitlab.com/runner/configuration/autoscale.html#distributed-runners-caching
如果要使用缓存,则必须设置分布式缓存。
如果要设置分布式缓存,则必须设置 S3 兼容的对象存储。
没有 out-of-the-box 不支持没有对象存储的缓存。
即使您为每个构建使用相同的运行器,它也不会持续存在。