Skip to content

Commit

Permalink
feat: Cleanup dist directory before startup
Browse files Browse the repository at this point in the history
  • Loading branch information
julienvey committed Feb 2, 2022
1 parent a99f8f6 commit e2adeb5
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import (
"path"
"strings"

"github.com/sirupsen/logrus"

"github.com/spf13/cobra"
"github.com/spf13/pflag"
"github.com/spf13/viper"
Expand All @@ -18,6 +20,7 @@ const (
defaultBuildPath = "docker"
defaultKanikoImage = "gcr.io/kaniko-project/executor:v1.7.0"
defaultKubernetesNamespace = "default"
distDirectory = "dist"
)

type rootOpts struct {
Expand All @@ -44,7 +47,7 @@ func Execute() {
}

func init() {
cobra.OnInitialize(initConfig, initLogLevel)
cobra.OnInitialize(initConfig, initLogLevel, cleanupDist)

desc := `Path to the directory you want to build All Dockerfiles within this directory will be recursively
found and added to the build graph. You can provide any subdirectory if you want to focus on a reduced set of images,
Expand All @@ -65,6 +68,12 @@ be considered as the root directory for the hash generation and comparison`
bindPFlagsSnakeCase(rootCmd.PersistentFlags())
}

func cleanupDist() {
logrus.Debugf("Cleaning up %s directory before startup", distDirectory)
// Ignore any error
_ = os.RemoveAll(distDirectory)
}

// initConfig reads in config file and ENV variables if set.
func initConfig() {
if cfgFile != "" {
Expand Down

0 comments on commit e2adeb5

Please sign in to comment.