From d78e77fb928a4213078ef46693bab61c8dfb2769 Mon Sep 17 00:00:00 2001 From: Luke Swithenbank Date: Thu, 13 Sep 2018 09:56:04 +1000 Subject: [PATCH] fix remote build's for subdirectories --- examples/remoteBuild.md | 13 ++++++++++++- pkg/loader/githubloader.go | 16 +++++++++++----- 2 files changed, 23 insertions(+), 6 deletions(-) diff --git a/examples/remoteBuild.md b/examples/remoteBuild.md index 63073deac..747724fca 100644 --- a/examples/remoteBuild.md +++ b/examples/remoteBuild.md @@ -16,6 +16,17 @@ test 3 == \ echo $? ``` +Overlays can be remote as well: + + + +``` +target=github.com/kubernetes-sigs/kustomize//examples/multibases/dev/?ref=v1.0.6 +test 1 == \ + $(kustomize build $target | grep cluster-a-dev-myapp-pod | wc -l); \ + echo $? +``` + A base can also be specified as a URL: @@ -55,4 +66,4 @@ Here are some example urls pointing to Github repos following this convention. `github.com/Liujingfang1/kustomize//examples/helloWorld?ref=repoUrl2` - a subdirectory in a repo on commit `7050a45134e9848fca214ad7e7007e96e5042c03` - `github.com/Liujingfang1/kustomize//examples/helloWorld?ref=7050a45134e9848fca214ad7e7007e96e5042c03` \ No newline at end of file + `github.com/Liujingfang1/kustomize//examples/helloWorld?ref=7050a45134e9848fca214ad7e7007e96e5042c03` diff --git a/pkg/loader/githubloader.go b/pkg/loader/githubloader.go index c60e54093..00e0da513 100644 --- a/pkg/loader/githubloader.go +++ b/pkg/loader/githubloader.go @@ -29,14 +29,17 @@ import ( // githubLoader loads files from a checkout github repo type githubLoader struct { - repo string + repo string + // target is the directory which is to be built + targetDir string + // checkoutDir is for the whole repository checkoutDir string loader *fileLoader } // Root returns the root location for this Loader. func (l *githubLoader) Root() string { - return l.checkoutDir + return l.targetDir } // New delegates to fileLoader.New @@ -60,15 +63,18 @@ func newGithubLoader(repoUrl string, fs fs.FileSystem) (*githubLoader, error) { if err != nil { return nil, err } - target := filepath.Join(dir, "repo") - err = checkout(repoUrl, target) + repodir := filepath.Join(dir, "repo") + src, subdir := getter.SourceDirSubdir(repoUrl) + err = checkout(src, repodir) if err != nil { return nil, err } + target := filepath.Join(repodir, subdir) l := newFileLoaderAtRoot(target, fs) return &githubLoader{ repo: repoUrl, - checkoutDir: dir, + targetDir: target, + checkoutDir: repodir, loader: l, }, nil }