Skip to content

Commit ec2a430

Browse files
committed
feat: Added no-push,compressedCaching flag features to skaffold kaniko
1 parent d7aa78b commit ec2a430

File tree

7 files changed

+108
-22
lines changed

7 files changed

+108
-22
lines changed

docs-v2/content/en/schemas/v4beta14.json

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2834,6 +2834,12 @@
28342834
"x-intellij-html-description": "to add timestamps to log format.",
28352835
"default": "false"
28362836
},
2837+
"noPush": {
2838+
"type": "boolean",
2839+
"description": "if you only want to build the image, without pushing to a registry.",
2840+
"x-intellij-html-description": "if you only want to build the image, without pushing to a registry.",
2841+
"default": "false"
2842+
},
28372843
"ociLayoutPath": {
28382844
"type": "string",
28392845
"description": "to specify a directory in the container where the OCI image layout of a built image will be placed. This can be used to automatically track the exact image built by kaniko.",
@@ -2941,6 +2947,7 @@
29412947
"cleanup",
29422948
"insecure",
29432949
"insecurePull",
2950+
"noPush",
29442951
"force",
29452952
"logTimestamp",
29462953
"reproducible",
@@ -2998,6 +3005,11 @@
29983005
"description": "enables caching of run layers (default=true).",
29993006
"x-intellij-html-description": "enables caching of run layers (default=true)."
30003007
},
3008+
"compressedCaching": {
3009+
"type": "boolean",
3010+
"description": "increases memory usage but reduces build runtime (default=true).",
3011+
"x-intellij-html-description": "increases memory usage but reduces build runtime (default=true)."
3012+
},
30013013
"hostPath": {
30023014
"type": "string",
30033015
"description": "specifies a path on the host that is mounted to each pod as read only cache volume containing base images. If set, must exist on each node and prepopulated with kaniko-warmer.",
@@ -3019,7 +3031,8 @@
30193031
"hostPath",
30203032
"ttl",
30213033
"cacheCopyLayers",
3022-
"cacheRunLayers"
3034+
"cacheRunLayers",
3035+
"compressedCaching"
30233036
],
30243037
"additionalProperties": false,
30253038
"type": "object",

pkg/skaffold/build/gcb/kaniko_test.go

Lines changed: 33 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,17 @@ func TestKanikoBuildSpec(t *testing.T) {
127127
fmt.Sprintf("%s=%t", kaniko.CacheRunLayersFlag, true),
128128
},
129129
},
130+
{
131+
description: "with CompressedCaching is false",
132+
artifact: &latest.KanikoArtifact{
133+
DockerfilePath: "Dockerfile",
134+
Cache: &latest.KanikoCache{CompressedCaching: boolPtr(false)},
135+
},
136+
expectedArgs: []string{
137+
kaniko.CacheFlag,
138+
fmt.Sprintf("%s=%t", kaniko.CompressedCachingFlag, false),
139+
},
140+
},
130141
{
131142
description: "with Cleanup",
132143
artifact: &latest.KanikoArtifact{
@@ -231,6 +242,16 @@ func TestKanikoBuildSpec(t *testing.T) {
231242
kaniko.LogTimestampFlag,
232243
},
233244
},
245+
{
246+
description: "with NoPush",
247+
artifact: &latest.KanikoArtifact{
248+
DockerfilePath: "Dockerfile",
249+
NoPush: true,
250+
},
251+
expectedArgs: []string{
252+
kaniko.NoPushFlag,
253+
},
254+
},
234255
{
235256
description: "with OCILayoutPath",
236257
artifact: &latest.KanikoArtifact{
@@ -447,12 +468,19 @@ func TestKanikoBuildSpec(t *testing.T) {
447468
Timeout: "10m",
448469
})
449470

450-
defaultExpectedArgs := []string{
451-
"--destination", "gcr.io/nginx",
452-
"--dockerfile", "Dockerfile",
453-
}
454-
455471
for _, test := range tests {
472+
var defaultExpectedArgs []string
473+
if test.artifact.NoPush {
474+
defaultExpectedArgs = []string{
475+
"--dockerfile", "Dockerfile",
476+
}
477+
} else {
478+
defaultExpectedArgs = []string{
479+
"--destination", "gcr.io/nginx",
480+
"--dockerfile", "Dockerfile",
481+
}
482+
}
483+
456484
testutil.Run(t, test.description, func(t *testutil.T) {
457485
artifact := &latest.Artifact{
458486
ImageName: "img1",

pkg/skaffold/build/kaniko/args.go

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,16 @@ import (
2828

2929
// Args returns kaniko command arguments
3030
func Args(artifact *latest.KanikoArtifact, tag, context string) ([]string, error) {
31-
args := []string{
32-
"--destination", tag,
33-
"--dockerfile", filepath.ToSlash(filepath.Join(artifact.ContextSubPath, artifact.DockerfilePath)),
31+
var args []string
32+
if artifact.NoPush {
33+
args = []string{
34+
"--dockerfile", filepath.ToSlash(filepath.Join(artifact.ContextSubPath, artifact.DockerfilePath)),
35+
}
36+
} else {
37+
args = []string{
38+
"--destination", tag,
39+
"--dockerfile", filepath.ToSlash(filepath.Join(artifact.ContextSubPath, artifact.DockerfilePath)),
40+
}
3441
}
3542

3643
if context != "" {
@@ -62,6 +69,9 @@ func Args(artifact *latest.KanikoArtifact, tag, context string) ([]string, error
6269
if artifact.Cache.CacheRunLayers != nil {
6370
args = append(args, fmt.Sprintf("%s=%t", CacheRunLayersFlag, *artifact.Cache.CacheRunLayers))
6471
}
72+
if artifact.Cache.CompressedCaching != nil {
73+
args = append(args, fmt.Sprintf("%s=%t", CompressedCachingFlag, *artifact.Cache.CompressedCaching))
74+
}
6575
}
6676

6777
if artifact.Target != "" {
@@ -72,11 +82,13 @@ func Args(artifact *latest.KanikoArtifact, tag, context string) ([]string, error
7282
args = append(args, CleanupFlag)
7383
}
7484

75-
var tags []string
76-
for _, r := range artifact.Destination {
77-
tags = append(tags, DestinationFlag, r)
85+
if artifact.NoPush {
86+
args = append(args, NoPushFlag)
87+
} else {
88+
for _, r := range artifact.Destination {
89+
args = append(args, DestinationFlag, r)
90+
}
7891
}
79-
args = append(args, tags...)
8092

8193
if artifact.DigestFile != "" {
8294
args = append(args, DigestFileFlag, artifact.DigestFile)

pkg/skaffold/build/kaniko/args_test.go

Lines changed: 32 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ import (
2626
)
2727

2828
func TestArgs(t *testing.T) {
29+
disableCompressedCache := false
30+
2931
tests := []struct {
3032
description string
3133
artifact *latest.KanikoArtifact
@@ -86,16 +88,18 @@ func TestArgs(t *testing.T) {
8688
artifact: &latest.KanikoArtifact{
8789
DockerfilePath: "dir/Dockerfile",
8890
Cache: &latest.KanikoCache{
89-
Repo: "gcr.io/ngnix",
90-
HostPath: "/cache",
91-
TTL: "2",
91+
Repo: "gcr.io/ngnix",
92+
HostPath: "/cache",
93+
TTL: "2",
94+
CompressedCaching: &disableCompressedCache,
9295
},
9396
},
9497
expectedArgs: []string{
9598
CacheFlag,
9699
CacheRepoFlag, "gcr.io/ngnix",
97100
CacheDirFlag, "/cache",
98101
CacheTTLFlag, "2",
102+
fmt.Sprintf("%s=%t", CompressedCachingFlag, false),
99103
},
100104
wantErr: false,
101105
},
@@ -202,6 +206,17 @@ func TestArgs(t *testing.T) {
202206
},
203207
wantErr: false,
204208
},
209+
{
210+
description: "with NoPush",
211+
artifact: &latest.KanikoArtifact{
212+
DockerfilePath: "dir/Dockerfile",
213+
NoPush: true,
214+
},
215+
expectedArgs: []string{
216+
NoPushFlag,
217+
},
218+
wantErr: false,
219+
},
205220
{
206221
description: "with OCILayoutPath",
207222
artifact: &latest.KanikoArtifact{
@@ -425,13 +440,21 @@ func TestArgs(t *testing.T) {
425440
},
426441
}
427442

428-
defaultExpectedArgs := []string{
429-
"--destination", "gcr.io/nginx",
430-
"--dockerfile", "dir/Dockerfile",
431-
"--context", fmt.Sprintf("dir://%s", DefaultEmptyDirMountPath),
432-
}
433-
434443
for _, test := range tests {
444+
var defaultExpectedArgs []string
445+
if test.artifact.NoPush {
446+
defaultExpectedArgs = []string{
447+
"--dockerfile", "dir/Dockerfile",
448+
"--context", fmt.Sprintf("dir://%s", DefaultEmptyDirMountPath),
449+
}
450+
} else {
451+
defaultExpectedArgs = []string{
452+
"--destination", "gcr.io/nginx",
453+
"--dockerfile", "dir/Dockerfile",
454+
"--context", fmt.Sprintf("dir://%s", DefaultEmptyDirMountPath),
455+
}
456+
}
457+
435458
testutil.Run(t, test.description, func(t *testutil.T) {
436459
got, err := Args(test.artifact, "gcr.io/nginx", fmt.Sprintf("dir://%s", DefaultEmptyDirMountPath))
437460
if (err != nil) != test.wantErr {

pkg/skaffold/build/kaniko/types.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@ const (
3131
CacheRepoFlag = "--cache-repo"
3232
// CacheTTLFlag additional flag
3333
CacheTTLFlag = "--cache-ttl"
34+
// CompressedCaching additional flag
35+
CompressedCachingFlag = "--compressed-caching"
3436
// TargetFlag additional flag
3537
TargetFlag = "--target"
3638
// CleanupFlag additional flag
@@ -57,6 +59,8 @@ const (
5759
LogFormatFlag = "--log-format"
5860
// LogTimestampFlag additional flag
5961
LogTimestampFlag = "--log-timestamp"
62+
// NoPushFlag additional flag
63+
NoPushFlag = "--no-push"
6064
// OCILayoutFlag additional flag
6165
OCILayoutFlag = "--oci-layout-path"
6266
// RegistryCertificateFlag additional flag

pkg/skaffold/schema/defaults/defaults.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -389,6 +389,7 @@ func setKanikoArtifactDefaults(a *latest.KanikoArtifact) {
389389
a.DigestFile = valueOrDefault(a.DigestFile, constants.DefaultKanikoDigestFile)
390390
if a.Cache != nil {
391391
a.Cache.CacheRunLayers = valueOrDefaultBool(a.Cache.CacheRunLayers, true)
392+
a.Cache.CompressedCaching = valueOrDefaultBool(a.Cache.CompressedCaching, true)
392393
}
393394
a.CopyMaxRetries = valueOrDefaultInt(a.CopyMaxRetries, kaniko.DefaultCopyMaxRetries)
394395
a.CopyTimeout = valueOrDefault(a.CopyTimeout, kaniko.DefaultCopyTimeout)

pkg/skaffold/schema/latest/config.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -501,6 +501,8 @@ type KanikoCache struct {
501501
CacheCopyLayers bool `yaml:"cacheCopyLayers,omitempty"`
502502
// CacheRunLayers enables caching of run layers (default=true).
503503
CacheRunLayers *bool `yaml:"cacheRunLayers,omitempty"`
504+
// CompressedCaching increases memory usage but reduces build runtime (default=true).
505+
CompressedCaching *bool `yaml:"compressedCaching,omitempty"`
504506
}
505507

506508
// ClusterDetails *beta* describes how to do an on-cluster build.
@@ -1432,6 +1434,9 @@ type KanikoArtifact struct {
14321434
// InsecurePull if you want to pull images from a plain HTTP registry.
14331435
InsecurePull bool `yaml:"insecurePull,omitempty"`
14341436

1437+
// NoPush if you only want to build the image, without pushing to a registry.
1438+
NoPush bool `yaml:"noPush,omitempty"`
1439+
14351440
// Force building outside of a container.
14361441
Force bool `yaml:"force,omitempty"`
14371442

0 commit comments

Comments
 (0)