Skip to content

Commit

Permalink
feat: add ingore-path kaniko flag support (#8340)
Browse files Browse the repository at this point in the history
  • Loading branch information
simonoff authored Jan 20, 2023
1 parent a325b29 commit 7d346f5
Show file tree
Hide file tree
Showing 6 changed files with 45 additions and 1 deletion.
12 changes: 11 additions & 1 deletion docs-v2/content/en/schemas/v4beta2.json
Original file line number Diff line number Diff line change
Expand Up @@ -2523,6 +2523,15 @@
"x-intellij-html-description": "building outside of a container.",
"default": "false"
},
"ignorePaths": {
"items": {
"type": "string"
},
"type": "array",
"description": "a list of ignored paths when making an image snapshot.",
"x-intellij-html-description": "a list of ignored paths when making an image snapshot.",
"default": "[]"
},
"image": {
"type": "string",
"description": "Docker image used by the Kaniko pod. Defaults to the latest released version of `gcr.io/kaniko-project/executor`.",
Expand Down Expand Up @@ -2729,7 +2738,8 @@
"label",
"buildArgs",
"volumeMounts",
"contextSubPath"
"contextSubPath",
"ignorePaths"
],
"additionalProperties": false,
"type": "object",
Expand Down
11 changes: 11 additions & 0 deletions pkg/skaffold/build/gcb/kaniko_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -397,6 +397,17 @@ func TestKanikoBuildSpec(t *testing.T) {
kaniko.LabelFlag, "label2",
},
},
{
description: "with IgnorePaths",
artifact: &latest.KanikoArtifact{
DockerfilePath: "Dockerfile",
IgnorePaths: []string{"/var", "/tmp"},
},
expectedArgs: []string{
kaniko.IgnorePathFlag, "/var",
kaniko.IgnorePathFlag, "/tmp",
},
},
}
store := mockArtifactStore{
"img2": "img2:tag",
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 @@ -174,6 +174,12 @@ func Args(artifact *latest.KanikoArtifact, tag, context string) ([]string, error
}
args = append(args, sRegArgs...)

var ignPathArgs []string
for _, r := range artifact.IgnorePaths {
ignPathArgs = append(ignPathArgs, IgnorePathFlag, r)
}
args = append(args, ignPathArgs...)

registryCertificate, err := util.MapToFlag(artifact.RegistryCertificate, RegistryCertificateFlag)
if err != nil {
return args, err
Expand Down
12 changes: 12 additions & 0 deletions pkg/skaffold/build/kaniko/args_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -407,6 +407,18 @@ func TestArgs(t *testing.T) {
},
wantErr: false,
},
{
description: "with IgnorePaths",
artifact: &latest.KanikoArtifact{
DockerfilePath: "dir/Dockerfile",
IgnorePaths: []string{"/tmp", "/proc"},
},
expectedArgs: []string{
IgnorePathFlag, "/tmp",
IgnorePathFlag, "/proc",
},
wantErr: false,
},
}

defaultExpectedArgs := []string{
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 @@ -107,4 +107,6 @@ const (
DefaultDockerConfigPath = "/kaniko/.docker"
// DefaultSecretMountPath for kaniko pod
DefaultSecretMountPath = "/secret"
// IgnorePath additional flag
IgnorePathFlag = "--ignore-path"
)
3 changes: 3 additions & 0 deletions pkg/skaffold/schema/latest/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -1387,6 +1387,9 @@ type KanikoArtifact struct {

// ContextSubPath is to specify a sub path within the context.
ContextSubPath string `yaml:"contextSubPath,omitempty" skaffold:"filepath"`

// IgnorePaths is a list of ignored paths when making an image snapshot.
IgnorePaths []string `yaml:"ignorePaths,omitempty"`
}

// DockerArtifact describes an artifact built from a Dockerfile,
Expand Down

0 comments on commit 7d346f5

Please sign in to comment.