kaniko icon indicating copy to clipboard operation
kaniko copied to clipboard

Use a subdirectory in git repo as docker context

Open rkamradt opened this issue 5 years ago • 4 comments

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.

rkamradt avatar Feb 18 '20 20:02 rkamradt

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?

cvgw avatar Feb 29 '20 01:02 cvgw

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.

rkamradt avatar Mar 08 '20 15:03 rkamradt

check https://github.com/GoogleContainerTools/kaniko#context-sub-path

caarlos0 avatar Jun 15 '20 18:06 caarlos0

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.

mickvangelderen avatar Jul 09 '24 09:07 mickvangelderen