Skip to content

Commit

Permalink
enhance(flags): add compressed caching, log timestamp, and ignore pat…
Browse files Browse the repository at this point in the history
…h flags (#197)

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

* fix reviewdog
  • Loading branch information
ecrupper authored Aug 20, 2024
1 parent 6645c4a commit cab1585
Show file tree
Hide file tree
Showing 6 changed files with 228 additions and 154 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/reviewdog.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ jobs:
uses: reviewdog/action-golangci-lint@7708105983c614f7a2725e2172908b7709d1c3e4 # v2.6.2
with:
github_token: ${{ secrets.github_token }}
golangci_lint_flags: "--config=.golangci.yml"
golangci_lint_flags: "--config=.golangci.yml --timeout=5m"
fail_on_error: true
filter_mode: diff_context
reporter: github-pr-review
Expand All @@ -50,6 +50,6 @@ jobs:
uses: reviewdog/action-golangci-lint@7708105983c614f7a2725e2172908b7709d1c3e4 # v2.6.2
with:
github_token: ${{ secrets.github_token }}
golangci_lint_flags: "--config=.golangci.yml"
golangci_lint_flags: "--config=.golangci.yml --timeout=5m"
fail_on_error: false
filter_mode: nofilter
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

0 comments on commit cab1585

Please sign in to comment.