diff --git a/cmd/kaniko-docker/main.go b/cmd/kaniko-docker/main.go index a0511da..5036d7c 100644 --- a/cmd/kaniko-docker/main.go +++ b/cmd/kaniko-docker/main.go @@ -201,6 +201,157 @@ func main() { Usage: "Output file location that will be generated by the plugin. This file will include information of the output that are exported by the plugin.", EnvVar: "DRONE_OUTPUT", }, + cli.StringFlag{ + Name: "cache-dir", + Usage: "Set this flag to specify a local directory cache for base images", + EnvVar: "PLUGIN_CACHE_DIR", + }, + + cli.BoolFlag{ + Name: "cache-copy-layers", + Usage: "Enable or disable copying layers from the cache.", + EnvVar: "PLUGIN_CACHE_COPY_LAYERS", + }, + cli.BoolFlag{ + Name: "cache-run-layers", + Usage: "Enable or disable running layers from the cache.", + EnvVar: "PLUGIN_CACHE_RUN_LAYERS", + }, + cli.BoolFlag{ + Name: "cleanup", + Usage: "Enable or disable cleanup of temporary files.", + EnvVar: "PLUGIN_CLEANUP", + }, + cli.BoolFlag{ + Name: "compressed-caching", + Usage: "Enable or disable compressed caching.", + EnvVar: "PLUGIN_COMPRESSED_CACHING", + }, + cli.StringFlag{ + Name: "context-sub-path", + Usage: "Sub-path within the context to build.", + EnvVar: "PLUGIN_CONTEXT_SUB_PATH", + }, + cli.StringFlag{ + Name: "custom-platform", + Usage: "Platform to use for building.", + EnvVar: "PLUGIN_CUSTOM_PLATFORM", + }, + cli.BoolFlag{ + Name: "force", + Usage: "Force building the image even if it already exists.", + EnvVar: "PLUGIN_FORCE", + }, + cli.BoolFlag{ + Name: "image-name-with-digest-file", + Usage: "Write image name with digest to a file.", + EnvVar: "PLUGIN_IMAGE_NAME_WITH_DIGEST_FILE", + }, + cli.BoolFlag{ + Name: "image-name-tag-with-digest-file", + Usage: "Write image name with tag and digest to a file.", + EnvVar: "PLUGIN_IMAGE_NAME_TAG_WITH_DIGEST_FILE", + }, + cli.BoolFlag{ + Name: "insecure", + Usage: "Allow connecting to registries without TLS.", + EnvVar: "PLUGIN_INSECURE", + }, + cli.BoolFlag{ + Name: "insecure-pull", + Usage: "Allow insecure pulls from the registry.", + EnvVar: "PLUGIN_INSECURE_PULL", + }, + cli.BoolFlag{ + Name: "insecure-registry", + Usage: "Use plain HTTP for registry communication.", + EnvVar: "PLUGIN_INSECURE_REGISTRY", + }, + cli.StringFlag{ + Name: "log-format", + Usage: "Set the log format for build output.", + EnvVar: "PLUGIN_LOG_FORMAT", + }, + cli.BoolFlag{ + Name: "log-timestamp", + Usage: "Show timestamps in build output.", + EnvVar: "PLUGIN_LOG_TIMESTAMP", + }, + cli.StringFlag{ + Name: "oci-layout-path", + Usage: "Directory to store OCI layout.", + EnvVar: "PLUGIN_OCI_LAYOUT_PATH", + }, + cli.IntFlag{ + Name: "push-retry", + Usage: "Number of times to retry pushing an image.", + EnvVar: "PLUGIN_PUSH_RETRY", + }, + cli.StringFlag{ + Name: "registry-certificate", + Usage: "Path to a file containing a registry certificate.", + EnvVar: "PLUGIN_REGISTRY_CERTIFICATE", + }, + cli.StringFlag{ + Name: "registry-client-cert", + Usage: "Path to a file containing a registry client certificate.", + EnvVar: "PLUGIN_REGISTRY_CLIENT_CERT", + }, + cli.BoolFlag{ + Name: "skip-default-registry-fallback", + Usage: "Skip Docker Hub and default registry fallback.", + EnvVar: "PLUGIN_SKIP_DEFAULT_REGISTRY_FALLBACK", + }, + cli.BoolFlag{ + Name: "reproducible", + Usage: "Create a reproducible image.", + EnvVar: "PLUGIN_REPRODUCIBLE", + }, + cli.BoolFlag{ + Name: "single-snapshot", + Usage: "Only create a single snapshot of the image.", + EnvVar: "PLUGIN_SINGLE_SNAPSHOT", + }, + cli.BoolFlag{ + Name: "skip-push-permission-check", + Usage: "Skip permission check when pushing.", + EnvVar: "PLUGIN_SKIP_PUSH_PERMISSION_CHECK", + }, + cli.BoolFlag{ + Name: "skip-tls-verify-pull", + Usage: "Skip TLS verification when pulling.", + EnvVar: "PLUGIN_SKIP_TLS_VERIFY_PULL", + }, + cli.BoolFlag{ + Name: "skip-tls-verify-registry", + Usage: "Skip TLS verification when connecting to a registry.", + EnvVar: "PLUGIN_SKIP_TLS_VERIFY_REGISTRY", + }, + cli.BoolFlag{ + Name: "use-new-run", + Usage: "Skip TLS verification when connecting to a registry.", + EnvVar: "PLUGIN_USE_NEW_RUN", + }, + cli.BoolFlag{ + Name: "ignore-var-run", + Usage: "Ignore the /var/run directory during build.", + EnvVar: "PLUGIN_IGNORE_VAR_RUN", + }, + cli.StringFlag{ + Name: "ignore-path", + Usage: "Path to ignore during the build.", + EnvVar: "PLUGIN_IGNORE_PATH", + }, + cli.IntFlag{ + Name: "image-fs-extract-retry", + Usage: "Number of retries for extracting filesystem layers.", + EnvVar: "PLUGIN_IMAGE_FS_EXTRACT_RETRY", + }, + cli.IntFlag{ + Name: "image-download-retry", + Usage: "Number of retries for downloading base images.", + EnvVar: "PLUGIN_IMAGE_DOWNLOAD_RETRY", + }, } if err := app.Run(os.Args); err != nil { diff --git a/kaniko.go b/kaniko.go index 62d324c..b3dbfab 100644 --- a/kaniko.go +++ b/kaniko.go @@ -40,6 +40,42 @@ type ( Platform string // Allows to build with another default platform than the host, similarly to docker build --platform SkipUnusedStages bool // Build only used stages TarPath string // Set this flag to save the image as a tarball at path + + Cache bool // Enable or disable caching during the build process. + CacheDir string // Directory to store cached layers. + 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. + 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. + Git bool // Branch to clone if build context is a git repository . + ImageNameWithDigestFile string // Write image name with digest to a file. + ImageNameTagWithDigestFile string // Write image name with tag and digest to a file. + Insecure bool // Allow connecting to registries without TLS. + InsecurePull bool // Allow insecure pulls from the registry. + InsecureRegistry string // Use plain HTTP for registry communication. + Label string // Add metadata to an image. + LogFormat string // Set the log format for build output. + LogTimestamp bool // Show timestamps in build output. + OCILayoutPath string // Directory to store OCI layout. + PushRetry int // Number of times to retry pushing an image. + RegistryCertificate string // Path to a file containing a registry certificate. + RegistryClientCert string // Path to a file containing a registry client certificate. + RegistryMirror string // Mirror for registry pulls. + SkipDefaultRegistryFallback bool // Skip Docker Hub and default registry fallback. + Reproducible bool // Create a reproducible image. + SingleSnapshot bool // Only create a single snapshot of the image. + SkipTLSVerify bool // Skip TLS verification when connecting to the registry. + SkipPushPermissionCheck bool // Skip permission check when pushing. + 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. + 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. } // Artifact defines content of artifact file @@ -224,7 +260,128 @@ func (p Plugin) Exec() error { if p.Build.TarPath != "" { cmdArgs = append(cmdArgs, fmt.Sprintf("--tar-path=%s", p.Build.TarPath)) } - + + if p.Build.CacheCopyLayers { + cmdArgs = append(cmdArgs, "--cache-copy-layers") + } + + if p.Build.CacheRunLayers { + cmdArgs = append(cmdArgs, "--cache-run-layers=true") + } + + if p.Build.Cleanup { + cmdArgs = append(cmdArgs, "--cleanup=true") + } + + compressedCaching, ok := os.LookupEnv("PLUGIN_COMPRESSED_CACHING") + if ok { + cmdArgs = append(cmdArgs, "--compressed-caching=%s", compressedCaching) + } + + if p.Build.ContextSubPath != "" { + cmdArgs = append(cmdArgs, fmt.Sprintf("--context-sub-path=%s", p.Build.ContextSubPath)) + } + + if p.Build.CustomPlatform != "" { + cmdArgs = append(cmdArgs, fmt.Sprintf("--custom-platform=%s", p.Build.CustomPlatform)) + } + + if p.Build.Force { + cmdArgs = append(cmdArgs, "--force") + } + + if p.Build.Git { + cmdArgs = append(cmdArgs, "--git") + } + + if p.Build.ImageNameWithDigestFile != "" { + cmdArgs = append(cmdArgs, fmt.Sprintf("--image-name-with-digest-file=%s", p.Build.ImageNameWithDigestFile)) + } + + if p.Build.ImageNameTagWithDigestFile != "" { + cmdArgs = append(cmdArgs, fmt.Sprintf("--image-name-tag-with-digest-file=%s", p.Build.ImageNameTagWithDigestFile)) + } + + if p.Build.Insecure { + cmdArgs = append(cmdArgs, "--insecure") + } + + if p.Build.InsecurePull { + cmdArgs = append(cmdArgs, "--insecure-pull") + } + + if p.Build.InsecureRegistry != "" { + cmdArgs = append(cmdArgs, fmt.Sprintf("--insecure-registry=%s", p.Build.InsecureRegistry)) + } + + if p.Build.LogFormat != "" { + cmdArgs = append(cmdArgs, fmt.Sprintf("--log-format=%s", p.Build.LogFormat)) + } + + if p.Build.LogTimestamp { + cmdArgs = append(cmdArgs, "--log-timestamp") + } + + if p.Build.OCILayoutPath != "" { + cmdArgs = append(cmdArgs, fmt.Sprintf("--oci-layout-path=%s", p.Build.OCILayoutPath)) + } + + if p.Build.PushRetry != 0 { + cmdArgs = append(cmdArgs, fmt.Sprintf("--push-retry=%d", p.Build.PushRetry)) + } + + if p.Build.RegistryCertificate != "" { + cmdArgs = append(cmdArgs, fmt.Sprintf("--registry-certificate=%s", p.Build.RegistryCertificate)) + } + + if p.Build.RegistryClientCert != "" { + cmdArgs = append(cmdArgs, fmt.Sprintf("--registry-client-cert=%s", p.Build.RegistryClientCert)) + } + + if p.Build.SkipDefaultRegistryFallback { + cmdArgs = append(cmdArgs, "--skip-default-registry-fallback") + } + + if p.Build.Reproducible { + cmdArgs = append(cmdArgs, "--reproducible") + } + + if p.Build.SingleSnapshot { + cmdArgs = append(cmdArgs, "--single-snapshot") + } + + if p.Build.SkipPushPermissionCheck { + cmdArgs = append(cmdArgs, "--skip-push-permission-check") + } + + if p.Build.SkipTLSVerifyPull { + cmdArgs = append(cmdArgs, "--skip-tls-verify-pull") + } + + if p.Build.SkipTLSVerifyRegistry { + cmdArgs = append(cmdArgs, "--skip-tls-verify-registry") + } + + if p.Build.UseNewRun { + cmdArgs = append(cmdArgs, "--use-new-run") + } + + if p.Build.IgnoreVarRun { + cmdArgs = append(cmdArgs, "--ignore-var-run") + } + + if p.Build.IgnorePath != "" { + cmdArgs = append(cmdArgs, fmt.Sprintf("--ignore-path=%s", p.Build.IgnorePath)) + } + + if p.Build.ImageFSExtractRetry != 0 { + cmdArgs = append(cmdArgs, fmt.Sprintf("--image-fs-extract-retry=%d", p.Build.ImageFSExtractRetry)) + } + + if p.Build.ImageDownloadRetry != 0 { + cmdArgs = append(cmdArgs, fmt.Sprintf("--image-download-retry=%d", p.Build.ImageDownloadRetry)) + } + cmd := exec.Command("/kaniko/executor", cmdArgs...) cmd.Stdout = os.Stdout cmd.Stderr = os.Stderr