Skip unused stages flag (#49)

* skip unused stages flag

* re-add smithy
This commit is contained in:
Peter Novotnak 2022-04-08 22:27:17 -07:00 committed by GitHub
parent c39a1155b5
commit 89b4f6b0c9
Signed by: GitHub
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 110 additions and 87 deletions

@ -181,6 +181,11 @@ func main() {
Usage: "Allows to build with another default platform than the host, similarly to docker build --platform", Usage: "Allows to build with another default platform than the host, similarly to docker build --platform",
EnvVar: "PLUGIN_PLATFORM", EnvVar: "PLUGIN_PLATFORM",
}, },
cli.BoolFlag{
Name: "skip-unused-stages",
Usage: "build only used stages",
EnvVar: "PLUGIN_SKIP_UNUSED_STAGES",
},
} }
if err := app.Run(os.Args); err != nil { if err := app.Run(os.Args); err != nil {
@ -201,28 +206,29 @@ func run(c *cli.Context) error {
plugin := kaniko.Plugin{ plugin := kaniko.Plugin{
Build: kaniko.Build{ Build: kaniko.Build{
DroneCommitRef: c.String("drone-commit-ref"), DroneCommitRef: c.String("drone-commit-ref"),
DroneRepoBranch: c.String("drone-repo-branch"), DroneRepoBranch: c.String("drone-repo-branch"),
Dockerfile: c.String("dockerfile"), Dockerfile: c.String("dockerfile"),
Context: c.String("context"), Context: c.String("context"),
Tags: c.StringSlice("tags"), Tags: c.StringSlice("tags"),
AutoTag: c.Bool("auto-tag"), AutoTag: c.Bool("auto-tag"),
AutoTagSuffix: c.String("auto-tag-suffix"), AutoTagSuffix: c.String("auto-tag-suffix"),
ExpandTag: c.Bool("expand-tag"), ExpandTag: c.Bool("expand-tag"),
Args: c.StringSlice("args"), Args: c.StringSlice("args"),
Target: c.String("target"), Target: c.String("target"),
Repo: buildRepo(c.String("registry"), c.String("repo"), c.Bool("expand-repo")), Repo: buildRepo(c.String("registry"), c.String("repo"), c.Bool("expand-repo")),
Mirrors: c.StringSlice("registry-mirrors"), Mirrors: c.StringSlice("registry-mirrors"),
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"), EnableCache: c.Bool("enable-cache"),
CacheRepo: buildRepo(c.String("registry"), c.String("cache-repo"), c.Bool("expand-repo")), CacheRepo: buildRepo(c.String("registry"), c.String("cache-repo"), c.Bool("expand-repo")),
CacheTTL: c.Int("cache-ttl"), CacheTTL: c.Int("cache-ttl"),
DigestFile: defaultDigestFile, DigestFile: defaultDigestFile,
NoPush: noPush, NoPush: noPush,
Verbosity: c.String("verbosity"), Verbosity: c.String("verbosity"),
Platform: c.String("platform"), Platform: c.String("platform"),
SkipUnusedStages: c.Bool("skip-unused-stages"),
}, },
Artifact: kaniko.Artifact{ Artifact: kaniko.Artifact{
Tags: c.StringSlice("tags"), Tags: c.StringSlice("tags"),

@ -12,7 +12,7 @@ import (
"github.com/aws/aws-sdk-go-v2/config" "github.com/aws/aws-sdk-go-v2/config"
"github.com/aws/aws-sdk-go-v2/service/ecr" "github.com/aws/aws-sdk-go-v2/service/ecr"
"github.com/aws/aws-sdk-go-v2/service/ecrpublic" "github.com/aws/aws-sdk-go-v2/service/ecrpublic"
"github.com/aws/smithy-go" "github.com/aws/smithy-go"
kaniko "github.com/drone/drone-kaniko" kaniko "github.com/drone/drone-kaniko"
"github.com/drone/drone-kaniko/pkg/artifact" "github.com/drone/drone-kaniko/pkg/artifact"
"github.com/drone/drone-kaniko/pkg/docker" "github.com/drone/drone-kaniko/pkg/docker"
@ -204,6 +204,11 @@ func main() {
Usage: "Allows to build with another default platform than the host, similarly to docker build --platform", Usage: "Allows to build with another default platform than the host, similarly to docker build --platform",
EnvVar: "PLUGIN_PLATFORM", EnvVar: "PLUGIN_PLATFORM",
}, },
cli.BoolFlag{
Name: "skip-unused-stages",
Usage: "build only used stages",
EnvVar: "PLUGIN_SKIP_UNUSED_STAGES",
},
} }
if err := app.Run(os.Args); err != nil { if err := app.Run(os.Args); err != nil {
@ -267,27 +272,28 @@ func run(c *cli.Context) error {
plugin := kaniko.Plugin{ plugin := kaniko.Plugin{
Build: kaniko.Build{ Build: kaniko.Build{
DroneCommitRef: c.String("drone-commit-ref"), DroneCommitRef: c.String("drone-commit-ref"),
DroneRepoBranch: c.String("drone-repo-branch"), DroneRepoBranch: c.String("drone-repo-branch"),
Dockerfile: c.String("dockerfile"), Dockerfile: c.String("dockerfile"),
Context: c.String("context"), Context: c.String("context"),
Tags: c.StringSlice("tags"), Tags: c.StringSlice("tags"),
AutoTag: c.Bool("auto-tag"), AutoTag: c.Bool("auto-tag"),
AutoTagSuffix: c.String("auto-tag-suffix"), AutoTagSuffix: c.String("auto-tag-suffix"),
ExpandTag: c.Bool("expand-tag"), ExpandTag: c.Bool("expand-tag"),
Args: c.StringSlice("args"), Args: c.StringSlice("args"),
Target: c.String("target"), Target: c.String("target"),
Repo: fmt.Sprintf("%s/%s", c.String("registry"), c.String("repo")), Repo: fmt.Sprintf("%s/%s", c.String("registry"), c.String("repo")),
Mirrors: c.StringSlice("registry-mirrors"), Mirrors: c.StringSlice("registry-mirrors"),
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"), EnableCache: c.Bool("enable-cache"),
CacheRepo: fmt.Sprintf("%s/%s", c.String("registry"), c.String("cache-repo")), CacheRepo: fmt.Sprintf("%s/%s", c.String("registry"), c.String("cache-repo")),
CacheTTL: c.Int("cache-ttl"), CacheTTL: c.Int("cache-ttl"),
DigestFile: defaultDigestFile, DigestFile: defaultDigestFile,
NoPush: noPush, NoPush: noPush,
Verbosity: c.String("verbosity"), Verbosity: c.String("verbosity"),
Platform: c.String("platform"), Platform: c.String("platform"),
SkipUnusedStages: c.Bool("skip-unused-stages"),
}, },
Artifact: kaniko.Artifact{ Artifact: kaniko.Artifact{
Tags: c.StringSlice("tags"), Tags: c.StringSlice("tags"),

@ -160,6 +160,11 @@ func main() {
Usage: "Allows to build with another default platform than the host, similarly to docker build --platform", Usage: "Allows to build with another default platform than the host, similarly to docker build --platform",
EnvVar: "PLUGIN_PLATFORM", EnvVar: "PLUGIN_PLATFORM",
}, },
cli.BoolFlag{
Name: "skip-unused-stages",
Usage: "build only used stages",
EnvVar: "PLUGIN_SKIP_UNUSED_STAGES",
},
} }
if err := app.Run(os.Args); err != nil { if err := app.Run(os.Args); err != nil {
@ -182,27 +187,28 @@ func run(c *cli.Context) error {
plugin := kaniko.Plugin{ plugin := kaniko.Plugin{
Build: kaniko.Build{ Build: kaniko.Build{
DroneCommitRef: c.String("drone-commit-ref"), DroneCommitRef: c.String("drone-commit-ref"),
DroneRepoBranch: c.String("drone-repo-branch"), DroneRepoBranch: c.String("drone-repo-branch"),
Dockerfile: c.String("dockerfile"), Dockerfile: c.String("dockerfile"),
Context: c.String("context"), Context: c.String("context"),
Tags: c.StringSlice("tags"), Tags: c.StringSlice("tags"),
AutoTag: c.Bool("auto-tag"), AutoTag: c.Bool("auto-tag"),
AutoTagSuffix: c.String("auto-tag-suffix"), AutoTagSuffix: c.String("auto-tag-suffix"),
ExpandTag: c.Bool("expand-tag"), ExpandTag: c.Bool("expand-tag"),
Args: c.StringSlice("args"), Args: c.StringSlice("args"),
Target: c.String("target"), Target: c.String("target"),
Repo: fmt.Sprintf("%s/%s", c.String("registry"), c.String("repo")), Repo: fmt.Sprintf("%s/%s", c.String("registry"), c.String("repo")),
Mirrors: c.StringSlice("registry-mirrors"), Mirrors: c.StringSlice("registry-mirrors"),
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"), EnableCache: c.Bool("enable-cache"),
CacheRepo: fmt.Sprintf("%s/%s", c.String("registry"), c.String("cache-repo")), CacheRepo: fmt.Sprintf("%s/%s", c.String("registry"), c.String("cache-repo")),
CacheTTL: c.Int("cache-ttl"), CacheTTL: c.Int("cache-ttl"),
DigestFile: defaultDigestFile, DigestFile: defaultDigestFile,
NoPush: noPush, NoPush: noPush,
Verbosity: c.String("verbosity"), Verbosity: c.String("verbosity"),
Platform: c.String("platform"), Platform: c.String("platform"),
SkipUnusedStages: c.Bool("skip-unused-stages"),
}, },
Artifact: kaniko.Artifact{ Artifact: kaniko.Artifact{
Tags: c.StringSlice("tags"), Tags: c.StringSlice("tags"),

@ -15,28 +15,29 @@ import (
type ( type (
// Build defines Docker build parameters. // Build defines Docker build parameters.
Build struct { Build struct {
DroneCommitRef string // Drone git commit reference DroneCommitRef string // Drone git commit reference
DroneRepoBranch string // Drone repo branch DroneRepoBranch string // Drone repo branch
Dockerfile string // Docker build Dockerfile Dockerfile string // Docker build Dockerfile
Context string // Docker build context Context string // Docker build context
Tags []string // Docker build tags Tags []string // Docker build tags
AutoTag bool // Set this to auto detect tags from git commits and semver-tagged labels AutoTag bool // Set this to auto detect tags from git commits and semver-tagged labels
AutoTagSuffix string // Suffix to append to the auto detect tags AutoTagSuffix string // Suffix to append to the auto detect tags
ExpandTag bool // Set this to expand the `Tags` into semver-tagged labels ExpandTag bool // Set this to expand the `Tags` into semver-tagged labels
Args []string // Docker build args Args []string // Docker build args
Target string // Docker build target Target string // Docker build target
Repo string // Docker build repository Repo string // Docker build repository
Mirrors []string // Docker repository mirrors Mirrors []string // Docker repository mirrors
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 EnableCache bool // Whether to enable kaniko cache
CacheRepo string // Remote repository that will be used to store cached layers CacheRepo string // Remote repository that will be used to store cached layers
CacheTTL int // Cache timeout in hours CacheTTL int // Cache timeout in hours
DigestFile string // Digest file location DigestFile string // Digest file location
NoPush bool // Set this flag if you only want to build the image, without pushing to a registry NoPush bool // Set this flag if you only want to build the image, without pushing to a registry
Verbosity string // Log level Verbosity string // Log level
Platform string // Allows to build with another default platform than the host, similarly to docker build --platform Platform string // Allows to build with another default platform than the host, similarly to docker build --platform
SkipUnusedStages bool // Build only used stages
} }
// Artifact defines content of artifact file // Artifact defines content of artifact file
@ -207,6 +208,10 @@ func (p Plugin) Exec() error {
cmdArgs = append(cmdArgs, fmt.Sprintf("--customPlatform=%s", p.Build.Platform)) cmdArgs = append(cmdArgs, fmt.Sprintf("--customPlatform=%s", p.Build.Platform))
} }
if p.Build.SkipUnusedStages {
cmdArgs = append(cmdArgs, "--skip-unused-stages")
}
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