diff --git a/pkg/buildcontext/buildcontext.go b/pkg/buildcontext/buildcontext.go index dea56fe6b..032f69fac 100644 --- a/pkg/buildcontext/buildcontext.go +++ b/pkg/buildcontext/buildcontext.go @@ -18,8 +18,9 @@ package buildcontext import ( "errors" - "github.com/GoogleContainerTools/kaniko/pkg/constants" "strings" + + "github.com/GoogleContainerTools/kaniko/pkg/constants" ) // BuildContext unifies calls to download and unpack the build context. @@ -41,6 +42,8 @@ func GetBuildContext(srcContext string) (BuildContext, error) { return &S3{context: context}, nil case constants.LocalDirBuildContextPrefix: return &Dir{context: context}, nil + case constants.GitBuildContextPrefix: + return &Git{context: context}, nil } - return nil, errors.New("unknown build context prefix provided, please use one of the following: gs://, dir://, s3://") + return nil, errors.New("unknown build context prefix provided, please use one of the following: gs://, dir://, s3://, git://") } diff --git a/pkg/buildcontext/git.go b/pkg/buildcontext/git.go new file mode 100644 index 000000000..1aa8691be --- /dev/null +++ b/pkg/buildcontext/git.go @@ -0,0 +1,39 @@ +/* +Copyright 2018 Google LLC + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +package buildcontext + +import ( + "os" + + "github.com/GoogleContainerTools/kaniko/pkg/constants" + git "gopkg.in/src-d/go-git.v4" +) + +// Git unifies calls to download and unpack the build context. +type Git struct { + context string +} + +// UnpackTarFromBuildContext will provide the directory where Git Repository is Cloned +func (g *Git) UnpackTarFromBuildContext() (string, error) { + directory := constants.BuildContextDir + _, err := git.PlainClone(directory, false, &git.CloneOptions{ + URL: "https://" + g.context, + Progress: os.Stdout, + }) + return directory, err +} diff --git a/pkg/constants/constants.go b/pkg/constants/constants.go index bcc658fca..5a356801c 100644 --- a/pkg/constants/constants.go +++ b/pkg/constants/constants.go @@ -54,6 +54,7 @@ const ( GCSBuildContextPrefix = "gs://" S3BuildContextPrefix = "s3://" LocalDirBuildContextPrefix = "dir://" + GitBuildContextPrefix = "git://" // DefaultHOMEValue is the default value Docker sets for $HOME HOME = "HOME"