Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding Git Buildcontext #332

Closed
wants to merge 18 commits into from
Closed
Show file tree
Hide file tree
Changes from 8 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
166 changes: 165 additions & 1 deletion Gopkg.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions Gopkg.toml
Original file line number Diff line number Diff line change
Expand Up @@ -38,3 +38,7 @@ required = [
[[override]]
name = "k8s.io/apimachinery"
version = "kubernetes-1.11.0"

[[constraint]]
name = "gopkg.in/src-d/go-git.v4"
version = "4.6.0"
1 change: 1 addition & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ VERSION_BUILD ?= 0
VERSION ?= v$(VERSION_MAJOR).$(VERSION_MINOR).$(VERSION_BUILD)
VERSION_PACKAGE = $(REPOPATH/pkg/version)

SHELL := /bin/bash
krtkvrm marked this conversation as resolved.
Show resolved Hide resolved
GOOS ?= $(shell go env GOOS)
GOARCH = amd64
ORG := github.com/GoogleContainerTools
Expand Down
6 changes: 5 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ To use kaniko to build and push an image for you, you will need:

### kaniko Build Contexts

kaniko currently supports local directories, Google Cloud Storage and Amazon S3 as build contexts.
kaniko currently supports local directories, Google Cloud Storage, Amazon S3 and Git Repositories as build contexts.
If using a GCS or S3 bucket, the bucket should contain a compressed tar of the build context, which kaniko will unpack and use.

To create a compressed tar, you can run:
Expand All @@ -77,10 +77,14 @@ Use the `--context` flag with the appropriate prefix to specify your build conte
| Local Directory | dir://[path to directory] |
| GCS Bucket | gs://[bucket name]/[path to .tar.gz] |
| S3 Bucket | s3://[bucket name]/[path to .tar.gz] |
| Git Repository | git://[repository url] |

If you don't specify a prefix, kaniko will assume a local directory.
For example, to use a GCS bucket called `kaniko-bucket`, you would pass in `--context=gs://kaniko-bucket/path/to/context.tar.gz`.

### Using Private Git Repository
You can use `Personal Access Tokens` for Build Contexts from Private Repositories from [GitHub](https://blog.github.com/2012-09-21-easier-builds-and-deployments-using-git-over-https-and-oauth/).

### Running kaniko

There are several different ways to deploy and run kaniko:
Expand Down
2 changes: 2 additions & 0 deletions integration/dockerfiles/Dockerfile_test_git
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
FROM scratch
COPY LICENSE /LICENSE
8 changes: 4 additions & 4 deletions integration/images.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ var additionalKanikoFlagsMap = map[string][]string{
"Dockerfile_test_target": {"--target=second"},
}

var bucketContextTests = []string{"Dockerfile_test_copy_bucket"}
var gitRepoTests = []string{"Dockerfile_test_git"}
krtkvrm marked this conversation as resolved.
Show resolved Hide resolved
var reproducibleTests = []string{"Dockerfile_test_reproducible"}

// GetDockerImage constructs the name of the docker image that would be built with
Expand Down Expand Up @@ -152,7 +152,7 @@ func (d *DockerFileBuilder) BuildImage(imageRepo, gcsBucket, dockerfilesPath, do
append([]string{"build",
"-t", dockerImage,
"-f", path.Join(dockerfilesPath, dockerfile),
"."},
"../"},
krtkvrm marked this conversation as resolved.
Show resolved Hide resolved
additionalFlags...)...,
)
_, err := RunCommandWithoutTest(dockerCmd)
Expand All @@ -162,10 +162,10 @@ func (d *DockerFileBuilder) BuildImage(imageRepo, gcsBucket, dockerfilesPath, do

contextFlag := "-c"
contextPath := buildContextPath
for _, d := range bucketContextTests {
for _, d := range gitRepoTests {
if d == dockerfile {
contextFlag = "-b"
contextPath = gcsBucket
contextPath = "https://github.com/GoogleContainerTools/kaniko"
break
}
}
Expand Down
4 changes: 3 additions & 1 deletion pkg/buildcontext/buildcontext.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,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://")
}
39 changes: 39 additions & 0 deletions pkg/buildcontext/git.go
Original file line number Diff line number Diff line change
@@ -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
}
1 change: 1 addition & 0 deletions pkg/constants/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ const (
GCSBuildContextPrefix = "gs://"
S3BuildContextPrefix = "s3://"
LocalDirBuildContextPrefix = "dir://"
GitBuildContextPrefix = "git://"

HOME = "HOME"
// DefaultHOMEValue is the default value Docker sets for $HOME
Expand Down
Loading