Michael Okoko
Posted on October 25, 2019
I was following some Docker/Kubernetes tutorial some time back, and all was bright and good until it wasn't. Travis was failing with the error "unable to prepare context: unable to evaluate symlinks in Dockerfile path" and the script causing the build to fail look like this:
docker build -t [secure]/client-test -f client/Dockerfile.dev ./client
It was weird to me because I just used the same command to build and tag the docker image locally, so I tried, again and again to replicate on local - but local worked every damn time.
Now, in most cases when this error happens, it is caused by a wrongly typed folder/file name, or an incorrect file reference, and you can just double-check to get it fixed. But this case was different!
What really happened? Submodules!
I removed the script instruction that was the culprit and watched the logs till I found something interesting, building the particular image for production was failing too, but all others were passing. At this point, it was becoming clear that my headache might have been caused by something around symlinks or so (it should have hit me from the error message anyway but e dey happen). I went back to Github, mindlessly looking at the repo and noticed this:
Ha! My fear was confirmed!
What are Submodules again?
Sub-module is Git's way of enabling you keep a git repository within another while maintaining their commit history separately. It's like having a project within a project. Gitbook has a quite solid explanation on how it works.
So here is how it happened:
create-react-app
automatically generated a git repository when it created the application (the client folder in this case), and I only initialized the repo on the parent folder after creating this react app. Somehow, the inner client directory (the react app) then became a submodule, and my naive self thought that deleting the .git
folder in that inner folder was enough to get me a smooth ride.
The fix.
Fixing it is as simple as removing the submodule and re-adding the folder to your staging like so:
# delete the submodule reference
git rm --cached submodule_path
# remove the inner .git dir if it still exists
rm -rf submodule_path/.git
# re-add the directory to the main repository
git add submodule_path
# commit and profit
git commit -m "removed git submodule"
and that is all.
Posted on October 25, 2019
Join Our Newsletter. No Spam, Only the good stuff.
Sign up to receive the latest update from our blog.