element-hq / element-web

A glossy Matrix collaboration client for the web.
https://element.io
GNU Affero General Public License v3.0
11.01k stars 1.96k forks source link

docker build fails when initialized as a git submodule #14031

Open rrix opened 4 years ago

rrix commented 4 years ago

Description

I have a repository where I manage all of my personal services' dockerfiles so that I can build them from source rather than have to worry about Docker, Inc. images in threat models. It's a makefile and a bunch of git submodules.

When riot-web is added a submodule, .git looks like this:

rrix@kusanagi:~/Code/dockerfiles/riot-web :) file .git
.git: ASCII text
rrix@kusanagi:~/Code/dockerfiles/riot-web :) cat .git
gitdir: ../.git/modules/riot-web

the Dockerfile copies the source in to the container, including this submodule stub, but obviously not the .git directory itself. I believe I could work around this by converting it to a git subtree, but this feels like a bad compromise, I am using submodules in their intended usecase right now.

Since this is a personal build for one user, I am comfortable simply removing the RUN docker-write-version command, but perhaps there's a solution to this worth considering, or at least documenting for the next person to try to do this.

Steps to reproduce

mkdir /tmp/dockerfiles
git init /tmp/dockerfiles 
git -C /tmp/dockerfiles submodule add https://github.com/vector-im/riot-web/
docker build /tmp/dockerfiles/riot-web/ -t riot-web:scratchbuild

Version information

For the web app:

rrix commented 4 years ago

This will also prevent using custom SDKs in the script/docker-link-repos.sh too for submodule users, not just the version string script.

rrix commented 4 years ago

my Makefile rule looks like this, to disable these two scripts from the root of my dockerfile repository:

rrix/riot-web: riot-web/*
    git -C riot-web/ fetch
    git -C riot-web/ checkout ${RIOT_WEB_VERSION}
    sed -i -e "/docker-write-version.sh/d" riot-web/Dockerfile
    sed -i -e "/docker-link-repos.sh/d" riot-web/Dockerfile
    docker build riot-web/ -t rrix/riot-web
t3chguy commented 1 year ago

With how docker contexts work, there's no way for it to access the parent directory so this seems like quite an incompatibility.