Allow remote caching of docker layers in kaniko build (#16)
This commit is contained in:
parent
0933926fe2
commit
4612825d41
@ -104,6 +104,21 @@ func main() {
|
|||||||
Usage: "Specify one of full, redo or time as snapshot mode",
|
Usage: "Specify one of full, redo or time as snapshot mode",
|
||||||
EnvVar: "PLUGIN_SNAPSHOT_MODE",
|
EnvVar: "PLUGIN_SNAPSHOT_MODE",
|
||||||
},
|
},
|
||||||
|
cli.BoolFlag{
|
||||||
|
Name: "enable-cache",
|
||||||
|
Usage: "Set this flag to opt into caching with kaniko",
|
||||||
|
EnvVar: "PLUGIN_ENABLE_CACHE",
|
||||||
|
},
|
||||||
|
cli.StringFlag{
|
||||||
|
Name: "cache-repo",
|
||||||
|
Usage: "Remote repository that will be used to store cached layers. enable-cache needs to be set to use this flag",
|
||||||
|
EnvVar: "PLUGIN_CACHE_REPO",
|
||||||
|
},
|
||||||
|
cli.IntFlag{
|
||||||
|
Name: "cache-ttl",
|
||||||
|
Usage: "Cache timeout in hours. Defaults to two weeks.",
|
||||||
|
EnvVar: "PLUGIN_CACHE_TTL",
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := app.Run(os.Args); err != nil {
|
if err := app.Run(os.Args); err != nil {
|
||||||
@ -128,6 +143,9 @@ func run(c *cli.Context) error {
|
|||||||
Labels: c.StringSlice("custom-labels"),
|
Labels: c.StringSlice("custom-labels"),
|
||||||
SkipTlsVerify: c.Bool("skip-tls-verify"),
|
SkipTlsVerify: c.Bool("skip-tls-verify"),
|
||||||
SnapshotMode: c.String("snapshot-mode"),
|
SnapshotMode: c.String("snapshot-mode"),
|
||||||
|
EnableCache: c.Bool("enable-cache"),
|
||||||
|
CacheRepo: c.String("cache-repo"),
|
||||||
|
CacheTTL: c.Int("cache-ttl"),
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
return plugin.Exec()
|
return plugin.Exec()
|
||||||
|
@ -94,6 +94,21 @@ func main() {
|
|||||||
Usage: "Specify one of full, redo or time as snapshot mode",
|
Usage: "Specify one of full, redo or time as snapshot mode",
|
||||||
EnvVar: "PLUGIN_SNAPSHOT_MODE",
|
EnvVar: "PLUGIN_SNAPSHOT_MODE",
|
||||||
},
|
},
|
||||||
|
cli.BoolFlag{
|
||||||
|
Name: "enable-cache",
|
||||||
|
Usage: "Set this flag to opt into caching with kaniko",
|
||||||
|
EnvVar: "PLUGIN_ENABLE_CACHE",
|
||||||
|
},
|
||||||
|
cli.StringFlag{
|
||||||
|
Name: "cache-repo",
|
||||||
|
Usage: "Remote repository that will be used to store cached layers. enable-cache needs to be set to use this flag",
|
||||||
|
EnvVar: "PLUGIN_CACHE_REPO",
|
||||||
|
},
|
||||||
|
cli.IntFlag{
|
||||||
|
Name: "cache-ttl",
|
||||||
|
Usage: "Cache timeout in hours. Defaults to two weeks.",
|
||||||
|
EnvVar: "PLUGIN_CACHE_TTL",
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := app.Run(os.Args); err != nil {
|
if err := app.Run(os.Args); err != nil {
|
||||||
@ -117,6 +132,9 @@ func run(c *cli.Context) error {
|
|||||||
Repo: fmt.Sprintf("%s/%s", c.String("registry"), c.String("repo")),
|
Repo: fmt.Sprintf("%s/%s", c.String("registry"), c.String("repo")),
|
||||||
Labels: c.StringSlice("custom-labels"),
|
Labels: c.StringSlice("custom-labels"),
|
||||||
SnapshotMode: c.String("snapshot-mode"),
|
SnapshotMode: c.String("snapshot-mode"),
|
||||||
|
EnableCache: c.Bool("enable-cache"),
|
||||||
|
CacheRepo: c.String("cache-repo"),
|
||||||
|
CacheTTL: c.Int("cache-ttl"),
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
return plugin.Exec()
|
return plugin.Exec()
|
||||||
|
@ -90,6 +90,21 @@ func main() {
|
|||||||
Usage: "Specify one of full, redo or time as snapshot mode",
|
Usage: "Specify one of full, redo or time as snapshot mode",
|
||||||
EnvVar: "PLUGIN_SNAPSHOT_MODE",
|
EnvVar: "PLUGIN_SNAPSHOT_MODE",
|
||||||
},
|
},
|
||||||
|
cli.BoolFlag{
|
||||||
|
Name: "enable-cache",
|
||||||
|
Usage: "Set this flag to opt into caching with kaniko",
|
||||||
|
EnvVar: "PLUGIN_ENABLE_CACHE",
|
||||||
|
},
|
||||||
|
cli.StringFlag{
|
||||||
|
Name: "cache-repo",
|
||||||
|
Usage: "Remote repository that will be used to store cached layers. enable-cache needs to be set to use this flag",
|
||||||
|
EnvVar: "PLUGIN_CACHE_REPO",
|
||||||
|
},
|
||||||
|
cli.IntFlag{
|
||||||
|
Name: "cache-ttl",
|
||||||
|
Usage: "Cache timeout in hours. Defaults to two weeks.",
|
||||||
|
EnvVar: "PLUGIN_CACHE_TTL",
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := app.Run(os.Args); err != nil {
|
if err := app.Run(os.Args); err != nil {
|
||||||
@ -117,6 +132,9 @@ func run(c *cli.Context) error {
|
|||||||
Repo: fmt.Sprintf("%s/%s", c.String("registry"), c.String("repo")),
|
Repo: fmt.Sprintf("%s/%s", c.String("registry"), c.String("repo")),
|
||||||
Labels: c.StringSlice("custom-labels"),
|
Labels: c.StringSlice("custom-labels"),
|
||||||
SnapshotMode: c.String("snapshot-mode"),
|
SnapshotMode: c.String("snapshot-mode"),
|
||||||
|
EnableCache: c.Bool("enable-cache"),
|
||||||
|
CacheRepo: c.String("cache-repo"),
|
||||||
|
CacheTTL: c.Int("cache-ttl"),
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
return plugin.Exec()
|
return plugin.Exec()
|
||||||
|
15
kaniko.go
15
kaniko.go
@ -19,6 +19,9 @@ type (
|
|||||||
Labels []string // Label map
|
Labels []string // Label map
|
||||||
SkipTlsVerify bool // Docker skip tls certificate verify for registry
|
SkipTlsVerify bool // Docker skip tls certificate verify for registry
|
||||||
SnapshotMode string // Kaniko 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
|
||||||
}
|
}
|
||||||
|
|
||||||
// Plugin defines the Docker plugin parameters.
|
// Plugin defines the Docker plugin parameters.
|
||||||
@ -67,6 +70,18 @@ func (p Plugin) Exec() error {
|
|||||||
cmdArgs = append(cmdArgs, fmt.Sprintf("--snapshotMode=%s", p.Build.SnapshotMode))
|
cmdArgs = append(cmdArgs, fmt.Sprintf("--snapshotMode=%s", p.Build.SnapshotMode))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if p.Build.EnableCache == true {
|
||||||
|
cmdArgs = append(cmdArgs, fmt.Sprintf("--cache=true"))
|
||||||
|
}
|
||||||
|
|
||||||
|
if p.Build.CacheRepo != "" {
|
||||||
|
cmdArgs = append(cmdArgs, fmt.Sprintf("--cache-repo=%s", p.Build.CacheRepo))
|
||||||
|
}
|
||||||
|
|
||||||
|
if p.Build.CacheTTL != 0 {
|
||||||
|
cmdArgs = append(cmdArgs, fmt.Sprintf("--cache-ttl=%d", p.Build.CacheTTL))
|
||||||
|
}
|
||||||
|
|
||||||
cmd := exec.Command("/kaniko/executor", cmdArgs...)
|
cmd := exec.Command("/kaniko/executor", cmdArgs...)
|
||||||
cmd.Stdout = os.Stdout
|
cmd.Stdout = os.Stdout
|
||||||
cmd.Stderr = os.Stderr
|
cmd.Stderr = os.Stderr
|
||||||
|
Loading…
Reference in New Issue
Block a user