Docker Hub and git submodules

送分小仙女□ 提交于 2020-01-24 19:23:28

问题


I have a repository that uses git submodules, and I configured the automated build on Docker Hub. At the beginning of the build process, it looks like Docker Hub pulls the repository from the default branch (master), update submodules and then checkout to the particular branch (let's say branch feature-a) that triggered the build. It works fine if feature-a branch has the very same submodules as master, but if the submodules are different (let's say, pull one submodule from a different repo), the build fails.

Is there a way to make Docker Hub clone the correct branch directly?


回答1:


It might be failing because the submodule is private.

You can add a build environment variable SSH_PRIVATE. And add a private key with access to the private submodule repository.

A word of caution though… you may want to generate a diff private key than the one you use for anything else and add that to the private submodules repo.

Edit: This is required even if your linked github account has access to the repo because you're most likely specifying the submodule url as ssh based (e.g. git@github.com:Account/repo.git)

Edit2: Adding docs https://docs.docker.com/docker-hub/builds/#build-repositories-with-linked-private-submodules




回答2:


You need to use hooks: https://docs.docker.com/docker-hub/builds/advanced/#custom-build-phase-hooks

TL;DR: Place this in 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


来源:https://stackoverflow.com/questions/54055666/docker-hub-and-git-submodules

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!