Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

enhance(flags): add compressed caching, log timestamp, and ignore path flags #197

Merged
merged 2 commits into from
Aug 20, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions cmd/vela-kaniko/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@ type Build struct {
SingleSnapshot bool
// https://github.com/GoogleContainerTools/kaniko#flag---ignore-var-run
IgnoreVarRun bool
// https://github.com/GoogleContainerTools/kaniko#flag---ignore-path
IgnorePath []string
// https://github.com/GoogleContainerTools/kaniko#flag---log-timestamp
LogTimestamp bool
}

// SnapshotModeValues represents the available options for setting a snapshot mode.
Expand Down
38 changes: 30 additions & 8 deletions cmd/vela-kaniko/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,18 @@ func main() {
Usage: "By default Kaniko ignores /var/run when taking image snapshot. Include this parameter to preserve /var/run/* in destination image.",
Value: true,
},
&cli.StringSliceFlag{
EnvVars: []string{"PARAMETER_IGNORE_PATH", "KANIKO_IGNORE_PATH"},
FilePath: "/vela/parameters/kaniko/ignore_path,/vela/secrets/kaniko/ignore_path",
Name: "build.ignore_path",
Usage: "ignore paths when taking image snapshot",
},
&cli.BoolFlag{
EnvVars: []string{"PARAMETER_LOG_TIMESTAMPS", "KANIKO_LOG_TIMESTAMPS"},
FilePath: "/vela/parameters/kaniko/log_timestamps,/vela/secrets/kaniko/log_timestamps",
Name: "build.log_timestamps",
Usage: "enable timestamps in logs",
},

// Image Flags

Expand Down Expand Up @@ -248,6 +260,13 @@ func main() {
Name: "repo.compression_level",
Usage: "set the compression level (1-9, inclusive)",
},
&cli.BoolFlag{
EnvVars: []string{"PARAMETER_COMPRESSED_CACHING", "KANIKO_COMPRESSED_CACHING"},
FilePath: "/vela/parameters/kaniko/compressed_caching,/vela/secrets/kaniko/compressed_caching",
Name: "repo.compressed_caching",
Usage: "when set to false, will prevent tar compression for cached layers",
Value: true,
},
&cli.StringFlag{
EnvVars: []string{"PARAMETER_REPO", "KANIKO_REPO"},
FilePath: "/vela/parameters/kaniko/repo,/vela/secrets/kaniko/repo",
Expand Down Expand Up @@ -374,6 +393,8 @@ func run(c *cli.Context) error {
TarPath: c.String("build.tar_path"),
SingleSnapshot: c.Bool("build.single_snapshot"),
IgnoreVarRun: c.Bool("build.ignore_var_run"),
IgnorePath: c.StringSlice("build.ignore_path"),
LogTimestamp: c.Bool("build.log_timestamps"),
},
// image configuration
Image: &Image{
Expand All @@ -398,14 +419,15 @@ func run(c *cli.Context) error {
},
// repo configuration
Repo: &Repo{
AutoTag: c.Bool("repo.auto_tag"),
Cache: c.Bool("repo.cache"),
CacheName: c.String("repo.cache_name"),
Compression: c.String("repo.compression"),
CompressionLevel: c.Int("repo.compression_level"),
Name: c.String("repo.name"),
Tags: c.StringSlice("repo.tags"),
TopicsFilter: c.String("repo.topics_filter"),
AutoTag: c.Bool("repo.auto_tag"),
Cache: c.Bool("repo.cache"),
CacheName: c.String("repo.cache_name"),
Compression: c.String("repo.compression"),
CompressionLevel: c.Int("repo.compression_level"),
CompressedCaching: c.Bool("repo.compressed_caching"),
Name: c.String("repo.name"),
Tags: c.StringSlice("repo.tags"),
TopicsFilter: c.String("repo.topics_filter"),
Label: &Label{
AuthorEmail: c.String("label.author_email"),
Commit: c.String("label.commit"),
Expand Down
17 changes: 17 additions & 0 deletions cmd/vela-kaniko/plugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,18 @@ func (p *Plugin) Command() *exec.Cmd {

flags = append(flags, fmt.Sprintf("--ignore-var-run=%s", strconv.FormatBool(p.Build.IgnoreVarRun)))

// add paths to be ignored if provided
if len(p.Build.IgnorePath) > 0 {
for _, path := range p.Build.IgnorePath {
flags = append(flags, fmt.Sprintf("--ignore-path=%s", path))
}
}

// add timestamps if enabled
if p.Build.LogTimestamp {
flags = append(flags, "--log-timestamp")
}

// iterate through all image build args
for _, arg := range p.Image.Args {
// add flag for build args from provided image build arg
Expand Down Expand Up @@ -96,6 +108,11 @@ func (p *Plugin) Command() *exec.Cmd {
flags = append(flags, fmt.Sprintf("--compression-level=%d", p.Repo.CompressionLevel))
}

// check if compressed caching is disabled
if !p.Repo.CompressedCaching {
flags = append(flags, "--compressed-caching=false")
}

// add flag for context from provided image context
flags = append(flags, fmt.Sprintf("--context=%s", p.Image.Context))

Expand Down
Loading
Loading