【问题标题】:Docker COPY fails Github actions with git lfsDocker COPY 使用 git lfs 使 Github 操作失败
【发布时间】:2021-03-04 11:14:41
【问题描述】:

我正在使用 Github 操作使用来自 git lfs 的文件构建 docker 映像。
我有以下步骤:

     - 
        name: Checkout code
        uses: actions/checkout@v2
        with:
          lfs: true
      - 
        run: head something.json

正确打印数据。

当我在构建阶段从我的 dockerfile 运行相同的命令时,
我得到以下 lfs 元数据:

#7 [4/5] RUN head something.json
#7 sha256:***
#7 0.138 version https://git-lfs.github.com/spec/v1
#7 0.138 oid sha256:***
#7 0.138 size 1230424
#7 DONE 0.2s

Dockerfile:

FROM bitnami/python:3.9.1

COPY . .

RUN head something.json

行动:

jobs:
  build-image:
    runs-on: ubuntu-latest
    steps:
      - 
        name: Checkout code
        uses: actions/checkout@v2
        with:
          lfs: true
      - 
        run: head something.json
      -
        name: Set up QEMU
        uses: docker/setup-qemu-action@v1
      -
        name: Set up Docker Buildx
        uses: docker/setup-buildx-action@v1
      -
        name: Build and push
        id: docker_build
        uses: docker/build-push-action@v2
        with:
          push: true
          file: Dockerfile

为什么 docker build 采用元数据而不是实际文件?

【问题讨论】:

  • 我们缺少一些东西。您的输出显示步骤 4/5,但您的 Dockerfile 只有 3 个步骤。这些缺失的步骤之一可能就是问题所在。

标签: git docker github continuous-integration github-actions


【解决方案1】:

修复

在你的 git checkout 之后运行这一步:

- run: git lfs pull

并添加到您的 docker build 操作中:

with:
  context: .

关于这个 repo 的完整示例:https://github.com/roim/docker-action-lfs

为什么?

2 个单独的问题:

  1. docker/build-push-action@v2 中的 docker 构建未使用您指定的结帐操作中的 git 存储库。您可以通过阅读该操作的日志并验证它再次将 git repo 拉入新文件夹来确认:
/usr/bin/docker buildx build --tag ***/www:latest --iidfile *** --secret id=*** --file ./Dockerfile --push https://github.com/***/www.git#heads/main
#1 [internal] load git source https://github.com/***/www.git#heads/main
#1 sha256:***
#1 0.013 Initialized empty Git repository in /var/lib/buildkit/runc-overlayfs/snapshots/snapshots/1/fs/
#1 0.334 ***    refs/heads/main
#1 0.622 From https://github.com/***/www
#1 0.622  * [new branch]      main       -> heads/main
#1 0.623  * [new branch]      main       -> origin/main
  1. The default checkout action seems to fetch LFS objects, but not resolve them in the working directory。显式运行 git lfs pull 将解决此问题。

--

请注意,DockerHub 不支持 git-lfs 的 a long standing issue reported in 2015 是 DockerHub 特有的,而不是 github 操作。

至于为什么默认上下文不尊重 lfs,I opened a new issue for that

【讨论】:

  • 谢谢!我花了几个小时试图弄清楚这一点。你的解决方案对我有用。关于第二个问题(GitHub Action 不拉取 LFS 资源):现在好像已经修复了,我在使用ubuntu-latest worker 时没有遇到这个问题。
猜你喜欢
  • 2021-10-01
  • 1970-01-01
  • 2020-10-06
  • 2021-10-29
  • 2021-05-16
  • 2021-11-13
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多