Skip to content

Commit

Permalink
fix: [CI-10165]: Add bool parse logic
Browse files Browse the repository at this point in the history
  • Loading branch information
smjt-h committed Feb 6, 2024
1 parent fbb03e2 commit 71882ec
Show file tree
Hide file tree
Showing 6 changed files with 46 additions and 18 deletions.
10 changes: 8 additions & 2 deletions cmd/kaniko-acr/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -410,7 +410,6 @@ func run(c *cli.Context) error {
CacheCopyLayers: c.Bool("cache-copy-layers"),
CacheRunLayers: c.Bool("cache-run-layers"),
Cleanup: c.Bool("cleanup"),
CompressedCaching: c.Bool("compressed-caching"),
ContextSubPath: c.String("context-sub-path"),
CustomPlatform: c.String("custom-platform"),
Force: c.Bool("force"),
Expand All @@ -434,7 +433,6 @@ func run(c *cli.Context) error {
SkipTLSVerifyPull: c.Bool("skip-tls-verify-pull"),
SkipTLSVerifyRegistry: c.Bool("skip-tls-verify-registry"),
UseNewRun: c.Bool("use-new-run"),
IgnoreVarRun: c.Bool("ignore-var-run"),
IgnorePath: c.String("ignore-path"),
ImageFSExtractRetry: c.Int("image-fs-extract-retry"),
ImageDownloadRetry: c.Int("image-download-retry"),
Expand All @@ -447,6 +445,14 @@ func run(c *cli.Context) error {
RegistryType: artifact.Docker,
},
}
if c.IsSet("compressed-caching") {
flag := c.Bool("compressed-caching")
plugin.Build.CompressedCaching = &flag
}
if c.IsSet("ignore-var-run") {
flag := c.Bool("ignore-var-run")
plugin.Build.IgnoreVarRun = &flag
}
return plugin.Exec()
}

Expand Down
10 changes: 8 additions & 2 deletions cmd/kaniko-docker/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -406,7 +406,6 @@ func run(c *cli.Context) error {
CacheCopyLayers: c.Bool("cache-copy-layers"),
CacheRunLayers: c.Bool("cache-run-layers"),
Cleanup: c.Bool("cleanup"),
CompressedCaching: c.Bool("compressed-caching"),
ContextSubPath: c.String("context-sub-path"),
CustomPlatform: c.String("custom-platform"),
Force: c.Bool("force"),
Expand All @@ -430,7 +429,6 @@ func run(c *cli.Context) error {
SkipTLSVerifyPull: c.Bool("skip-tls-verify-pull"),
SkipTLSVerifyRegistry: c.Bool("skip-tls-verify-registry"),
UseNewRun: c.Bool("use-new-run"),
IgnoreVarRun: c.Bool("ignore-var-run"),
IgnorePath: c.String("ignore-path"),
ImageFSExtractRetry: c.Int("image-fs-extract-retry"),
ImageDownloadRetry: c.Int("image-download-retry"),
Expand All @@ -446,6 +444,14 @@ func run(c *cli.Context) error {
OutputFile: c.String("output-file"),
},
}
if c.IsSet("compressed-caching") {
flag := c.Bool("compressed-caching")
plugin.Build.CompressedCaching = &flag
}
if c.IsSet("ignore-var-run") {
flag := c.Bool("ignore-var-run")
plugin.Build.IgnoreVarRun = &flag
}
return plugin.Exec()
}

Expand Down
10 changes: 8 additions & 2 deletions cmd/kaniko-ecr/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -480,7 +480,6 @@ func run(c *cli.Context) error {
CacheCopyLayers: c.Bool("cache-copy-layers"),
CacheRunLayers: c.Bool("cache-run-layers"),
Cleanup: c.Bool("cleanup"),
CompressedCaching: c.Bool("compressed-caching"),
ContextSubPath: c.String("context-sub-path"),
CustomPlatform: c.String("custom-platform"),
Force: c.Bool("force"),
Expand All @@ -504,7 +503,6 @@ func run(c *cli.Context) error {
SkipTLSVerifyPull: c.Bool("skip-tls-verify-pull"),
SkipTLSVerifyRegistry: c.Bool("skip-tls-verify-registry"),
UseNewRun: c.Bool("use-new-run"),
IgnoreVarRun: c.Bool("ignore-var-run"),
IgnorePath: c.String("ignore-path"),
ImageFSExtractRetry: c.Int("image-fs-extract-retry"),
ImageDownloadRetry: c.Int("image-download-retry"),
Expand All @@ -517,6 +515,14 @@ func run(c *cli.Context) error {
RegistryType: artifact.ECR,
},
}
if c.IsSet("compressed-caching") {
flag := c.Bool("compressed-caching")
plugin.Build.CompressedCaching = &flag
}
if c.IsSet("ignore-var-run") {
flag := c.Bool("ignore-var-run")
plugin.Build.IgnoreVarRun = &flag
}
return plugin.Exec()
}

Expand Down
10 changes: 8 additions & 2 deletions cmd/kaniko-gar/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -363,7 +363,6 @@ func run(c *cli.Context) error {
CacheCopyLayers: c.Bool("cache-copy-layers"),
CacheRunLayers: c.Bool("cache-run-layers"),
Cleanup: c.Bool("cleanup"),
CompressedCaching: c.Bool("compressed-caching"),
ContextSubPath: c.String("context-sub-path"),
CustomPlatform: c.String("custom-platform"),
Force: c.Bool("force"),
Expand All @@ -387,7 +386,6 @@ func run(c *cli.Context) error {
SkipTLSVerifyPull: c.Bool("skip-tls-verify-pull"),
SkipTLSVerifyRegistry: c.Bool("skip-tls-verify-registry"),
UseNewRun: c.Bool("use-new-run"),
IgnoreVarRun: c.Bool("ignore-var-run"),
IgnorePath: c.String("ignore-path"),
ImageFSExtractRetry: c.Int("image-fs-extract-retry"),
ImageDownloadRetry: c.Int("image-download-retry"),
Expand All @@ -400,6 +398,14 @@ func run(c *cli.Context) error {
RegistryType: artifact.GAR,
},
}
if c.IsSet("compressed-caching") {
flag := c.Bool("compressed-caching")
plugin.Build.CompressedCaching = &flag
}
if c.IsSet("ignore-var-run") {
flag := c.Bool("ignore-var-run")
plugin.Build.IgnoreVarRun = &flag
}
return plugin.Exec()
}

Expand Down
10 changes: 8 additions & 2 deletions cmd/kaniko-gcr/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -364,7 +364,6 @@ func run(c *cli.Context) error {
CacheCopyLayers: c.Bool("cache-copy-layers"),
CacheRunLayers: c.Bool("cache-run-layers"),
Cleanup: c.Bool("cleanup"),
CompressedCaching: c.Bool("compressed-caching"),
ContextSubPath: c.String("context-sub-path"),
CustomPlatform: c.String("custom-platform"),
Force: c.Bool("force"),
Expand All @@ -388,7 +387,6 @@ func run(c *cli.Context) error {
SkipTLSVerifyPull: c.Bool("skip-tls-verify-pull"),
SkipTLSVerifyRegistry: c.Bool("skip-tls-verify-registry"),
UseNewRun: c.Bool("use-new-run"),
IgnoreVarRun: c.Bool("ignore-var-run"),
IgnorePath: c.String("ignore-path"),
ImageFSExtractRetry: c.Int("image-fs-extract-retry"),
ImageDownloadRetry: c.Int("image-download-retry"),
Expand All @@ -401,6 +399,14 @@ func run(c *cli.Context) error {
RegistryType: artifact.GCR,
},
}
if c.IsSet("compressed-caching") {
flag := c.Bool("compressed-caching")
plugin.Build.CompressedCaching = &flag
}
if c.IsSet("ignore-var-run") {
flag := c.Bool("ignore-var-run")
plugin.Build.IgnoreVarRun = &flag
}
return plugin.Exec()
}

Expand Down
14 changes: 6 additions & 8 deletions kaniko.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ type (
CacheCopyLayers bool // Enable or disable copying layers from the cache.
CacheRunLayers bool // Enable or disable running layers from the cache.
Cleanup bool // Enable or disable cleanup of temporary files.
CompressedCaching bool // Enable or disable compressed caching.
CompressedCaching *bool // Enable or disable compressed caching.
ContextSubPath string // Sub-path within the context to build.
CustomPlatform string // Platform to use for building.
Force bool // Force building the image even if it already exists.
Expand All @@ -72,7 +72,7 @@ type (
SkipTLSVerifyPull bool // Skip TLS verification when pulling.
SkipTLSVerifyRegistry bool // Skip TLS verification when connecting to a registry.
UseNewRun bool // Use the new container runtime (`runc`) for builds.
IgnoreVarRun bool // Ignore `/var/run` when copying from the context.
IgnoreVarRun *bool // Ignore `/var/run` when copying from the context.
IgnorePath string // Ignore files matching the specified path pattern.
ImageFSExtractRetry int // Number of times to retry extracting the image filesystem.
ImageDownloadRetry int // Number of times to retry downloading layers.
Expand Down Expand Up @@ -273,9 +273,8 @@ func (p Plugin) Exec() error {
cmdArgs = append(cmdArgs, "--cleanup=true")
}

_, ok := os.LookupEnv("PLUGIN_COMPRESSED_CACHING")
if ok {
if p.Build.CompressedCaching {
if p.Build.CompressedCaching != nil {
if *p.Build.CompressedCaching {
cmdArgs = append(cmdArgs, "--compressed-caching=true")
} else {
cmdArgs = append(cmdArgs, "--compressed-caching=false")
Expand Down Expand Up @@ -370,9 +369,8 @@ func (p Plugin) Exec() error {
cmdArgs = append(cmdArgs, "--use-new-run")
}

_, ok = os.LookupEnv("PLUGIN_IGNORE_VAR_RUN")
if ok {
if p.Build.IgnoreVarRun {
if p.Build.IgnoreVarRun != nil {
if *p.Build.IgnoreVarRun {
cmdArgs = append(cmdArgs, "--ignore-var-run=true")
} else {
cmdArgs = append(cmdArgs, "--ignore-var-run=false")
Expand Down

0 comments on commit 71882ec

Please sign in to comment.