Skip to content

Commit

Permalink
feat: add --description flag for kaniko build (#9415)
Browse files Browse the repository at this point in the history
  • Loading branch information
hedinasr authored May 10, 2024
1 parent 0ffd373 commit 38c7308
Show file tree
Hide file tree
Showing 7 changed files with 70 additions and 1 deletion.
10 changes: 10 additions & 0 deletions docs-v2/content/en/schemas/v4beta11.json
Original file line number Diff line number Diff line change
Expand Up @@ -2671,6 +2671,15 @@
"description": "timeout for copying build contexts to a cluster. Defaults to 5 minutes (`5m`).",
"x-intellij-html-description": "timeout for copying build contexts to a cluster. Defaults to 5 minutes (<code>5m</code>)."
},
"destination": {
"items": {
"type": "string"
},
"type": "array",
"description": "additional tags to push.",
"x-intellij-html-description": "additional tags to push.",
"default": "[]"
},
"digestFile": {
"type": "string",
"description": "to specify a file in the container. This file will receive the digest of a built image. This can be used to automatically track the exact image built by kaniko.",
Expand Down Expand Up @@ -2888,6 +2897,7 @@
"target",
"initImage",
"image",
"destination",
"digestFile",
"imageFSExtractRetry",
"imageNameWithDigestFile",
Expand Down
21 changes: 20 additions & 1 deletion pkg/skaffold/build/cluster/pod_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,20 @@ func TestKanikoArgs(t *testing.T) {
},
expectedArgs: []string{},
},
{
description: "with Destination",
artifact: &latest.KanikoArtifact{
DockerfilePath: "Dockerfile",
Destination: []string{
"gcr.io/foo/bar:test-1",
"gcr.io/foo/bar:test-2",
},
},
expectedArgs: []string{
kaniko.DestinationFlag, "gcr.io/foo/bar:test-1",
kaniko.DestinationFlag, "gcr.io/foo/bar:test-2",
},
},
{
description: "cache layers",
artifact: &latest.KanikoArtifact{
Expand Down Expand Up @@ -170,6 +184,10 @@ func TestKanikoPodSpec(t *testing.T) {
Image: "image",
DockerfilePath: "Dockerfile",
InitImage: "init/image",
Destination: []string{
"gcr.io/foo/bar:test-1",
"gcr.io/foo/bar:test-2",
},
Env: []v1.EnvVar{{
Name: "KEY",
Value: "VALUE",
Expand Down Expand Up @@ -284,7 +302,7 @@ func TestKanikoPodSpec(t *testing.T) {
Containers: []v1.Container{{
Name: kaniko.DefaultContainerName,
Image: "image",
Args: []string{"--dockerfile", "Dockerfile", "--context", "dir:///kaniko/buildcontext", "--destination", "tag", "-v", "info"},
Args: []string{"--destination", "tag", "--dockerfile", "Dockerfile", "--context", "dir:///kaniko/buildcontext", "--destination", "gcr.io/foo/bar:test-1", "--destination", "gcr.io/foo/bar:test-2"},
ImagePullPolicy: v1.PullIfNotPresent,
Env: []v1.EnvVar{{
Name: "UPSTREAM_CLIENT_TYPE",
Expand Down Expand Up @@ -386,6 +404,7 @@ func TestKanikoPodSpec(t *testing.T) {
}

testutil.CheckDeepEqual(t, expectedPod.Spec.Containers[0].Env, pod.Spec.Containers[0].Env)
testutil.CheckDeepEqual(t, expectedPod.Spec.Containers[0].Args, pod.Spec.Containers[0].Args)
}

func TestResourceRequirements(t *testing.T) {
Expand Down
14 changes: 14 additions & 0 deletions pkg/skaffold/build/gcb/kaniko_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,20 @@ func TestKanikoBuildSpec(t *testing.T) {
},
expectedArgs: []string{},
},
{
description: "with destination",
artifact: &latest.KanikoArtifact{
DockerfilePath: "Dockerfile",
Destination: []string{
"gcr.io/foo/bar:test-1",
"gcr.io/foo/bar:test-2",
},
},
expectedArgs: []string{
kaniko.DestinationFlag, "gcr.io/foo/bar:test-1",
kaniko.DestinationFlag, "gcr.io/foo/bar:test-2",
},
},
{
description: "with BuildArgs",
artifact: &latest.KanikoArtifact{
Expand Down
6 changes: 6 additions & 0 deletions pkg/skaffold/build/kaniko/args.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,12 @@ func Args(artifact *latest.KanikoArtifact, tag, context string) ([]string, error
args = append(args, CleanupFlag)
}

var tags []string
for _, r := range artifact.Destination {
tags = append(tags, DestinationFlag, r)
}
args = append(args, tags...)

if artifact.DigestFile != "" {
args = append(args, DigestFileFlag, artifact.DigestFile)
}
Expand Down
15 changes: 15 additions & 0 deletions pkg/skaffold/build/kaniko/args_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,21 @@ func TestArgs(t *testing.T) {
expectedArgs: []string{},
wantErr: false,
},
{
description: "with Destination",
artifact: &latest.KanikoArtifact{
DockerfilePath: "dir/Dockerfile",
Destination: []string{
"gcr.io/foo/bar:test-1",
"gcr.io/foo/bar:test-2",
},
},
expectedArgs: []string{
DestinationFlag, "gcr.io/foo/bar:test-1",
DestinationFlag, "gcr.io/foo/bar:test-2",
},
wantErr: false,
},
{
description: "with BuildArgs",
artifact: &latest.KanikoArtifact{
Expand Down
2 changes: 2 additions & 0 deletions pkg/skaffold/build/kaniko/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ const (
CleanupFlag = "--cleanup"
// DigestFileFlag additional flag
DigestFileFlag = "--digest-file"
// Destination additional flag
DestinationFlag = "--destination"
// ForceFlag additional flag
ForceFlag = "--force"
// ImageFSExtractRetry additional flag
Expand Down
3 changes: 3 additions & 0 deletions pkg/skaffold/schema/latest/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -1456,6 +1456,9 @@ type KanikoArtifact struct {
// Defaults to the latest released version of `gcr.io/kaniko-project/executor`.
Image string `yaml:"image,omitempty"`

// Destination is additional tags to push.
Destination []string `yaml:"destination,omitempty"`

// DigestFile to specify a file in the container. This file will receive the digest of a built image.
// This can be used to automatically track the exact image built by kaniko.
DigestFile string `yaml:"digestFile,omitempty"`
Expand Down

0 comments on commit 38c7308

Please sign in to comment.