在 Gitlab CI 中缓存 Rust/Wasm 工具?

Caching Rust/Wasm tools in Gitlab CI?

我正在使用 Wasm 和 Rust,我正在使用 gitlab 页面部署页面。

我正在使用 gitlab-ci.yml 文件,如下所示:

image: "rust:latest"

variables:
  PUBLIC_URL: "/repo-name"

pages:
  stage: deploy
  script:
    - rustup target add wasm32-unknown-unknown
    - cargo install wasm-pack
    - wasm-pack build --target web
    - mkdir public
    - mv ./pkg ./public/pkg
    - cp ./index.html ./public/index.html
  artifacts:
    paths:
      - public

但即使是“Hello World”应用,这也需要大约 12 分钟。

~cargo install wasm-pack 步骤占用了其中的 11 分钟。

有什么方法可以缓存中间步骤,以避免每次都这样做吗?

此页面:Caching in GitLab CI/CD 讨论缓存 and/or 使用工件在作业之间持久保存文件。您也许可以利用它。

然后就变成了如何让 cargo install 使用该缓存或保存的工件的问题。

或者,您可以定义自己的基础构建映像(运行 其中的 cargo install 步骤),并将其存储在 Gitlab 的 docker 注册表中;参见 https://docs.gitlab.com/ee/user/packages/container_registry/