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

Add caching to kaniko builder #1287

Merged
merged 2 commits into from
Nov 19, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions examples/kaniko-local/skaffold.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ build:
localDir: {}
pullSecretName: e2esecret
namespace: default
cache: {}
deploy:
kubectl:
manifests:
Expand Down
1 change: 1 addition & 0 deletions examples/kaniko/skaffold.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ build:
gcsBucket: skaffold-kaniko
pullSecretName: e2esecret
namespace: default
cache: {}
deploy:
kubectl:
manifests:
Expand Down
5 changes: 5 additions & 0 deletions integration/examples/annotated-skaffold.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -111,11 +111,16 @@ build:
# If gcsBucket is specified, skaffold will send sources to the GCS bucket provided
# Kaniko also needs access to a service account to push the final image.
# See https://github.com/GoogleContainerTools/kaniko#running-kaniko-in-a-kubernetes-cluster
# If cache is specified, kaniko will use a remote cache which will speed up builds.
# A cache repo can be specified to store cached layers, otherwise one will be inferred
# from the image name. See https://github.com/GoogleContainerTools/kaniko#caching
#
# kaniko:
# buildContext:
# gcsBucket: k8s-skaffold
# localDir: {}
# cache:
# repo: gcr.io/my-project/skaffold/cache
# pullSecret: /a/secret/path/serviceaccount.json
# namespace: default
# timeout: 20m
Expand Down
7 changes: 7 additions & 0 deletions pkg/skaffold/build/kaniko/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,13 @@ func (b *Builder) run(ctx context.Context, out io.Writer, artifact *latest.Artif
}
args = append(args, docker.GetBuildArgs(artifact.DockerArtifact)...)

if cfg.Cache != nil {
args = append(args, "--cache=true")
if cfg.Cache.Repo != "" {
args = append(args, fmt.Sprintf("--cache-repo=%s", cfg.Cache.Repo))
}
}

pods := client.CoreV1().Pods(cfg.Namespace)
p, err := pods.Create(s.Pod(args))
if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion pkg/skaffold/constants/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ const (

DefaultKustomizationPath = "."

DefaultKanikoImage = "gcr.io/kaniko-project/executor:v0.4.0@sha256:0bbaa4859eec9796d32ab45e6c1627562dbc7796e40450295b9604cd3f4197af"
DefaultKanikoImage = "gcr.io/kaniko-project/executor@sha256:434bbb1d998ba1bd8ebc04c90d93afa859fd5c7ff93326bca9f6e7da0d6277ff"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you leave the version here, in addition to the sha256? It makes it easier to find which version we are using.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

kaniko actually hasn't released a version with the new caching stuff yet -- I was going to come back to this and add the new version in once that happened.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll open an issue for it!

DefaultKanikoSecretName = "kaniko-secret"
DefaultKanikoTimeout = "20m"
DefaultKanikoContainerName = "kaniko"
Expand Down
6 changes: 6 additions & 0 deletions pkg/skaffold/schema/latest/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,10 +119,16 @@ type KanikoBuildContext struct {
LocalDir *LocalDir `yaml:"localDir,omitempty" yamltags:"oneOf=buildContext"`
}

// KanikoCache contains fields related to kaniko caching
type KanikoCache struct {
Repo string `yaml:"repo,omitempty"`
}

// KanikoBuild contains the fields needed to do a on-cluster build using
// the kaniko image
type KanikoBuild struct {
BuildContext *KanikoBuildContext `yaml:"buildContext,omitempty"`
Cache *KanikoCache `yaml:"cache,omitempty"`
PullSecret string `yaml:"pullSecret,omitempty"`
PullSecretName string `yaml:"pullSecretName,omitempty"`
Namespace string `yaml:"namespace,omitempty"`
Expand Down