Skip to content

Commit 6667a2e

Browse files
author
priyawadhwa
authored
Merge pull request #1287 from priyawadhwa/kaniko-cache
Add caching to kaniko builder
2 parents e3d808c + 6861fa1 commit 6667a2e

File tree

6 files changed

+21
-1
lines changed

6 files changed

+21
-1
lines changed

examples/kaniko-local/skaffold.yaml

+1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ build:
88
localDir: {}
99
pullSecretName: e2esecret
1010
namespace: default
11+
cache: {}
1112
deploy:
1213
kubectl:
1314
manifests:

examples/kaniko/skaffold.yaml

+1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ build:
88
gcsBucket: skaffold-kaniko
99
pullSecretName: e2esecret
1010
namespace: default
11+
cache: {}
1112
deploy:
1213
kubectl:
1314
manifests:

integration/examples/annotated-skaffold.yaml

+5
Original file line numberDiff line numberDiff line change
@@ -111,11 +111,16 @@ build:
111111
# If gcsBucket is specified, skaffold will send sources to the GCS bucket provided
112112
# Kaniko also needs access to a service account to push the final image.
113113
# See https://github.com/GoogleContainerTools/kaniko#running-kaniko-in-a-kubernetes-cluster
114+
# If cache is specified, kaniko will use a remote cache which will speed up builds.
115+
# A cache repo can be specified to store cached layers, otherwise one will be inferred
116+
# from the image name. See https://github.com/GoogleContainerTools/kaniko#caching
114117
#
115118
# kaniko:
116119
# buildContext:
117120
# gcsBucket: k8s-skaffold
118121
# localDir: {}
122+
# cache:
123+
# repo: gcr.io/my-project/skaffold/cache
119124
# pullSecret: /a/secret/path/serviceaccount.json
120125
# namespace: default
121126
# timeout: 20m

pkg/skaffold/build/kaniko/run.go

+7
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,13 @@ func (b *Builder) run(ctx context.Context, out io.Writer, artifact *latest.Artif
5555
}
5656
args = append(args, docker.GetBuildArgs(artifact.DockerArtifact)...)
5757

58+
if cfg.Cache != nil {
59+
args = append(args, "--cache=true")
60+
if cfg.Cache.Repo != "" {
61+
args = append(args, fmt.Sprintf("--cache-repo=%s", cfg.Cache.Repo))
62+
}
63+
}
64+
5865
pods := client.CoreV1().Pods(cfg.Namespace)
5966
p, err := pods.Create(s.Pod(args))
6067
if err != nil {

pkg/skaffold/constants/constants.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ const (
4646

4747
DefaultKustomizationPath = "."
4848

49-
DefaultKanikoImage = "gcr.io/kaniko-project/executor:v0.4.0@sha256:0bbaa4859eec9796d32ab45e6c1627562dbc7796e40450295b9604cd3f4197af"
49+
DefaultKanikoImage = "gcr.io/kaniko-project/executor@sha256:434bbb1d998ba1bd8ebc04c90d93afa859fd5c7ff93326bca9f6e7da0d6277ff"
5050
DefaultKanikoSecretName = "kaniko-secret"
5151
DefaultKanikoTimeout = "20m"
5252
DefaultKanikoContainerName = "kaniko"

pkg/skaffold/schema/latest/config.go

+6
Original file line numberDiff line numberDiff line change
@@ -119,10 +119,16 @@ type KanikoBuildContext struct {
119119
LocalDir *LocalDir `yaml:"localDir,omitempty" yamltags:"oneOf=buildContext"`
120120
}
121121

122+
// KanikoCache contains fields related to kaniko caching
123+
type KanikoCache struct {
124+
Repo string `yaml:"repo,omitempty"`
125+
}
126+
122127
// KanikoBuild contains the fields needed to do a on-cluster build using
123128
// the kaniko image
124129
type KanikoBuild struct {
125130
BuildContext *KanikoBuildContext `yaml:"buildContext,omitempty"`
131+
Cache *KanikoCache `yaml:"cache,omitempty"`
126132
PullSecret string `yaml:"pullSecret,omitempty"`
127133
PullSecretName string `yaml:"pullSecretName,omitempty"`
128134
Namespace string `yaml:"namespace,omitempty"`

0 commit comments

Comments
 (0)