首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >在``ubuntu latest`‘中创建的缓存无法在Docker容器中恢复

在``ubuntu latest`‘中创建的缓存无法在Docker容器中恢复
EN

Stack Overflow用户
提问于 2022-01-18 18:58:17
回答 3查看 262关注 0票数 1

这是我的工作流文件:

代码语言:javascript
复制
name: Build Pipeline
on: push
env:
  NODE_VERSION: 11

jobs:
  build:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v2
      - uses: actions/setup-node@v2
        with:
          node-version: ${{ env.NODE_VERSION }}
      - id: cache-node-modules
        uses: actions/cache@v2
        with:
          path: ${{ github.workspace }}/node_modules
          key: node_modules-${{ hashFiles('package-lock.json') }}
          restore-keys: node_modules
      - uses: actions/cache@v2
        with:
          path: ${{ github.workspace }}/build
          key: build-${{ github.sha }}
          restore-keys: build
      - if: steps.cache-node-modules.outputs.cache-hit != 'true'
        run: npm install
      - run: npm run build -- --incremental
  npm-scripts:
    needs: [build]
    runs-on: ubuntu-latest
    strategy:
      matrix:
        script: ['lint:pipeline', 'lint:exports', 'i18n:pipeline', 'schema:validate']
    steps:
      - uses: actions/checkout@v2
      - uses: actions/setup-node@v2
        with:
          node-version: ${{ env.NODE_VERSION }}
      - id: cache-node-modules
        uses: actions/cache@v2
        with:
          path: ${{ github.workspace }}/node_modules
          key: node_modules-${{ hashFiles('package-lock.json') }}
      - if: steps.cache-node-modules.outputs.cache-hit != 'true'
        run: |
          echo 'Expected to have a cache hit for "node_modules", since this job runs after the "build" job, which caches the latest version of "node_modules". Not having a cache hit means probably there is a bug with the workflow file.'
          exit 1
      - id: cache-build-output
        uses: actions/cache@v2
        with:
          path: ${{ github.workspace }}/build
          key: build-${{ github.sha }}
      - if: steps.cache-build-output.outputs.cache-hit != 'true'
        run: |
          echo 'Expected to have a cache hit for the build output folder, since this job runs after the "build" job, which caches the latest version of the "build" folder. Not having a cache hit means probably there is a bug with the workflow file.'
          exit 1
      - run: npm run ${{ matrix.script }}
  jest-tests:
    needs: [build]
    runs-on: ubuntu-latest
    container: node:11
    services:
      postgres:
        image: postgres
        env:
          POSTGRES_DB: localhost
          POSTGRES_USER: postgres
          POSTGRES_PASSWORD: password
      redis:
        image: redis
    steps:
      - uses: actions/checkout@v2
      - id: cache-node-modules
        uses: actions/cache@v2
        with:
          path: ${{ github.workspace }}/node_modules
          key: node_modules-${{ hashFiles('package-lock.json') }}
      - if: steps.cache-node-modules.outputs.cache-hit != 'true'
        run: |
          echo 'Expected to have a cache hit for "node_modules", since this job runs after the "build" job, which caches the latest version of "node_modules". Not having a cache hit means probably there is a bug with the workflow file.'
          exit 1
      - id: cache-build-output
        uses: actions/cache@v2
        with:
          path: ${{ github.workspace }}/build
          key: build-${{ github.sha }}
      - if: steps.cache-build-output.outputs.cache-hit != 'true'
        run: |
          echo 'Expected to have a cache hit for the build output folder, since this job runs after the "build" job, which caches the latest version of the "build" folder. Not having a cache hit means probably there is a bug with the workflow file.'
          exit 1
      - run: echo

node_modulesbuild文件夹缓存在build作业中。这些缓存可以在npm-scripts作业中没有问题的情况下恢复。但是,无法在jest-tests作业中还原它们,在该作业中,它将得到一个Cache not found for input keys错误。

我不知道这是怎么可能的,因为完全相同的缓存键能够在所有npm-scripts作业中不出问题地被还原。

当我移除:

代码语言:javascript
复制
container: node:11
services:
  postgres:
    image: postgres
    env:
      POSTGRES_DB: localhost
      POSTGRES_USER: postgres
      POSTGRES_PASSWORD: password
  redis:
    image: redis

部分(因此允许作业在ubuntu-latest上运行,而不是Docker容器),缓存能够再次正确地恢复。所以不知道这是怎么回事。

EN

回答 3

Stack Overflow用户

发布于 2022-03-14 01:41:46

如果您正在运行的容器中的路径中没有可用的@actions/cache二进制文件,那么似乎zstd作业就会悄然失败。这可能是您的节点容器的情况。

我通过在存储库机密中将ACTIONS_STEP_DEBUG设置为true来发现这一点。调试日志显示该操作试图运行zstd,但无法运行,但它被报告为缓存丢失。一旦我知道了这一点,我就发现有一个bug报告正在为它打开:https://github.com/actions/cache/issues/580

票数 1
EN

Stack Overflow用户

发布于 2022-01-19 00:11:50

这是个奇怪的虫子。我发现的解决方法不是在容器中运行jest-tests作业。也就是说,在常规的ubuntu-latest机器中运行ubuntu-latest作业,并映射服务容器端口,如:

代码语言:javascript
复制
jest-tests:
  needs: [build]
  runs-on: ubuntu-latest
  services:
    postgres:
      image: postgres
      ports:
        - 5432:5432
      env:
        POSTGRES_DB: localhost
        POSTGRES_USER: postgres
        POSTGRES_PASSWORD: password
    redis:
      image: redis
      ports:
        - 6379:6379
票数 0
EN

Stack Overflow用户

发布于 2022-10-24 14:48:32

我使用的是自定义映像,只需将zstd包添加到映像中,就可以使操作/缓存工作。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/70761005

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档