繁体   English   中英

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

我有他们建议您合并到.gitlab-ci.yml以利用缓存的行

您尚未配置分布式缓存,因此您的缓存仅在本地存储在缓存上传时运行作业的特定运行器上。

跑步者之间不共享缓存。 因此,如果您有多个跑步者,如果您的作业被与上次不同的跑步者接手,则缓存可能不可用。 这是因为 GitLab 假设不同的运行器可能位于不同的平台和架构上,并且缓存文件可能取决于这些环境因素(例如二进制兼容性)。 如果您有多个跑步者或正在使用自动缩放功能,则需要配置分布式缓存

如果您只有一个运行器但仍然存在此问题,请确保您的配置没有缓存不匹配问题

您的作业中的日志消息表明缓存正在成功创建和恢复(从本地缓存)。

共享跑步者是否需要 S3?

如果您有多个运行器或者如果您使用如上所述的自动缩放配置,则需要分布式缓存。 但是,您不必为此使用AWS S3,只需使用与 S3兼容的对象存储即可。 例如,您可以自托管提供(除其他外)与 S3 兼容的对象存储服务器的minio

或者通过卷挂载使缓存可用,但我无法在 /cache 或 ./cache 中找到它。

这是从跑步者吊舱的角度来看的。 runner 会自动从/cache (挂载到 runner pod)中提取压缩缓存(如果存在)到构建目录。 Jobs 不会直接访问/cache挂载! 但是,如果您想手动检查 runner pod 上的缓存,最好知道这一点。

您可以通过登录 runner pod 上的 shell(使用kubectl exec -it <your-runner-pod-name> /bin/sh )并检查/cache目录和其中的任何压缩档案来检查缓存。

如果要使用缓存,则必须设置分布式缓存。

如果要设置分布式缓存,则必须设置与 S3 兼容的对象存储。

没有对象存储的缓存没有开箱即用的支持。

即使您为每个构建使用相同的运行器,它也不会持续存在。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM