Use a subdirectory in git repo as docker context
I have a use case where I want to build from a git repo with Kaniko. However, I have some git repos that have several projects in subdirectories with a Dockerfile and the application code in each subdirectory. I can't find a way with Kaniko to set the docker context to anything other than the root of the repo.
My current work-around is to copy the Dockerfiles in each subdirectory to the root directory, rename them, and edit them to reference the files in the subdirectory for each application.
Here is the script with the work-around https://github.com/rkamradt/batchjobs/blob/master/buildimage.yaml
The preferred parameter usage would be --dockerfile=hellokworld/Dockerfile and to have the docker context inferred from the directory the Dockerfile is in, or a seperate parameter to point into the context established by the git URL.
I would prefer this is not done via inferring the context from the Dockerfile path; I think that will cause unexpected behavior.
My suggestion would be that we update the code to allow subpaths on a git context.
E.G. --context=git://github.com/foo/bar.git/sub/path#master
@tejal29 wdyt?
I closed the #1065 PR as it was committed on the wrong computer so it didn't pass the CLA. I have recreated it as PR #1078. This is a possible solution using the # separator to give the path at the end of the context.
check https://github.com/GoogleContainerTools/kaniko#context-sub-path
Updated link to context-sub-path.
Can this issue be closed as completed? The OP stated "I can't find a way with Kaniko to set the docker context to anything other than the root of the repo." and --context-sub-path solves that.