From dd579cb43612f4349e171506ce3922c1c02cbed7 Mon Sep 17 00:00:00 2001 From: psbits Date: Fri, 10 Dec 2021 18:46:30 +0100 Subject: [PATCH] added the upstream option for the single snapshot mode --- cmd/kaniko-docker/main.go | 40 ++++++++++++++++++++++----------------- cmd/kaniko-ecr/main.go | 38 +++++++++++++++++++++---------------- cmd/kaniko-gcr/main.go | 38 +++++++++++++++++++++---------------- kaniko.go | 39 +++++++++++++++++++++----------------- 4 files changed, 89 insertions(+), 66 deletions(-) diff --git a/cmd/kaniko-docker/main.go b/cmd/kaniko-docker/main.go index 6169075..c4e4244 100644 --- a/cmd/kaniko-docker/main.go +++ b/cmd/kaniko-docker/main.go @@ -110,6 +110,11 @@ func main() { Usage: "Skip registry tls verify", EnvVar: "PLUGIN_SKIP_TLS_VERIFY", }, + cli.StringFlag{ + Name: "single-snapshot", + Usage: "Takes a single snapshot of the filesystem at the end of the build, only that will be appended to the base image", + EnvVar: "PLUGIN_SINGLE_SNAPSHOT", + }, cli.StringFlag{ Name: "snapshot-mode", Usage: "Specify one of full, redo or time as snapshot mode", @@ -170,23 +175,24 @@ func run(c *cli.Context) error { plugin := kaniko.Plugin{ Build: kaniko.Build{ - Dockerfile: c.String("dockerfile"), - Context: c.String("context"), - Tags: c.StringSlice("tags"), - AutoTag: c.Bool("auto_tag"), - Args: c.StringSlice("args"), - Target: c.String("target"), - Repo: c.String("repo"), - Labels: c.StringSlice("custom-labels"), - SkipTlsVerify: c.Bool("skip-tls-verify"), - SnapshotMode: c.String("snapshot-mode"), - EnableCache: c.Bool("enable-cache"), - CacheRepo: c.String("cache-repo"), - CacheTTL: c.Int("cache-ttl"), - DigestFile: defaultDigestFile, - NoPush: noPush, - Verbosity: c.String("verbosity"), - Platform: c.String("platform"), + Dockerfile: c.String("dockerfile"), + Context: c.String("context"), + Tags: c.StringSlice("tags"), + AutoTag: c.Bool("auto_tag"), + Args: c.StringSlice("args"), + Target: c.String("target"), + Repo: c.String("repo"), + Labels: c.StringSlice("custom-labels"), + SkipTlsVerify: c.Bool("skip-tls-verify"), + SingleSnapshot: c.Bool("single-snapshot"), + SnapshotMode: c.String("snapshot-mode"), + EnableCache: c.Bool("enable-cache"), + CacheRepo: c.String("cache-repo"), + CacheTTL: c.Int("cache-ttl"), + DigestFile: defaultDigestFile, + NoPush: noPush, + Verbosity: c.String("verbosity"), + Platform: c.String("platform"), }, Artifact: kaniko.Artifact{ Tags: c.StringSlice("tags"), diff --git a/cmd/kaniko-ecr/main.go b/cmd/kaniko-ecr/main.go index 48fea83..e4f2ad9 100644 --- a/cmd/kaniko-ecr/main.go +++ b/cmd/kaniko-ecr/main.go @@ -129,6 +129,11 @@ func main() { Usage: "ECR secret key", EnvVar: "PLUGIN_SECRET_KEY", }, + cli.StringFlag{ + Name: "single-snapshot", + Usage: "Takes a single snapshot of the filesystem at the end of the build, only that will be appended to the base image", + EnvVar: "PLUGIN_SINGLE_SNAPSHOT", + }, cli.StringFlag{ Name: "snapshot-mode", Usage: "Specify one of full, redo or time as snapshot mode", @@ -242,22 +247,23 @@ func run(c *cli.Context) error { plugin := kaniko.Plugin{ Build: kaniko.Build{ - Dockerfile: c.String("dockerfile"), - Context: c.String("context"), - Tags: c.StringSlice("tags"), - AutoTag: c.Bool("auto_tag"), - Args: c.StringSlice("args"), - Target: c.String("target"), - Repo: fmt.Sprintf("%s/%s", c.String("registry"), c.String("repo")), - Labels: c.StringSlice("custom-labels"), - SnapshotMode: c.String("snapshot-mode"), - EnableCache: c.Bool("enable-cache"), - CacheRepo: fmt.Sprintf("%s/%s", c.String("registry"), c.String("cache-repo")), - CacheTTL: c.Int("cache-ttl"), - DigestFile: defaultDigestFile, - NoPush: noPush, - Verbosity: c.String("verbosity"), - Platform: c.String("platform"), + Dockerfile: c.String("dockerfile"), + Context: c.String("context"), + Tags: c.StringSlice("tags"), + AutoTag: c.Bool("auto_tag"), + Args: c.StringSlice("args"), + Target: c.String("target"), + Repo: fmt.Sprintf("%s/%s", c.String("registry"), c.String("repo")), + Labels: c.StringSlice("custom-labels"), + SingleSnapshot: c.Bool("single-snapshot"), + SnapshotMode: c.String("snapshot-mode"), + EnableCache: c.Bool("enable-cache"), + CacheRepo: fmt.Sprintf("%s/%s", c.String("registry"), c.String("cache-repo")), + CacheTTL: c.Int("cache-ttl"), + DigestFile: defaultDigestFile, + NoPush: noPush, + Verbosity: c.String("verbosity"), + Platform: c.String("platform"), }, Artifact: kaniko.Artifact{ Tags: c.StringSlice("tags"), diff --git a/cmd/kaniko-gcr/main.go b/cmd/kaniko-gcr/main.go index 1492a7b..6664b8d 100644 --- a/cmd/kaniko-gcr/main.go +++ b/cmd/kaniko-gcr/main.go @@ -95,6 +95,11 @@ func main() { Usage: "docker username", EnvVar: "PLUGIN_JSON_KEY", }, + cli.StringFlag{ + Name: "single-snapshot", + Usage: "Takes a single snapshot of the filesystem at the end of the build, only that will be appended to the base image", + EnvVar: "PLUGIN_SINGLE_SNAPSHOT", + }, cli.StringFlag{ Name: "snapshot-mode", Usage: "Specify one of full, redo or time as snapshot mode", @@ -157,22 +162,23 @@ func run(c *cli.Context) error { plugin := kaniko.Plugin{ Build: kaniko.Build{ - Dockerfile: c.String("dockerfile"), - Context: c.String("context"), - Tags: c.StringSlice("tags"), - AutoTag: c.Bool("auto_tag"), - Args: c.StringSlice("args"), - Target: c.String("target"), - Repo: fmt.Sprintf("%s/%s", c.String("registry"), c.String("repo")), - Labels: c.StringSlice("custom-labels"), - SnapshotMode: c.String("snapshot-mode"), - EnableCache: c.Bool("enable-cache"), - CacheRepo: fmt.Sprintf("%s/%s", c.String("registry"), c.String("cache-repo")), - CacheTTL: c.Int("cache-ttl"), - DigestFile: defaultDigestFile, - NoPush: noPush, - Verbosity: c.String("verbosity"), - Platform: c.String("platform"), + Dockerfile: c.String("dockerfile"), + Context: c.String("context"), + Tags: c.StringSlice("tags"), + AutoTag: c.Bool("auto_tag"), + Args: c.StringSlice("args"), + Target: c.String("target"), + Repo: fmt.Sprintf("%s/%s", c.String("registry"), c.String("repo")), + Labels: c.StringSlice("custom-labels"), + SingleSnapshot: c.Bool("single-snapshot"), + SnapshotMode: c.String("snapshot-mode"), + EnableCache: c.Bool("enable-cache"), + CacheRepo: fmt.Sprintf("%s/%s", c.String("registry"), c.String("cache-repo")), + CacheTTL: c.Int("cache-ttl"), + DigestFile: defaultDigestFile, + NoPush: noPush, + Verbosity: c.String("verbosity"), + Platform: c.String("platform"), }, Artifact: kaniko.Artifact{ Tags: c.StringSlice("tags"), diff --git a/kaniko.go b/kaniko.go index 78d1f97..8f67527 100644 --- a/kaniko.go +++ b/kaniko.go @@ -14,23 +14,24 @@ import ( type ( // Build defines Docker build parameters. Build struct { - Dockerfile string // Docker build Dockerfile - Context string // Docker build context - Tags []string // Docker build tags - AutoTag bool // Set this to create semver-tagged labels - Args []string // Docker build args - Target string // Docker build target - Repo string // Docker build repository - Labels []string // Label map - SkipTlsVerify bool // Docker skip tls certificate verify for registry - SnapshotMode string // Kaniko snapshot mode - EnableCache bool // Whether to enable kaniko cache - CacheRepo string // Remote repository that will be used to store cached layers - CacheTTL int // Cache timeout in hours - DigestFile string // Digest file location - NoPush bool // Set this flag if you only want to build the image, without pushing to a registry - Verbosity string // Log level - Platform string // Allows to build with another default platform than the host, similarly to docker build --platform + Dockerfile string // Docker build Dockerfile + Context string // Docker build context + Tags []string // Docker build tags + AutoTag bool // Set this to create semver-tagged labels + Args []string // Docker build args + Target string // Docker build target + Repo string // Docker build repository + Labels []string // Label map + SkipTlsVerify bool // Docker skip tls certificate verify for registry + SingleSnapshot bool // Kaniko single snapshot mode + SnapshotMode string // Kaniko snapshot mode + EnableCache bool // Whether to enable kaniko cache + CacheRepo string // Remote repository that will be used to store cached layers + CacheTTL int // Cache timeout in hours + DigestFile string // Digest file location + NoPush bool // Set this flag if you only want to build the image, without pushing to a registry + Verbosity string // Log level + Platform string // Allows to build with another default platform than the host, similarly to docker build --platform } // Artifact defines content of artifact file @@ -134,6 +135,10 @@ func (p Plugin) Exec() error { cmdArgs = append(cmdArgs, fmt.Sprintf("--snapshotMode=%s", p.Build.SnapshotMode)) } + if p.Build.SingleSnapshot { + cmdArgs = append(cmdArgs, "--single-snapshot=true") + } + if p.Build.EnableCache { cmdArgs = append(cmdArgs, "--cache=true")