【问题标题】:Github actions/cache@v2: unrecognized option: posix in the post jobGithub actions/cache@v2: unrecognized option: posix in post job
【发布时间】:2020-10-04 03:03:09
【问题描述】:

我正在使用 Github Actions 在我的项目中实施 CI 管道。目前,我正在尝试使用 actions/cache@v2 来缓存 yarn cache dir 以改善管道时间。不幸的是,总是在操作/缓存@v2 运行时,我在作业后遇到错误:/bin/tar: unrecognized option: posix。完整的日志是:

Post job cleanup.
/usr/bin/docker exec  4decc52e7744d9ab2e81bb24c99a830acc848912515ef1e86fbb9b8d5049c9cf sh -c "cat /etc/*release | grep ^ID"
/bin/tar --posix -z -cf cache.tgz -P -C /__w/open-tuna-api/open-tuna-api --files-from manifest.txt
/bin/tar: unrecognized option: posix
BusyBox v1.31.1 () multi-call binary.

Usage: tar c|x|t [-ZzJjahmvokO] [-f TARFILE] [-C DIR] [-T FILE] [-X FILE] [--exclude PATTERN]... [FILE]...

Create, extract, or list files from a tar file

    c   Create
    x   Extract
    t   List
    -f FILE Name of TARFILE ('-' for stdin/out)
    -C DIR  Change to DIR before operation
    -v  Verbose
    -O  Extract to stdout
    -m  Don't restore mtime
    -o  Don't restore user:group
    -k  Don't replace existing files
    -Z  (De)compress using compress
    -z  (De)compress using gzip
    -J  (De)compress using xz
    -j  (De)compress using bzip2
    -a  (De)compress using lzma
    -h  Follow symlinks
    -T FILE File with names to include
    -X FILE File with glob patterns to exclude
    --exclude PATTERN   Glob pattern to exclude
Warning: Tar failed with error: The process '/bin/tar' failed with exit code 1

我按照官方action cache repository的例子。这是我的 CI.yml 的 sn-p

  # Configure cache
  - name: Get yarn cache directory path
    id: yarn-cache-dir-path
    run: echo "::set-output name=dir::$(yarn cache dir)"

  - uses: actions/cache@v2
    id: yarn-cache # use this to check for `cache-hit` (`steps.yarn-cache.outputs.cache-hit != 'true'`)
    with:
      path: ${{ steps.yarn-cache-dir-path.outputs.dir }}
      key: ${{ runner.os }}-yarn-${{ hashFiles('yarn.lock') }}
      restore-keys: |
        ${{ runner.os }}-yarn-

由于上述错误,没有创建缓存,也没有提高流水线时间。我尝试更改 hasFiles 表达式和整个密钥,但没有成功。

我的问题是:我在使用 Action Cache 时是否犯了一些错误?谁能帮我解决这个问题?谢谢。

【问题讨论】:

  • 您是在使用非标准的PATH 还是在 Docker 容器或其他非默认操作系统中运行此操作?
  • @bk2204 是的,它在 Docker 容器中运行。您可以访问完整的工作流文件here

标签: github github-actions


【解决方案1】:

您的问题是您在基于 Alpine Linux 的容器中运行。 Alpine Linux 是为小尺寸而设计的,因此它用busybox(一个多调用二进制文件)替换了许多标准的GNU 实用程序。你的tar 就是其中之一。

actions/cache@v2 操作使用tar --posix,它告诉tar 创建一个标准的pax 格式存档。 pax 归档是 tar 归档的一种形式,它可以处理任意长的文件名、巨大的文件大小以及 tar 归档无法处理的其他类型的元数据。这种格式由 POSIX 指定,是比 GNU tar 样式存档更好的选择,因为它适用于各种系统,并且除了功能更丰富之外,它并不受单一实现的指定。

但是,作为busybox 的一部分提供的tar 版本不支持--posix 选项,因此该命令会失败。如果您想使用actions/cache@v2 GitHub Action,那么您需要在运行之前在您的PATH 中提供早期版本的 GNU 或 BSD(libarchive)tar,以便可以使用该命令代替busybox。

【讨论】:

  • 感谢您的回答。那么,您的建议是将 Alpine Linux 更改为另一个发行版吗?还是有其他方法可以实现相同的目标?谢谢!
  • 您可以使用与 Alpine 不同的发行版(有基于 Debian 的节点映像)或安装不同的 tar 实现(例如 bsdtar 或 GNU tar)并将其放在您的 PATH 中。
  • 您可以运行apk add --no-cache tar 来获取兼容的tar。
猜你喜欢
  • 2022-12-19
  • 2020-10-29
  • 2022-10-05
  • 2022-11-11
  • 2020-01-15
  • 2020-01-14
  • 2021-08-30
  • 2020-04-15
  • 2020-09-06
相关资源
最近更新 更多