问题
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