Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Docker Hub and git submodules

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?

like image 505
Felipe Cecagno Avatar asked Jan 05 '19 19:01

Felipe Cecagno


2 Answers

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
like image 174
Geod24 Avatar answered Nov 07 '22 11:11

Geod24


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. [email protected]:Account/repo.git)

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

like image 21
Clintm Avatar answered Nov 07 '22 11:11

Clintm