如何在Docker Cloud的Dockerfile中正确初始化git子模块



我们正在Docker Cloud上构建一个Docker容器。构建过程需要git子模块。

为了初始化本地构建的子模块,我们在Dockerfile中添加了以下行:

RUN git submodule update --init --recursive

请参阅:https://github.com/open62541/open62541/blob/master/Dockerfile#L9

相应的提交:https://github.com/open62541/open62541/commit/ee9c18a6a05722edfe7c0d8d8e140d802fa2e5f2和拉取请求:
https://github.com/open62541/open62541/pull/3191

注意:与类似问题相反,所有子模块都是github上的公共转发,无需身份验证。

没有子模块初始化行的情况:

  • 构建Docker云:成功
    https://cloud.docker.com/u/open62541/repository/registry-1.docker.io/open62541/open62541/builds/dcd3283c-76af-4f6b-bb00-cecbaaffc82f
  • 本地生成:失败
git clone https://github.com/open62541/open62541.git
cd open62541
# Parent commit without git submodule update
git checkout e97abd591a159ce894488d93796b858d9f0d00b9
# This will fail because the submodules are obviously not initialized
docker build .

错误:

CMake Error at CMakeLists.txt:830 (message):
File /opt/open62541/deps/ua-nodeset/Schema/Opc.Ua.NodeSet2.xml not found.
You probably need to initialize the git submodule for deps/ua-nodeset.

Dockerfile中子模块初始化的情况:

  • 在Docker Cloud上构建:失败
    https://cloud.docker.com/u/open62541/repository/registry-1.docker.io/open62541/open62541/builds/28663705-c324-4c7f-a084-f94eb80057bc
Step 7/18 : RUN git submodule update --init --recursive
---> Running in b358c21c4d53
fatal: not a git repository: /src/b6tohshrfzzntavvhek3zna/.git/modules/deps/mdnsd
Unable to find current revision in submodule path 'deps/mdnsd'
  • 本地构建:成功
git clone https://github.com/open62541/open62541.git
cd open62541
# Commit which added git submodule init in Dockerfile
git checkout ee9c18a6a05722edfe7c0d8d8e140d802fa2e5f2
# This will succeed
docker build .

如何正确初始化Docker文件中的子模块,使其在Docker云上工作,同时可以提取主repo并构建Docker容器


相关问题:

  • Docker云子模块认证
    私有git子模块。没有答案
  • 带有git子模块的Google容器生成器DockerFile
    私有git子模件。与Google Container Builder相关
  • Docker Hub和git子模块
    Docker Hub,但与私有子模块相关
  • docker自动构建git私有子模块
    docker Hub,但与私有子模块相关

请参阅我在此处给出的答案:https://stackoverflow.com/a/59640438/1021344

为简便起见,在此复制:您需要使用挂钩:https://docs.docker.com/docker-hub/builds/advanced/#custom-构建阶段挂钩

TL;DR:将其放入hooks/post_checkout:

#!/bin/bash
# Docker hub does a recursive clone, then checks the branch out,
# so when a PR adds a submodule (or updates it), it fails.
git submodule update --init

相关内容

  • 没有找到相关文章

最新更新