问题描述
我正在使用Github动作来构建git lfs中的文件的docker镜像.
我有以下步骤:
I am using Github actions to build docker images with a file from git lfs.
I have the following step:
-
name: Checkout code
uses: actions/checkout@v2
with:
lfs: true
-
run: head something.json
可以正确打印数据.
在构建阶段从dockerfile运行相同命令时,
我得到以下lfs元数据:
When I run the same command from my dockerfile in the build stage,
I get the following lfs metadata:
#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:
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构建采用元数据而不是实际文件?
Why the docker build takes the metadata and not the actual file?
推荐答案
修复
在git checkout之后运行此步骤:
The fix
Run this step after your git checkout:
- run: git lfs pull
并添加到您的docker build操作:
And add to your docker build action:
with:
context: .
此仓库中的完整示例: https://github.com/roim/docker-行动lfs
Fully working example on this repo: https://github.com/roim/docker-action-lfs
2个独立问题:
-
docker/build-push-action @ v2
中的docker构建未使用您指定的checkout操作中的git repo.您可以通过读取该操作的日志并确认该操作将git repo再次拉入新文件夹来进行确认:
- The docker build in
docker/build-push-action@v2
isn't using the git repo from the checkout action you specified. You can confirm by reading logs for that action and verifying it pulls a git repo again, into a new folder:
/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
- 默认的结帐操作似乎来获取LFS对象,但不能在工作目录中解析它们.明确运行
git lfs pull
将解决此问题.
- The default checkout action seems to fetch LFS objects, but not resolve them in the working directory. Explicitly running
git lfs pull
will fix that.
-
请注意, 2015年报道了一个长期存在的问题,其中DockerHub不支持git-lfs-特定于DockerHub,而不是github操作.
Note that there is a long standing issue reported in 2015 where DockerHub doesn't support git-lfs--that's specific to DockerHub, not github actions.
关于默认上下文为何不遵循lfs的原因,我打开了一个的新问题.
As to why the default context doesn't respect lfs, I opened a new issue for that.
这篇关于Docker COPY使用git lfs使Github操作失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!