Skip to content

Commit

Permalink
Merge pull request #1287 from priyawadhwa/kaniko-cache
Browse files Browse the repository at this point in the history
Add caching to kaniko builder
  • Loading branch information
priyawadhwa authored Nov 19, 2018
2 parents e3d808c + 6861fa1 commit 6667a2e
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 1 deletion.
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"
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

0 comments on commit 6667a2e

Please sign in to comment.