diff --git a/Makefile b/Makefile index b7534050..0d7763d5 100644 --- a/Makefile +++ b/Makefile @@ -4,4 +4,4 @@ install: bin .PHONY: bin bin: - go build -o ./ize \ No newline at end of file + go build -o ./ize ./cmd \ No newline at end of file diff --git a/main.go b/cmd/main.go similarity index 87% rename from main.go rename to cmd/main.go index 73b4c728..d449d142 100644 --- a/main.go +++ b/cmd/main.go @@ -15,8 +15,12 @@ limitations under the License. */ package main -import "github.com/hazelops/ize/cmd" +import ( + "os" + + "github.com/hazelops/ize/commands" +) func main() { - cmd.Execute() + commands.Execute(os.Args[1:]) } diff --git a/commands/base.go b/commands/base.go new file mode 100644 index 00000000..d729c498 --- /dev/null +++ b/commands/base.go @@ -0,0 +1,156 @@ +package commands + +import ( + "fmt" + "os" + + "github.com/hazelops/ize/config" + "github.com/hazelops/ize/pkg/logger" + "github.com/spf13/cobra" + "github.com/spf13/viper" + "go.uber.org/zap/zapcore" +) + +var ( + ll string +) + +type baseCmd struct { + cmd *cobra.Command +} + +type baseBuilderCmd struct { + *baseCmd + *commandsBuilder +} + +type izeCmd struct { + *baseBuilderCmd + + //Need to get state app who build + c *commandeer +} + +type commandsBuilder struct { + izeBuilderCommon + + commands []cmder +} + +func newCommandBuilder() *commandsBuilder { + return &commandsBuilder{} +} + +func (b *commandsBuilder) newBuilderCmd(cmd *cobra.Command) *baseBuilderCmd { + bcmd := &baseBuilderCmd{commandsBuilder: b, baseCmd: &baseCmd{cmd: cmd}} + return bcmd +} + +func (b *commandsBuilder) addCommands(commands ...cmder) *commandsBuilder { + b.commands = append(b.commands, commands...) + return b +} + +func (b *commandsBuilder) addAll() *commandsBuilder { + b.addCommands(b.newTerraformCmd()) + + return b +} + +func (b *commandsBuilder) newBuilderBasicCdm(cmd *cobra.Command) *baseBuilderCmd { + bcmd := &baseBuilderCmd{baseCmd: &baseCmd{cmd: cmd}, commandsBuilder: b} + return bcmd +} + +func (b *commandsBuilder) newIzeCmd() *izeCmd { + cc := &izeCmd{} + + cc.baseBuilderCmd = b.newBuilderCmd(&cobra.Command{ + Use: "ize", + Short: "A brief description of your application", + Long: `A longer description that spans multiple lines and likely contains +examples and usage of using your application. For example: + +Cobra is a CLI library for Go that empowers applications. +This application is a tool to generate the needed files +to quickly create a Cobra application.`, + }) + + cc.cmd.PersistentFlags().StringVarP(&ll, "log-level", "l", "warn", "enable debug message") + cc.cmd.PersistentFlags().StringVarP(&cc.cfgFile, "config-file", "c", "", "set config file name") + + var logLevel zapcore.Level + + // TODO: Fix + switch ll { + case "info": + logLevel = zapcore.InfoLevel + + case "debug": + logLevel = zapcore.DebugLevel + default: + logLevel = zapcore.WarnLevel + } + + cc.log = logger.NewSugaredLogger(logLevel) + + return cc +} + +func addCommands(root *cobra.Command, commands ...cmder) { + for _, command := range commands { + cmd := command.getCommand() + if cmd == nil { + continue + } + root.AddCommand(cmd) + } +} + +func (c *baseCmd) getCommand() *cobra.Command { + return c.cmd +} + +func (b *commandsBuilder) build() *izeCmd { + i := b.newIzeCmd() + addCommands(i.getCommand(), b.commands...) + return i +} + +type izeBuilderCommon struct { + cfgFile string + cfg *config.Config + log logger.StandartLogger +} + +func (cc *izeBuilderCommon) Init() error { + cfg, err := cc.initConfig(cc.cfgFile) + if err != nil { + return err + } + + cc.cfg = cfg + + cwd, err := os.Getwd() + if err != nil { + fmt.Println("Error getting current directory") + } + + // Find home directory. + home, err := os.UserHomeDir() + cobra.CheckErr(err) + + viper.AutomaticEnv() // read in environment variables that match + + //TODO ensure values of the variables are checked for nil before passing down to docker. + + // Global + viper.SetDefault("ROOT_DIR", cwd) + viper.SetDefault("INFRA_DIR", fmt.Sprintf("%v/.infra", cwd)) + viper.SetDefault("ENV_DIR", fmt.Sprintf("%v/.infra/env/%v", cwd, cc.cfg.Env)) + viper.SetDefault("HOME", fmt.Sprintf("%v", home)) + viper.SetDefault("TF_LOG", fmt.Sprintf("")) + viper.SetDefault("TF_LOG_PATH", fmt.Sprintf("%v/tflog.txt", viper.Get("ENV_DIR"))) + + return nil +} diff --git a/commands/base_init.go b/commands/base_init.go new file mode 100644 index 00000000..f663482a --- /dev/null +++ b/commands/base_init.go @@ -0,0 +1,41 @@ +package commands + +import ( + "errors" + "fmt" + + "github.com/hazelops/ize/config" +) + +func (c *izeBuilderCommon) initConfig(filename string) (*config.Config, error) { + path, err := c.initConfigPath(filename) + if err != nil { + return nil, err + } + + if path == "" { + return nil, errors.New("A Waypoint configuration file (waypoint.hcl) is required but wasn't found.") + } + + return c.initConfigLoad(path) +} + +func (c *izeBuilderCommon) initConfigPath(filename string) (string, error) { + path, err := config.FindPath(filename) + if err != nil { + return "", fmt.Errorf("Error looking for a Ize configuration: %s", err) + } + + return path, nil +} + +func (c *izeBuilderCommon) initConfigLoad(path string) (*config.Config, error) { + cfg, err := config.Load(path) + if err != nil { + return nil, err + } + + //TODO: Validate + + return cfg, nil +} diff --git a/commands/comandeer.go b/commands/comandeer.go new file mode 100644 index 00000000..c4c8e20c --- /dev/null +++ b/commands/comandeer.go @@ -0,0 +1,7 @@ +package commands + +import "github.com/hazelops/ize/pkg/logger" + +type commandeer struct { + logger logger.StandartLogger +} diff --git a/commands/helpers.go b/commands/helpers.go new file mode 100644 index 00000000..a4b4bfa0 --- /dev/null +++ b/commands/helpers.go @@ -0,0 +1,7 @@ +package commands + +import "github.com/spf13/cobra" + +type cmder interface { + getCommand() *cobra.Command +} diff --git a/commands/ize.go b/commands/ize.go new file mode 100644 index 00000000..c0bccde2 --- /dev/null +++ b/commands/ize.go @@ -0,0 +1,24 @@ +package commands + +import "github.com/spf13/cobra" + +type Response struct { + Err error + + Cmd *cobra.Command +} + +func Execute(args []string) Response { + izeCmd := newCommandBuilder().addAll().build() + cmd := izeCmd.getCommand() + cmd.SetArgs(args) + + c, err := cmd.ExecuteC() + + var resp Response + + resp.Err = err + resp.Cmd = c + + return resp +} diff --git a/commands/terraform.go b/commands/terraform.go new file mode 100644 index 00000000..f0ab628b --- /dev/null +++ b/commands/terraform.go @@ -0,0 +1,170 @@ +package commands + +import ( + "context" + "fmt" + "os" + "strings" + + "github.com/docker/docker/api/types" + "github.com/docker/docker/api/types/container" + "github.com/docker/docker/api/types/mount" + "github.com/docker/docker/client" + "github.com/docker/docker/pkg/jsonmessage" + "github.com/hazelops/ize/pkg/gomplate" + "github.com/moby/term" + "github.com/pterm/pterm" + "github.com/spf13/cobra" + "github.com/spf13/viper" +) + +type terraformCmd struct { + *baseBuilderCmd +} + +func (b *commandsBuilder) newTerraformCmd() *terraformCmd { + cc := &terraformCmd{} + + cmd := &cobra.Command{ + Use: "terraform", + Short: "Terraform management.", + Long: `This command contains subcommands for work with terraform.`, + RunE: nil, + } + + cmd.AddCommand(&cobra.Command{ + Use: "init", + Short: "Download terraform docker image", + Long: `This command download terraform docker image of the specified version.`, + RunE: func(cmd *cobra.Command, args []string) error { + cc.log.Debug("Init Run Terrafrom Init") + err := cc.Init() + + if err != nil { + return err + } + + err = gomplate.RunGomplate(gomplate.GomplateOptions{ + OutputFileDir: viper.GetString("ENV_DIR"), + InputFileDir: fmt.Sprintf("%v/terraform/template/", viper.GetString("INFRA_DIR")), + InputFileName: "backend.tf.gotmpl", + OutputFileName: "backend.tf", + Env: []string{ + fmt.Sprintf("ENV=%v", viper.Get("ENV")), + fmt.Sprintf("AWS_PROFILE=%v", viper.Get("AWS_PROFILE")), + fmt.Sprintf("TF_LOG=%v", viper.Get("TF_LOG")), + fmt.Sprintf("TF_LOG_PATH=%v", viper.Get("TF_LOG_PATH")), + }, + }, cc.log) + if err != nil { + return err + } + + err = gomplate.RunGomplate(gomplate.GomplateOptions{ + OutputFileDir: viper.GetString("ENV_DIR"), + InputFileDir: fmt.Sprintf("%v/terraform/template/", viper.GetString("INFRA_DIR")), + InputFileName: "terraform.tfvars.gotmpl", + OutputFileName: "terraform.tfvars", + Env: []string{ + fmt.Sprintf("ENV=%v", viper.Get("ENV")), + fmt.Sprintf("AWS_PROFILE=%v", viper.Get("AWS_PROFILE")), + fmt.Sprintf("TF_LOG=%v", viper.Get("TF_LOG")), + fmt.Sprintf("TF_LOG_PATH=%v", viper.Get("TF_LOG_PATH")), + }, + }, cc.log) + if err != nil { + return err + } + + runTerraform(cc) + return nil + }, + }) + + cc.baseBuilderCmd = b.newBuilderBasicCdm(cmd) + + return cc +} + +func runTerraform(cc *terraformCmd) error { + pterm.Success.Println("Init docker client") + cc.log.Debug("Init docker client") + + cli, err := client.NewClientWithOpts(client.FromEnv) + if err != nil { + return err + } + + imageName := "hashicorp/terraform" + imageTag := cc.cfg.TerraformVersion + termFd, _ := term.GetFdInfo(os.Stderr) + + pterm.Success.Printfln("Started pull terraform image %v:%v", imageName, imageTag) + + out, err := cli.ImagePull(context.Background(), fmt.Sprintf("%v:%v", imageName, imageTag), types.ImagePullOptions{}) + if err != nil { + return err + } + + err = jsonmessage.DisplayJSONMessagesStream(out, &cc.log, termFd, true, nil) + + if err != nil { + return err + } + + pterm.Success.Printfln("Finished pulling terraform image %v:%v", imageName, imageTag) + + pterm.Success.Printfln("Start creating terraform container from image %v:%v", imageName, imageTag) + + //TODO: Add Auto Pull Docker image + //TODO: Check if such container exists to use fixed name + cont, err := cli.ContainerCreate( + context.Background(), + &container.Config{ + Image: fmt.Sprintf("%v:%v", imageName, imageTag), + Tty: true, + Cmd: strings.Split("init", " "), + AttachStdin: true, + AttachStdout: true, + AttachStderr: true, + OpenStdin: true, + WorkingDir: fmt.Sprintf("%v", viper.Get("ENV_DIR")), + Env: []string{ + fmt.Sprintf("ENV=%v", viper.Get("ENV")), + fmt.Sprintf("AWS_PROFILE=%v", viper.Get("AWS_PROFILE")), + fmt.Sprintf("TF_LOG=%v", viper.Get("TF_LOG")), + fmt.Sprintf("TF_LOG_PATH=%v", viper.Get("TF_LOG_PATH")), + }, + }, + + &container.HostConfig{ + AutoRemove: false, + Mounts: []mount.Mount{ + { + Type: mount.TypeBind, + Source: fmt.Sprintf("%v", viper.Get("ENV_DIR")), + Target: fmt.Sprintf("%v", viper.Get("ENV_DIR")), + }, + { + Type: mount.TypeBind, + Source: fmt.Sprintf("%v", viper.Get("INFRA_DIR")), + Target: fmt.Sprintf("%v", viper.Get("INFRA_DIR")), + }, + { + Type: mount.TypeBind, + Source: fmt.Sprintf("%v", viper.Get("HOME")), + Target: fmt.Sprintf("%v", viper.Get("HOME")), + }, + }, + }, nil, nil, "terraform") + + pterm.Success.Printfln("Finished creating terraform container from image %v:%v", imageName, imageTag) + + if err := cli.ContainerStart(context.Background(), cont.ID, types.ContainerStartOptions{}); err != nil { + return err + } + + pterm.Success.Printfln("Terraform container started!", cont.ID) + + return nil +} diff --git a/config/config.go b/config/config.go new file mode 100644 index 00000000..fd8db5b6 --- /dev/null +++ b/config/config.go @@ -0,0 +1,64 @@ +package config + +import ( + "os" + "path/filepath" + + "github.com/hashicorp/hcl/v2" + "github.com/hashicorp/hcl/v2/hclsimple" +) + +const Filename = "ize.hcl" + +type Config struct { + AwsConfig string `hcl:"aws_config,optional"` + TerraformVersion string `hcl:"terraform_version"` + Env string `hcl:"env"` + AwsRegion string `hcl:"aws_region"` + AwsProfile string `hcl:"aws_profile"` + + Service []*struct { + Type string `hcl:"type,label"` + Name string `hcl:"name,label"` + } `hcl:"service,block"` +} + +func FindPath(filename string) (string, error) { + var err error + wd, err := os.Getwd() + if err != nil { + return "", err + } + + if filename == "" { + filename = Filename + } + + path := filepath.Join(wd, filename) + if _, err := os.Stat(path); err == nil { + return path, nil + } else { + return "", err + } +} + +func Load(path string) (*Config, error) { + var ctx *hcl.EvalContext + + // We require an absolute path for the path so we can set the path vars + if !filepath.IsAbs(path) { + var err error + path, err = filepath.Abs(path) + if err != nil { + return nil, err + } + } + + // Decode + var cfg Config + if err := hclsimple.DecodeFile(path, ctx, &cfg); err != nil { + return nil, err + } + + return &cfg, nil +} diff --git a/docker/terraform.go b/docker/terraform.go deleted file mode 100644 index 9f17926e..00000000 --- a/docker/terraform.go +++ /dev/null @@ -1,98 +0,0 @@ -package docker - -import ( - "context" - "fmt" - "io" - "os" - "strings" - - "github.com/docker/docker/api/types" - "github.com/docker/docker/api/types/container" - "github.com/docker/docker/api/types/mount" - "github.com/docker/docker/client" - "github.com/spf13/viper" -) - -func TerraformInit() { - command := "init" - runTerraform(command) - -} - -func TerraformPlan() { - command := "plan" - runTerraform(command) - -} - -func runTerraform(command string) { - cli, err := client.NewClientWithOpts(client.FromEnv) - if err != nil { - panic(err) - } - - imageName := "hashicorp/terraform" - imageTag := viper.Get("TERRAFORM_VERSION") - - out, err := cli.ImagePull(context.Background(), fmt.Sprintf("%v:%v", imageName, imageTag), types.ImagePullOptions{}) - if err != nil { - panic(err) - } - - io.Copy(os.Stdout, out) - - //TODO: Add Auto Pull Docker image - //TODO: Check if such container exists to use fixed name - cont, err := cli.ContainerCreate( - context.Background(), - &container.Config{ - Image: fmt.Sprintf("%v:%v", imageName, imageTag), - Tty: true, - Cmd: strings.Split(command, " "), - AttachStdin: true, - AttachStdout: true, - AttachStderr: true, - OpenStdin: true, - WorkingDir: fmt.Sprintf("%v", viper.Get("ENV_DIR")), - Env: []string{ - fmt.Sprintf("ENV=%v", viper.Get("ENV")), - fmt.Sprintf("AWS_PROFILE=%v", viper.Get("AWS_PROFILE")), - fmt.Sprintf("TF_LOG=%v", viper.Get("TF_LOG")), - fmt.Sprintf("TF_LOG_PATH=%v", viper.Get("TF_LOG_PATH")), - }, - }, - - &container.HostConfig{ - AutoRemove: false, - Mounts: []mount.Mount{ - { - Type: mount.TypeBind, - Source: fmt.Sprintf("%v", viper.Get("ENV_DIR")), - Target: fmt.Sprintf("%v", viper.Get("ENV_DIR")), - }, - { - Type: mount.TypeBind, - Source: fmt.Sprintf("%v", viper.Get("INFRA_DIR")), - Target: fmt.Sprintf("%v", viper.Get("INFRA_DIR")), - }, - { - Type: mount.TypeBind, - Source: fmt.Sprintf("%v", viper.Get("HOME")), - Target: fmt.Sprintf("%v", viper.Get("HOME")), - }, - }, - }, nil, nil, "") - - if err := cli.ContainerStart(context.Background(), cont.ID, types.ContainerStartOptions{}); err != nil { - panic(err) - } - - out, err = cli.ContainerLogs(context.Background(), cont.ID, types.ContainerLogsOptions{ShowStdout: true, ShowStderr: true, Follow: true, Timestamps: false}) - if err != nil { - panic(err) - } - - io.Copy(os.Stdout, out) - -} diff --git a/examples/simple-monorepo/.infra/.gitignore b/examples/simple-monorepo/.infra/.gitignore index 1345be72..508f381b 100644 --- a/examples/simple-monorepo/.infra/.gitignore +++ b/examples/simple-monorepo/.infra/.gitignore @@ -13,6 +13,8 @@ output.json tfplan *.tfvars +.infra + env/* !env/testnut !env/prod diff --git a/go.mod b/go.mod index 26877a72..fcbec616 100644 --- a/go.mod +++ b/go.mod @@ -6,10 +6,11 @@ require ( github.com/containerd/containerd v1.5.4 // indirect github.com/docker/docker v20.10.7+incompatible github.com/docker/go-connections v0.4.0 // indirect - github.com/gorilla/mux v1.8.0 // indirect - github.com/moby/term v0.0.0-20210619224110-3f7ff695adc6 // indirect + github.com/hashicorp/hcl/v2 v2.10.1 + github.com/moby/term v0.0.0-20210619224110-3f7ff695adc6 github.com/morikuni/aec v1.0.0 // indirect - github.com/sirupsen/logrus v1.8.1 // indirect + github.com/pterm/pterm v0.12.31 // indirect github.com/spf13/cobra v1.2.1 github.com/spf13/viper v1.8.1 + go.uber.org/zap v1.19.0 ) diff --git a/go.sum b/go.sum index 88c73a9e..ec1b0719 100644 --- a/go.sum +++ b/go.sum @@ -54,6 +54,9 @@ github.com/Azure/go-autorest/logger v0.2.0/go.mod h1:T9E3cAhj2VqvPOtCYAvby9aBXkZ github.com/Azure/go-autorest/tracing v0.6.0/go.mod h1:+vhtPC754Xsa23ID7GlGsrdKBpUA79WCAKPPZVC2DeU= github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU= github.com/BurntSushi/xgb v0.0.0-20160522181843-27f122750802/go.mod h1:IVnqGOEym/WlBOVXweHU+Q+/VP0lqqI8lqeDx9IjBqo= +github.com/MarvinJWendt/testza v0.1.0/go.mod h1:7AxNvlfeHP7Z/hDQ5JtE3OKYT3XFUeLCDE2DQninSqs= +github.com/MarvinJWendt/testza v0.2.1/go.mod h1:God7bhG8n6uQxwdScay+gjm9/LnO4D3kkcZX4hv9Rp8= +github.com/MarvinJWendt/testza v0.2.8/go.mod h1:nwIcjmr0Zz+Rcwfh3/4UhBp7ePKVhuBExvZqnKYWlII= github.com/Microsoft/go-winio v0.4.11/go.mod h1:VhR8bwka0BXejwEJY73c50VrPtXAaKcyvVC4A4RozmA= github.com/Microsoft/go-winio v0.4.14/go.mod h1:qXqCSQ3Xa7+6tgxaGTIe4Kpcdsi+P8jBhyzoq1bpyYA= github.com/Microsoft/go-winio v0.4.15-0.20190919025122-fc70bd9a86b5/go.mod h1:tTuCMEN+UleMWgg9dVx4Hu52b1bJo+59jBh3ajtinzw= @@ -78,18 +81,29 @@ github.com/OneOfOne/xxhash v1.2.2/go.mod h1:HSdplMjZKSmBqAxg5vPj2TmRDmfkzw+cTzAE github.com/PuerkitoBio/purell v1.1.1/go.mod h1:c11w/QuzBsJSee3cPx9rAFu61PvFxuPbtSwDGJws/X0= github.com/PuerkitoBio/urlesc v0.0.0-20170810143723-de5bf2ad4578/go.mod h1:uGdkoq3SwY9Y+13GIhn11/XLaGBb4BfwItxLd5jeuXE= github.com/Shopify/logrus-bugsnag v0.0.0-20171204204709-577dee27f20d/go.mod h1:HI8ITrYtUY+O+ZhtlqUnD8+KwNPOyugEhfP9fdUIaEQ= +github.com/agext/levenshtein v1.2.1 h1:QmvMAjj2aEICytGiWzmxoE0x2KZvE0fvmqMOfy2tjT8= +github.com/agext/levenshtein v1.2.1/go.mod h1:JEDfjyjHDjOF/1e4FlBE/PkbqA9OfWu2ki2W0IB5558= github.com/alecthomas/template v0.0.0-20160405071501-a0175ee3bccc/go.mod h1:LOuyumcjzFXgccqObfd/Ljyb9UuFJ6TxHnclSeseNhc= github.com/alecthomas/template v0.0.0-20190718012654-fb15b899a751/go.mod h1:LOuyumcjzFXgccqObfd/Ljyb9UuFJ6TxHnclSeseNhc= github.com/alecthomas/units v0.0.0-20151022065526-2efee857e7cf/go.mod h1:ybxpYRFXyAe+OPACYpWeL0wqObRcbAqCMya13uyzqw0= github.com/alecthomas/units v0.0.0-20190717042225-c3de453c63f4/go.mod h1:ybxpYRFXyAe+OPACYpWeL0wqObRcbAqCMya13uyzqw0= github.com/alexflint/go-filemutex v0.0.0-20171022225611-72bdc8eae2ae/go.mod h1:CgnQgUtFrFz9mxFNtED3jI5tLDjKlOM+oUF/sTk6ps0= github.com/antihax/optional v1.0.0/go.mod h1:uupD/76wgC+ih3iEmQUL+0Ugr19nfwCT1kdvxnR2qWY= +github.com/apparentlymart/go-dump v0.0.0-20180507223929-23540a00eaa3/go.mod h1:oL81AME2rN47vu18xqj1S1jPIPuN7afo62yKTNn3XMM= +github.com/apparentlymart/go-textseg v1.0.0 h1:rRmlIsPEEhUTIKQb7T++Nz/A5Q6C9IuX2wFoYVvnCs0= +github.com/apparentlymart/go-textseg v1.0.0/go.mod h1:z96Txxhf3xSFMPmb5X/1W05FF/Nj9VFpLOpjS5yuumk= +github.com/apparentlymart/go-textseg/v13 v13.0.0 h1:Y+KvPE1NYz0xl601PVImeQfFyEy6iT90AvPUL1NNfNw= +github.com/apparentlymart/go-textseg/v13 v13.0.0/go.mod h1:ZK2fH7c4NqDTLtiYLvIkEghdlcqw7yxLeM89kiTRPUo= github.com/armon/circbuf v0.0.0-20150827004946-bbbad097214e/go.mod h1:3U/XgcO3hCbHZ8TKRvWD2dDTCfh9M9ya+I9JpbB7O8o= github.com/armon/consul-api v0.0.0-20180202201655-eb2c6b5be1b6/go.mod h1:grANhF5doyWs3UAsr3K4I6qtAmlQcZDesFNEHPZAzj8= github.com/armon/go-metrics v0.0.0-20180917152333-f0300d1749da/go.mod h1:Q73ZrmVTwzkszR9V5SSuryQ31EELlFMUz1kKyl939pY= github.com/armon/go-radix v0.0.0-20180808171621-7fddfc383310/go.mod h1:ufUuZ+zHj4x4TnLV4JWEpy2hxWSpsRywHrMgIH9cCH8= github.com/asaskevich/govalidator v0.0.0-20190424111038-f61b66f89f4a/go.mod h1:lB+ZfQJz7igIIfQNfa7Ml4HSf2uFQQRzpGGRXenZAgY= +github.com/atomicgo/cursor v0.0.1 h1:xdogsqa6YYlLfM+GyClC/Lchf7aiMerFiZQn7soTOoU= +github.com/atomicgo/cursor v0.0.1/go.mod h1:cBON2QmmrysudxNBFthvMtN32r3jxVRIvzkUiF/RuIk= github.com/aws/aws-sdk-go v1.15.11/go.mod h1:mFuSZ37Z9YOHbQEwBWztmVzqXrEkub65tZoCYDt7FT0= +github.com/benbjohnson/clock v1.1.0 h1:Q92kusRqC1XV2MjkWETPvjJVqKetz1OzxZB7mHJLju8= +github.com/benbjohnson/clock v1.1.0/go.mod h1:J11/hYXuz8f4ySSvYwY0FKfm+ezbsZBKZxNJlLklBHA= github.com/beorn7/perks v0.0.0-20160804104726-4c0e84591b9a/go.mod h1:Dwedo/Wpr24TaqPxmxbtue+5NUziq4I4S80YR8gNf3Q= github.com/beorn7/perks v0.0.0-20180321164747-3a771d992973/go.mod h1:Dwedo/Wpr24TaqPxmxbtue+5NUziq4I4S80YR8gNf3Q= github.com/beorn7/perks v1.0.0/go.mod h1:KWe93zE9D1o94FZ5RNwFwVgaQK1VOXiVxmqh+CedLV8= @@ -222,6 +236,7 @@ github.com/coreos/pkg v0.0.0-20180928190104-399ea9e2e55f/go.mod h1:E3G3o1h8I7cfc github.com/cpuguy83/go-md2man/v2 v2.0.0-20190314233015-f79a8a8ca69d/go.mod h1:maD7wRr/U5Z6m/iR4s+kqSMx2CaBsrgA7czyZG/E6dU= github.com/cpuguy83/go-md2man/v2 v2.0.0/go.mod h1:maD7wRr/U5Z6m/iR4s+kqSMx2CaBsrgA7czyZG/E6dU= github.com/creack/pty v1.1.7/go.mod h1:lj5s0c3V2DBrqTV7llrYr5NG6My20zk30Fl46Y7DoTY= +github.com/creack/pty v1.1.11 h1:07n33Z8lZxZ2qwegKbObQohDhXDQxiMMz1NOUGYlesw= github.com/creack/pty v1.1.11/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E= github.com/cyphar/filepath-securejoin v0.2.2/go.mod h1:FpkQEhXnPnOthhzymB7CGsFk2G9VLXONKD9G7QGMM+4= github.com/d2g/dhcp4 v0.0.0-20170904100407-a1d1b6c41b1c/go.mod h1:Ct2BUK8SB0YC1SMSibvLzxjeJLnrYEVLULFNiHY9YfQ= @@ -294,6 +309,8 @@ github.com/go-openapi/spec v0.19.3/go.mod h1:FpwSN1ksY1eteniUU7X0N/BgJ7a4WvBFVA8 github.com/go-openapi/swag v0.19.2/go.mod h1:POnQmlKehdgb5mhVOsnJFsivZCEZ/vjK9gh66Z9tfKk= github.com/go-openapi/swag v0.19.5/go.mod h1:POnQmlKehdgb5mhVOsnJFsivZCEZ/vjK9gh66Z9tfKk= github.com/go-stack/stack v1.8.0/go.mod h1:v0f6uXyyMGvRgIKkXu+yp6POWl0qKG85gN/melR3HDY= +github.com/go-test/deep v1.0.3 h1:ZrJSEWsXzPOxaZnFteGEfooLba+ju3FYIbOrS+rQd68= +github.com/go-test/deep v1.0.3/go.mod h1:wGDj63lr65AM2AQyKZd/NYHGb0R+1RLqB8NKt3aSFNA= github.com/godbus/dbus v0.0.0-20151105175453-c7fdd8b5cd55/go.mod h1:/YcGZj5zSblfDWMMoOzV4fas9FZnQYTkDnsGvmh2Grw= github.com/godbus/dbus v0.0.0-20180201030542-885f9cc04c9c/go.mod h1:/YcGZj5zSblfDWMMoOzV4fas9FZnQYTkDnsGvmh2Grw= github.com/godbus/dbus v0.0.0-20190422162347-ade71ed3457e/go.mod h1:bBOAhwG1umN6/6ZUMtDFBMQR8jRg9O75tm9K00oMsK4= @@ -322,6 +339,7 @@ github.com/golang/mock v1.4.1/go.mod h1:UOMv5ysSaYNkG+OFQykRIcU/QvvxJf3p21QfJ2Bt github.com/golang/mock v1.4.3/go.mod h1:UOMv5ysSaYNkG+OFQykRIcU/QvvxJf3p21QfJ2Bt3cw= github.com/golang/mock v1.4.4/go.mod h1:l3mdAwkq5BuhzHwde/uurv3sEJeZMXNpwsxVWU71h+4= github.com/golang/mock v1.5.0/go.mod h1:CWnOUgYIOo4TcNZ0wHX3YZCqsaM1I1Jvs6v3mP3KVu8= +github.com/golang/protobuf v1.1.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= github.com/golang/protobuf v1.3.1/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= github.com/golang/protobuf v1.3.2/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= @@ -378,12 +396,13 @@ github.com/google/uuid v1.2.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+ github.com/googleapis/gax-go/v2 v2.0.4/go.mod h1:0Wqv26UfaUD9n4G6kQubkQ+KchISgw+vpHVxEJEs9eg= github.com/googleapis/gax-go/v2 v2.0.5/go.mod h1:DWXyrwAJ9X0FpwwEdw+IPEYBICEFu5mhpdKc/us6bOk= github.com/googleapis/gnostic v0.4.1/go.mod h1:LRhVm6pbyptWbWbuZ38d1eyptfvIytN3ir6b65WBswg= +github.com/gookit/color v1.4.2 h1:tXy44JFSFkKnELV6WaMo/lLfu/meqITX3iAV52do7lk= +github.com/gookit/color v1.4.2/go.mod h1:fqRyamkC1W8uxl+lxCQxOT09l/vYfZ+QeiX3rKQHCoQ= github.com/gopherjs/gopherjs v0.0.0-20181017120253-0766667cb4d1 h1:EGx4pi6eqNxGaHF6qqu48+N2wcFQ5qg5FXgOdqsJ5d8= github.com/gopherjs/gopherjs v0.0.0-20181017120253-0766667cb4d1/go.mod h1:wJfORRmW1u3UXTncJ5qlYoELFm8eSnnEO6hX4iZ3EWY= github.com/gorilla/handlers v0.0.0-20150720190736-60c7bfde3e33/go.mod h1:Qkdc/uu4tH4g6mTK6auzZ766c4CA0Ng8+o/OAirnOIQ= +github.com/gorilla/mux v1.7.2 h1:zoNxOV7WjqXptQOVngLmcSQgXmgk4NMz1HibBchjl/I= github.com/gorilla/mux v1.7.2/go.mod h1:1lud6UwP+6orDFRuTfBEV8e9/aOM/c4fVVCaMa2zaAs= -github.com/gorilla/mux v1.8.0 h1:i40aqfkR1h2SlN9hojwV5ZA91wcXFOvkdNIeFDP5koI= -github.com/gorilla/mux v1.8.0/go.mod h1:DVbg23sWSpFRCP0SfiEN6jmj59UnW/n46BH5rLB71So= github.com/gorilla/websocket v0.0.0-20170926233335-4201258b820c/go.mod h1:E7qHFY5m1UJ88s3WnNqhKjPHQ0heANvMoAMk2YaljkQ= github.com/gorilla/websocket v1.4.0/go.mod h1:E7qHFY5m1UJ88s3WnNqhKjPHQ0heANvMoAMk2YaljkQ= github.com/gorilla/websocket v1.4.2/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE= @@ -413,6 +432,8 @@ github.com/hashicorp/golang-lru v0.5.0/go.mod h1:/m3WP610KZHVQ1SGc6re/UDhFvYD7pJ github.com/hashicorp/golang-lru v0.5.1/go.mod h1:/m3WP610KZHVQ1SGc6re/UDhFvYD7pJ4Ao+sR/qLZy8= github.com/hashicorp/hcl v1.0.0 h1:0Anlzjpi4vEasTeNFn2mLJgTSwt0+6sfsiTG8qcWGx4= github.com/hashicorp/hcl v1.0.0/go.mod h1:E5yfLk+7swimpb2L/Alb/PJmXilQ/rhwaUYs4T20WEQ= +github.com/hashicorp/hcl/v2 v2.10.1 h1:h4Xx4fsrRE26ohAk/1iGF/JBqRQbyUqu5Lvj60U54ys= +github.com/hashicorp/hcl/v2 v2.10.1/go.mod h1:FwWsfWEjyV/CMj8s/gqAuiviY72rJ1/oayI9WftqcKg= github.com/hashicorp/logutils v1.0.0/go.mod h1:QIAnNjmIWmVIIkWDTG1z5v++HQmx9WQRO+LraFDTW64= github.com/hashicorp/mdns v1.0.0/go.mod h1:tL+uN++7HEJ6SQLQ2/p+z2pH24WQKWjBPkE0mNTz8vQ= github.com/hashicorp/memberlist v0.1.3/go.mod h1:ajVTdAv/9Im8oMAAj5G31PhhMCZJV2pPBoIllUwCN7I= @@ -458,6 +479,8 @@ github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ= github.com/kr/pty v1.1.5/go.mod h1:9r2w37qlBe7rQ6e1fg1S/9xpWHSnaqNdHD3WcMdbPDA= github.com/kr/text v0.1.0 h1:45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE= github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI= +github.com/kylelemons/godebug v0.0.0-20170820004349-d65d576e9348 h1:MtvEpTB6LX3vkb4ax0b5D2DHbNAUsen0Gx5wZoq3lV4= +github.com/kylelemons/godebug v0.0.0-20170820004349-d65d576e9348/go.mod h1:B69LEHPfb2qLo0BaaOLcbitczOKLWTsrBG9LczfCD4k= github.com/magiconair/properties v1.8.0/go.mod h1:PppfXfuXeibc/6YijjN8zIbojt8czPbwD3XqdrwzmxQ= github.com/magiconair/properties v1.8.5 h1:b6kJs+EmPFMYGkow9GiUyCyOvIwYetYJ3fSaWak/Gls= github.com/magiconair/properties v1.8.5/go.mod h1:y3VJvCyxH9uVvJTWEGAELF3aiYNyPKd5NZ3oSwXrF60= @@ -469,6 +492,8 @@ github.com/mattn/go-colorable v0.0.9/go.mod h1:9vuHe8Xs5qXnSaW/c/ABM9alt+Vo+STaO github.com/mattn/go-isatty v0.0.3/go.mod h1:M+lRXTBqGeGNdLjl/ufCoiOlB5xdOkqRJdNxMWT7Zi4= github.com/mattn/go-isatty v0.0.4/go.mod h1:M+lRXTBqGeGNdLjl/ufCoiOlB5xdOkqRJdNxMWT7Zi4= github.com/mattn/go-runewidth v0.0.2/go.mod h1:LwmH8dsx7+W8Uxz3IHJYH5QSwggIsqBzpuz5H//U1FU= +github.com/mattn/go-runewidth v0.0.13 h1:lTGmDsbAYt5DmK6OnoV7EuIF1wEIFAcxld6ypU4OSgU= +github.com/mattn/go-runewidth v0.0.13/go.mod h1:Jdepj2loyihRzMpdS35Xk/zdY8IAYHsh153qUoGf23w= github.com/mattn/go-shellwords v1.0.3/go.mod h1:3xCvwCdWdlDJUrvuMn7Wuy9eWs4pE8vqg+NOMyg4B2o= github.com/matttproud/golang_protobuf_extensions v1.0.1/go.mod h1:D8He9yQNgCq6Z5Ld7szi9bcBfOoFv/3dc6xSMkL2PC0= github.com/matttproud/golang_protobuf_extensions v1.0.2-0.20181231171920-c182affec369/go.mod h1:BSXmuO+STAnVfrANrmjBb36TMTDstsz7MSK+HVaYKv4= @@ -479,6 +504,8 @@ github.com/mitchellh/cli v1.0.0/go.mod h1:hNIlj7HEI86fIcpObd7a0FcrxTWetlwJDGcceT github.com/mitchellh/go-homedir v1.0.0/go.mod h1:SfyaCUpYCn1Vlf4IUYiD9fPX4A5wJrkLzIz1N1q0pr0= github.com/mitchellh/go-homedir v1.1.0/go.mod h1:SfyaCUpYCn1Vlf4IUYiD9fPX4A5wJrkLzIz1N1q0pr0= github.com/mitchellh/go-testing-interface v1.0.0/go.mod h1:kRemZodwjscx+RGhAo8eIhFbs2+BFgRtFPeD/KE+zxI= +github.com/mitchellh/go-wordwrap v0.0.0-20150314170334-ad45545899c7 h1:DpOJ2HYzCv8LZP15IdmG+YdwD2luVPHITV96TkirNBM= +github.com/mitchellh/go-wordwrap v0.0.0-20150314170334-ad45545899c7/go.mod h1:ZXFpozHsX6DPmq2I0TCekCxypsnAUbP2oI0UX1GXzOo= github.com/mitchellh/gox v0.4.0/go.mod h1:Sd9lOJ0+aimLBi73mGofS1ycjY8lL3uZM3JPS42BGNg= github.com/mitchellh/iochan v1.0.0/go.mod h1:JwYml1nuB7xOzsp52dPpHFffvOCDupsG0QubkSMEySY= github.com/mitchellh/mapstructure v0.0.0-20160808181253-ca63d7c062ee/go.mod h1:FVVH3fgwuzCH5S8UJGiWEs2h04kUh9fWfEaFds41c1Y= @@ -587,6 +614,13 @@ github.com/prometheus/procfs v0.1.3/go.mod h1:lV6e/gmhEcM9IjHGsFOCxxuZ+z1YqCvr4O github.com/prometheus/procfs v0.2.0/go.mod h1:lV6e/gmhEcM9IjHGsFOCxxuZ+z1YqCvr4OA4YeYWdaU= github.com/prometheus/procfs v0.6.0/go.mod h1:cz+aTbrPOrUb4q7XlbU9ygM+/jj0fzG6c1xBZuNvfVA= github.com/prometheus/tsdb v0.7.1/go.mod h1:qhTCs0VvXwvX/y3TZrWD7rabWM+ijKTux40TwIPHuXU= +github.com/pterm/pterm v0.12.27/go.mod h1:PhQ89w4i95rhgE+xedAoqous6K9X+r6aSOI2eFF7DZI= +github.com/pterm/pterm v0.12.29/go.mod h1:WI3qxgvoQFFGKGjGnJR849gU0TsEOvKn5Q8LlY1U7lg= +github.com/pterm/pterm v0.12.30/go.mod h1:MOqLIyMOgmTDz9yorcYbcw+HsgoZo3BQfg2wtl3HEFE= +github.com/pterm/pterm v0.12.31 h1:+UFxhtv9Kuz0nIBH7Aqc2AF0QeOlNChb38L2sYPtXiU= +github.com/pterm/pterm v0.12.31/go.mod h1:32ZAWZVXD7ZfG0s8qqHXePte42kdz8ECtRyEejaWgXU= +github.com/rivo/uniseg v0.2.0 h1:S1pD9weZBuJdFmowNwbpi7BJ8TNftyUImj/0WQi72jY= +github.com/rivo/uniseg v0.2.0/go.mod h1:J6wj4VEh+S6ZtnVlnTBMWIodfgj8LQOQFoIToxlJtxc= github.com/rogpeppe/fastuuid v0.0.0-20150106093220-6724a57986af/go.mod h1:XWv6SoW27p1b0cqNHllgS5HIMJraePCO15w5zCzIWYg= github.com/rogpeppe/fastuuid v1.2.0/go.mod h1:jVj6XXZzXRy/MSR5jhDC/2q6DgLz+nrA6LYCDYWNEvQ= github.com/rogpeppe/go-internal v1.3.0/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFRclV5y23lUDJ4= @@ -596,6 +630,8 @@ github.com/safchain/ethtool v0.0.0-20190326074333-42ed695e3de8/go.mod h1:Z0q5wiB github.com/satori/go.uuid v1.2.0/go.mod h1:dA0hQrYB0VpLJoorglMZABFdXlWrHn1NEOzdhQKdks0= github.com/sean-/seed v0.0.0-20170313163322-e2103e2c3529/go.mod h1:DxrIzT+xaE7yg65j358z/aeFdxmN0P9QXhEzd20vsDc= github.com/seccomp/libseccomp-golang v0.9.1/go.mod h1:GbW5+tmTXfcxTToHLXlScSlAvWlF4P2Ca7zGrPiEpWo= +github.com/sergi/go-diff v1.0.0 h1:Kpca3qRNrduNnOQeazBd0ysaKrUJiIuISHxogkT9RPQ= +github.com/sergi/go-diff v1.0.0/go.mod h1:0CfEIISq7TuYL3j771MWULgwwjU+GofnZX9QAmXWZgo= github.com/shurcooL/sanitized_anchor_name v1.0.0/go.mod h1:1NzhyTcUVG4SuEtjjoZeVRXNmyL/1OwPU0+IJeTBvfc= github.com/sirupsen/logrus v1.0.4-0.20170822132746-89742aefa4b2/go.mod h1:pMByvHTf9Beacp5x1UXfOR9xyW/9antXMhjMPG0dEzc= github.com/sirupsen/logrus v1.0.6/go.mod h1:pMByvHTf9Beacp5x1UXfOR9xyW/9antXMhjMPG0dEzc= @@ -603,9 +639,8 @@ github.com/sirupsen/logrus v1.2.0/go.mod h1:LxeOpSwHxABJmUn/MG1IvRgCAasNZTLOkJPx github.com/sirupsen/logrus v1.4.1/go.mod h1:ni0Sbl8bgC9z8RoU9G6nDWqqs/fq4eDPysMBDgk/93Q= github.com/sirupsen/logrus v1.4.2/go.mod h1:tLMulIdttU9McNUspp0xgXVQah82FyeX6MwdIuYE2rE= github.com/sirupsen/logrus v1.6.0/go.mod h1:7uNnSEd1DgxDLC74fIahvMZmmYsHGZGEOFrfsX/uA88= +github.com/sirupsen/logrus v1.7.0 h1:ShrD1U9pZB12TX0cVy0DtePoCH97K8EtX+mg7ZARUtM= github.com/sirupsen/logrus v1.7.0/go.mod h1:yWOB1SBYBC5VeMP7gHvWumXLIWorT60ONWic61uBYv0= -github.com/sirupsen/logrus v1.8.1 h1:dJKuHgqk1NNQlqoA6BTlM1Wf9DOH3NBjQyu0h9+AZZE= -github.com/sirupsen/logrus v1.8.1/go.mod h1:yWOB1SBYBC5VeMP7gHvWumXLIWorT60ONWic61uBYv0= github.com/smartystreets/assertions v0.0.0-20180927180507-b2de0cb4f26d h1:zE9ykElWQ6/NYmHa3jpm/yHnI4xSofP+UP6SpjHcSeM= github.com/smartystreets/assertions v0.0.0-20180927180507-b2de0cb4f26d/go.mod h1:OnSkiWE9lh6wB0YB77sQom3nweQdgAjqCqsofrRNTgc= github.com/smartystreets/goconvey v0.0.0-20190330032615-68dc04aab96a/go.mod h1:syvi0/a8iFYH4r/RixwvyeAJjdLS9QV7WQ/tjFTllLA= @@ -631,6 +666,7 @@ github.com/spf13/jwalterweatherman v1.1.0/go.mod h1:aNWZUN0dPAAO/Ljvb5BEdw96iTZ0 github.com/spf13/pflag v0.0.0-20170130214245-9ff6c6923cff/go.mod h1:DYY7MBk1bdzusC3SYhjObp+wFpr4gzcvqqNjLnInEg4= github.com/spf13/pflag v1.0.1-0.20171106142849-4c012f6dcd95/go.mod h1:DYY7MBk1bdzusC3SYhjObp+wFpr4gzcvqqNjLnInEg4= github.com/spf13/pflag v1.0.1/go.mod h1:DYY7MBk1bdzusC3SYhjObp+wFpr4gzcvqqNjLnInEg4= +github.com/spf13/pflag v1.0.2/go.mod h1:DYY7MBk1bdzusC3SYhjObp+wFpr4gzcvqqNjLnInEg4= github.com/spf13/pflag v1.0.3/go.mod h1:DYY7MBk1bdzusC3SYhjObp+wFpr4gzcvqqNjLnInEg4= github.com/spf13/pflag v1.0.5 h1:iy+VFUOCP1a+8yFto/drg2CJ5u0yRoB7fZw3DKv/JXA= github.com/spf13/pflag v1.0.5/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg= @@ -669,12 +705,17 @@ github.com/vishvananda/netlink v1.1.1-0.20201029203352-d40f9887b852/go.mod h1:tw github.com/vishvananda/netns v0.0.0-20180720170159-13995c7128cc/go.mod h1:ZjcWmFBXmLKZu9Nxj3WKYEafiSqer2rnvPr0en9UNpI= github.com/vishvananda/netns v0.0.0-20191106174202-0a2b9b5464df/go.mod h1:JP3t17pCcGlemwknint6hfoeCVQrEMVwxRLRjXpq+BU= github.com/vishvananda/netns v0.0.0-20200728191858-db3c7e526aae/go.mod h1:DD4vA1DwXk04H54A1oHXtwZmA0grkVMdPxx/VGLCah0= +github.com/vmihailenco/msgpack v3.3.3+incompatible/go.mod h1:fy3FlTQTDXWkZ7Bh6AcGMlsjHatGryHQYUTf1ShIgkk= +github.com/vmihailenco/msgpack/v4 v4.3.12/go.mod h1:gborTTJjAo/GWTqqRjrLCn9pgNN+NXzzngzBKDPIqw4= +github.com/vmihailenco/tagparser v0.1.1/go.mod h1:OeAg3pn3UbLjkWt+rN9oFYB6u/cQgqMEUPoW2WPyhdI= github.com/willf/bitset v1.1.11-0.20200630133818-d5bec3311243/go.mod h1:RjeCKbqT1RxIR/KWY6phxZiaY1IyutSBfGjNPySAYV4= github.com/willf/bitset v1.1.11/go.mod h1:83CECat5yLh5zVOf4P1ErAgKA5UDvKtgyUABdr3+MjI= github.com/xeipuuv/gojsonpointer v0.0.0-20180127040702-4e3ac2762d5f/go.mod h1:N2zxlSyiKSe5eX1tZViRH5QA0qijqEDrYZiPEAiq3wU= github.com/xeipuuv/gojsonreference v0.0.0-20180127040603-bd5ef7bd5415/go.mod h1:GwrjFmJcFw6At/Gs6z4yjiIwzuJ1/+UwLxMQDVQXShQ= github.com/xeipuuv/gojsonschema v0.0.0-20180618132009-1d523034197f/go.mod h1:5yf86TLmAcydyeJq5YvxkGPE2fm/u4myDekKRoLuqhs= github.com/xiang90/probing v0.0.0-20190116061207-43a291ad63a2/go.mod h1:UETIi67q53MR2AWcXfiuqkDkRtnGDLqkBTpCHuJHxtU= +github.com/xo/terminfo v0.0.0-20210125001918-ca9a967f8778 h1:QldyIu/L63oPpyvQmHgvgickp1Yw510KJOqX7H24mg8= +github.com/xo/terminfo v0.0.0-20210125001918-ca9a967f8778/go.mod h1:2MuV+tbUrU1zIOPMxZ5EncGwgmMJsa+9ucAQZXxsObs= github.com/xordataexchange/crypt v0.0.3-0.20170626215501-b2862e3d0a77/go.mod h1:aYKd//L2LvnjZzWKhF00oedf4jCCReLcmhLdhm1A27Q= github.com/yuin/goldmark v1.1.25/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= github.com/yuin/goldmark v1.1.27/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= @@ -684,6 +725,10 @@ github.com/yuin/goldmark v1.3.5/go.mod h1:mwnBkeHKe2W/ZEtQ+71ViKU8L12m81fl3OWwC1 github.com/yvasiyarov/go-metrics v0.0.0-20140926110328-57bccd1ccd43/go.mod h1:aX5oPXxHm3bOH+xeAttToC8pqch2ScQN/JoXYupl6xs= github.com/yvasiyarov/gorelic v0.0.0-20141212073537-a9bba5b9ab50/go.mod h1:NUSPSUX/bi6SeDMUh6brw0nXpxHnc96TguQh0+r/ssA= github.com/yvasiyarov/newrelic_platform_go v0.0.0-20140908184405-b21fdbd4370f/go.mod h1:GlGEuHIJweS1mbCqG+7vt2nvWLzLLnRHbXz5JKd/Qbg= +github.com/zclconf/go-cty v1.2.0/go.mod h1:hOPWgoHbaTUnI5k4D2ld+GRpFJSCe6bCM7m1q/N4PQ8= +github.com/zclconf/go-cty v1.8.0 h1:s4AvqaeQzJIu3ndv4gVIhplVD0krU+bgrcLSVUnaWuA= +github.com/zclconf/go-cty v1.8.0/go.mod h1:vVKLxnk3puL4qRAv72AO+W99LUD4da90g3uUAzyuvAk= +github.com/zclconf/go-cty-debug v0.0.0-20191215020915-b22d67c1ba0b/go.mod h1:ZRKQfBXbGkpdV6QMzT3rU1kSTAnfu1dO8dPKjYprgj8= go.etcd.io/bbolt v1.3.2/go.mod h1:IbVyRI1SCnLcuJnV2u8VeU0CEYM7e686BmAb1XKL+uU= go.etcd.io/bbolt v1.3.3/go.mod h1:IbVyRI1SCnLcuJnV2u8VeU0CEYM7e686BmAb1XKL+uU= go.etcd.io/bbolt v1.3.5/go.mod h1:G5EMThwa9y8QZGBClrRx5EY+Yw9kAhnjy3bSjsnlVTQ= @@ -701,16 +746,23 @@ go.opencensus.io v0.22.5/go.mod h1:5pWMHQbX5EPX2/62yrJeAkowc+lfs/XD7Uxpq3pI6kk= go.opencensus.io v0.23.0/go.mod h1:XItmlyltB5F7CS4xOC1DcqMoFqwtC6OG2xF7mCv7P7E= go.uber.org/atomic v1.3.2/go.mod h1:gD2HeocX3+yG+ygLZcrzQJaqmWj9AIm7n08wl/qW/PE= go.uber.org/atomic v1.4.0/go.mod h1:gD2HeocX3+yG+ygLZcrzQJaqmWj9AIm7n08wl/qW/PE= +go.uber.org/atomic v1.7.0 h1:ADUqmZGgLDDfbSL9ZmPxKTybcoEYHgpYfELNoN+7hsw= go.uber.org/atomic v1.7.0/go.mod h1:fEN4uk6kAWBTFdckzkM89CLk9XfWZrxpCo0nPH17wJc= +go.uber.org/goleak v1.1.10 h1:z+mqJhf6ss6BSfSM671tgKyZBFPTTJM+HLxnhPC3wu0= +go.uber.org/goleak v1.1.10/go.mod h1:8a7PlsEVH3e/a/GLqe5IIrQx6GzcnRmZEufDUTk4A7A= go.uber.org/multierr v1.1.0/go.mod h1:wR5kodmAFQ0UK8QlbwjlSNy0Z68gJhDJUG5sjR94q/0= +go.uber.org/multierr v1.6.0 h1:y6IPFStTAIT5Ytl7/XYmHvzXQ7S3g/IeZW9hyZ5thw4= go.uber.org/multierr v1.6.0/go.mod h1:cdWPpRnG4AhwMwsgIHip0KRBQjJy5kYEpYjJxpXp9iU= go.uber.org/zap v1.10.0/go.mod h1:vwi/ZaCAaUcBkycHslxD9B2zi4UTXhF60s6SWpuDF0Q= go.uber.org/zap v1.17.0/go.mod h1:MXVU+bhUf/A7Xi2HNOnopQOrmycQ5Ih87HtOu4q5SSo= +go.uber.org/zap v1.19.0 h1:mZQZefskPPCMIBCSEH0v2/iUqqLrYtaeqwD6FUGUnFE= +go.uber.org/zap v1.19.0/go.mod h1:xg/QME4nWcxGxrpdeYfq7UvYrLh66cuVKdrbD1XF/NI= golang.org/x/crypto v0.0.0-20171113213409-9f005a07e0d3/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4= golang.org/x/crypto v0.0.0-20180904163835-0709b304e793/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4= golang.org/x/crypto v0.0.0-20181009213950-7c1a557ab941/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4= golang.org/x/crypto v0.0.0-20181029021203-45a5f77698d3/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4= golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= +golang.org/x/crypto v0.0.0-20190426145343-a29dc8fdc734/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= golang.org/x/crypto v0.0.0-20190510104115-cbcb75029529/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= golang.org/x/crypto v0.0.0-20190605123033-f99c8df09eb5/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= golang.org/x/crypto v0.0.0-20190611184440-5c40567a22f8/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= @@ -744,6 +796,7 @@ golang.org/x/lint v0.0.0-20191125180803-fdd1cda4f05f/go.mod h1:5qLYkcX4OjUUV8bRu golang.org/x/lint v0.0.0-20200130185559-910be7a94367/go.mod h1:3xt1FjdF8hUf6vQPIChWIBhFzV8gjjsPE/fR3IyQdNY= golang.org/x/lint v0.0.0-20200302205851-738671d3881b/go.mod h1:3xt1FjdF8hUf6vQPIChWIBhFzV8gjjsPE/fR3IyQdNY= golang.org/x/lint v0.0.0-20201208152925-83fdc39ff7b5/go.mod h1:3xt1FjdF8hUf6vQPIChWIBhFzV8gjjsPE/fR3IyQdNY= +golang.org/x/lint v0.0.0-20210508222113-6edffad5e616 h1:VLliZ0d+/avPrXXH+OakdXhpJuEoBZuwh1m2j7U6Iug= golang.org/x/lint v0.0.0-20210508222113-6edffad5e616/go.mod h1:3xt1FjdF8hUf6vQPIChWIBhFzV8gjjsPE/fR3IyQdNY= golang.org/x/mobile v0.0.0-20190312151609-d3739f865fa6/go.mod h1:z+o9i4GpDbdi3rU15maQ/Ox0txvL9dWGYEHz965HBQE= golang.org/x/mobile v0.0.0-20190719004257-d2bd2a29d028/go.mod h1:E/iHnbuqvinMTCcRqshq8CkpyQDoeVncDDYHnLhea+o= @@ -757,6 +810,7 @@ golang.org/x/mod v0.4.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= golang.org/x/mod v0.4.1/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= golang.org/x/mod v0.4.2/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= golang.org/x/net v0.0.0-20180724234803-3673e40ba225/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= +golang.org/x/net v0.0.0-20180811021610-c39426892332/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= golang.org/x/net v0.0.0-20180826012351-8a410e7b638d/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= golang.org/x/net v0.0.0-20180906233101-161cd47e91fd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= golang.org/x/net v0.0.0-20181011144130-49bb7cea24b1/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= @@ -840,6 +894,7 @@ golang.org/x/sys v0.0.0-20190312061237-fead79001313/go.mod h1:h1NjWce9XRLGQEsW7w golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20190422165155-953cdadca894/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20190502145724-3ef323f4f1fd/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20190502175342-a43fa875dd82/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20190507160741-ecd444e8653b/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20190514135907-3a4b5fb9f71f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20190522044717-8097e1b27ff5/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= @@ -905,9 +960,13 @@ golang.org/x/sys v0.0.0-20210324051608-47abb6519492/go.mod h1:h1NjWce9XRLGQEsW7w golang.org/x/sys v0.0.0-20210330210617-4fbd30eecc44/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20210403161142-5e06dd20ab57/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20210510120138-977fb7262007/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20210616094352-59db8d763f22 h1:RqytpXGR1iVNX7psjB3ff8y7sNFinVFvkx1c8SjBkio= golang.org/x/sys v0.0.0-20210616094352-59db8d763f22/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= +golang.org/x/term v0.0.0-20210220032956-6a3ed077a48d/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= +golang.org/x/term v0.0.0-20210615171337-6886f2dfbf5b h1:9zKuko04nR4gjZ4+DNjHqRlAJqbJETHwiNKDqTfOjfE= +golang.org/x/term v0.0.0-20210615171337-6886f2dfbf5b/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8= golang.org/x/text v0.0.0-20170915032832-14c0d48ead0c/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/text v0.3.1-0.20180807135948-17ff2d5776d2/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= @@ -942,6 +1001,7 @@ golang.org/x/tools v0.0.0-20190628153133-6cdbf07be9d0/go.mod h1:/rFqwRUd4F7ZHNgw golang.org/x/tools v0.0.0-20190816200558-6889da9d5479/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= golang.org/x/tools v0.0.0-20190911174233-4f2ddba30aff/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= golang.org/x/tools v0.0.0-20191012152004-8de300cfc20a/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= +golang.org/x/tools v0.0.0-20191108193012-7d206e10da11/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= golang.org/x/tools v0.0.0-20191112195655-aa38f8e97acc/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= golang.org/x/tools v0.0.0-20191113191852-77e3bb0ad9e7/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= golang.org/x/tools v0.0.0-20191115202509-3a792d9c32b2/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= @@ -976,6 +1036,7 @@ golang.org/x/tools v0.0.0-20201208233053-a543418bbed2/go.mod h1:emZCQorbCU4vsT4f golang.org/x/tools v0.0.0-20210105154028-b0ab187a4818/go.mod h1:emZCQorbCU4vsT4fOWvOPXz4eW1wZW4PmDk9uLelYpA= golang.org/x/tools v0.0.0-20210106214847-113979e3529a/go.mod h1:emZCQorbCU4vsT4fOWvOPXz4eW1wZW4PmDk9uLelYpA= golang.org/x/tools v0.1.0/go.mod h1:xkSsbof2nBLbhDlRMhhhyNLN/zl3eTqcnHD5viDpcZ0= +golang.org/x/tools v0.1.2 h1:kRBLX7v7Af8W7Gdbbc908OJcdgtK8bOz9Uaj8/F1ACA= golang.org/x/tools v0.1.2/go.mod h1:o0xws9oXOQQZyjljx8fwUC0k7L1pTE6eaCbjGeHmOkk= golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= diff --git a/pkg/gomplate/gomplate.go b/pkg/gomplate/gomplate.go new file mode 100644 index 00000000..c18114f0 --- /dev/null +++ b/pkg/gomplate/gomplate.go @@ -0,0 +1,83 @@ +package gomplate + +import ( + "context" + "fmt" + + "github.com/docker/docker/api/types" + "github.com/docker/docker/api/types/container" + "github.com/docker/docker/api/types/mount" + "github.com/docker/docker/api/types/strslice" + "github.com/docker/docker/client" + "github.com/hazelops/ize/pkg/logger" +) + +const ( + imageName = "hairyhenderson/gomplate" + imageTag = "latest" +) + +// Options for run gomplate +type GomplateOptions struct { + OutputFileDir string + InputFileDir string + InputFileName string + OutputFileName string + Env []string +} + +// Run gomplate container and generate file +func RunGomplate(opts GomplateOptions, log logger.StandartLogger) error { + cli, err := client.NewClientWithOpts(client.FromEnv) + if err != nil { + return err + } + + _, err = cli.ImagePull(context.Background(), fmt.Sprintf("%v:%v", imageName, imageTag), types.ImagePullOptions{}) + if err != nil { + return err + } + + cont, err := cli.ContainerCreate(context.Background(), &container.Config{ + Cmd: strslice.StrSlice{"-f", fmt.Sprintf("%v/%v", opts.InputFileDir, opts.InputFileName), + "-o", fmt.Sprintf("%v/%v", opts.OutputFileDir, opts.OutputFileName)}, + Image: fmt.Sprintf("%v:%v", imageName, imageTag), + Tty: true, + AttachStdin: true, + AttachStdout: true, + AttachStderr: true, + OpenStdin: true, + WorkingDir: opts.InputFileDir, + Env: opts.Env, + }, + &container.HostConfig{ + + AutoRemove: true, + Mounts: []mount.Mount{ + { + Type: mount.TypeBind, + Source: fmt.Sprintf("%v", opts.InputFileDir), + Target: fmt.Sprintf("%v", opts.InputFileDir), + }, + { + Type: mount.TypeBind, + Source: fmt.Sprintf("%v", opts.OutputFileDir), + Target: fmt.Sprintf("%v", opts.OutputFileDir), + }, + }, + }, + nil, nil, "", + ) + + if err != nil { + return err + } + + err = cli.ContainerStart(context.Background(), cont.ID, types.ContainerStartOptions{}) + + if err != nil { + log.Error(err) + return err + } + return nil +} diff --git a/pkg/logger/zap.go b/pkg/logger/zap.go new file mode 100644 index 00000000..021acbdb --- /dev/null +++ b/pkg/logger/zap.go @@ -0,0 +1,88 @@ +package logger + +import ( + "errors" + + "go.uber.org/zap" + "go.uber.org/zap/zapcore" +) + +const maxLogLen = 1024 + +type StandartLogger struct { + *zap.SugaredLogger +} + +func (l *StandartLogger) Write(p []byte) (n int, err error) { + if len(p) > maxLogLen { + l.Debugw(string(p[:maxLogLen]), "truncated", true) + return maxLogLen, errors.New("log line too long") + } + l.Debug(string(p)) + return len(p), nil +} + +func (l *StandartLogger) Infof(template string, args ...interface{}) { + l.SugaredLogger.Infof(template, args...) +} + +func NewSugaredLogger(logLevel zapcore.Level) StandartLogger { + config := NewStandardZapConfig(logLevel) + + zapLogger, err := config.Build() + if err != nil { + panic(err) + } + + return StandartLogger{ + SugaredLogger: zapLogger.Sugar(), + } +} + +// NewStandardLogger creates a new zap.Logger based on common configuration +// +// This is intended to be used with zap.ReplaceGlobals() in an application's +// main.go. +func NewStandardLogger(logLevel zapcore.Level) (l *zap.Logger, err error) { + config := NewStandardZapConfig(logLevel) + return config.Build() +} + +// NewStandardZapConfig returns a sensible [config](https://godoc.org/go.uber.org/zap#Config) for a Zap logger. +func NewStandardZapConfig(logLevel zapcore.Level) zap.Config { + if logLevel.String() == "info" || logLevel.String() == "debug" { + return zap.Config{ + Level: zap.NewAtomicLevelAt(logLevel), + Development: false, + Sampling: &zap.SamplingConfig{ + Initial: 100, + Thereafter: 100, + }, + Encoding: "console", + EncoderConfig: zapcore.EncoderConfig{ + TimeKey: "timestamp", + LevelKey: "level", + NameKey: "logger", + CallerKey: "caller", + MessageKey: "message", + StacktraceKey: "stacktrace", + EncodeLevel: zapcore.LowercaseLevelEncoder, + EncodeTime: zapcore.ISO8601TimeEncoder, + EncodeDuration: zapcore.SecondsDurationEncoder, + EncodeCaller: zapcore.ShortCallerEncoder, + }, + OutputPaths: []string{"stdout"}, + ErrorOutputPaths: []string{"stderr"}, + } + } + + return zap.Config{ + Level: zap.NewAtomicLevelAt(logLevel), + Development: false, + Sampling: &zap.SamplingConfig{ + Initial: 100, + Thereafter: 100, + }, + Encoding: "console", + } +} diff --git a/cmd/root.go b/temp similarity index 91% rename from cmd/root.go rename to temp index 15de214a..c84979f9 100644 --- a/cmd/root.go +++ b/temp @@ -13,18 +13,23 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. */ -package cmd +package commands import ( "fmt" + "os" + "github.com/hazelops/ize/docker" + "github.com/hazelops/ize/pkg/logger" + "github.com/spf13/cobra" - "os" + "go.uber.org/zap/zapcore" "github.com/spf13/viper" ) var cfgFile string +var debug bool // rootCmd represents the base command when called without any subcommands var rootCmd = &cobra.Command{ @@ -41,8 +46,6 @@ to quickly create a Cobra application.`, // Run: func(cmd *cobra.Command, args []string) { }, } - - var versionCmd = &cobra.Command{ Use: "version", Short: "Print the version number of Hugo", @@ -82,7 +85,6 @@ var runWaypointInit = &cobra.Command{ }, } - var terraformCmd = &cobra.Command{ Use: "terraform", Short: "Run Terraform Init", @@ -99,7 +101,19 @@ var runTerraformInit = &cobra.Command{ Long: `Run Terraform Init`, Run: func(cmd *cobra.Command, args []string) { fmt.Println("Running Terraform Init") - docker.TerraformInit() + + logLevel := zapcore.InfoLevel + + if debug { + logLevel = zapcore.DebugLevel + + } + + l := logger.NewSugaredLogger(logLevel) + + l.Infof("err") + + docker.TerraformInit(l) }, } var runTerraformPlan = &cobra.Command{ @@ -108,11 +122,13 @@ var runTerraformPlan = &cobra.Command{ Long: `Run Terraform Plan`, Run: func(cmd *cobra.Command, args []string) { fmt.Println("Running Terraform Plan") - docker.TerraformPlan() + + var log logger.StandartLogger + + docker.TerraformPlan(log) }, } - // Execute adds all child commands to the root command and sets flags appropriately. // This is called by main.main(). It only needs to happen once to the rootCmd. func Execute() { @@ -128,6 +144,7 @@ func init() { // will be global for your application. rootCmd.PersistentFlags().StringVar(&cfgFile, "config", "", "config file (default is $HOME/.ize.yaml)") + rootCmd.PersistentFlags().BoolVarP(&debug, "", "v", false, "enable debug message") // Cobra also supports local flags, which will only run // when this action is called directly. @@ -157,7 +174,6 @@ func initConfig() { // Search config in home directory with name ".ize" (without extension). viper.AddConfigPath(".") - viper.SetConfigName("ize") viper.SetConfigType("yaml") } @@ -167,12 +183,10 @@ func initConfig() { fmt.Println("Error getting current directory") } - // Find home directory. home, err := os.UserHomeDir() cobra.CheckErr(err) - viper.AutomaticEnv() // read in environment variables that match //TODO ensure values of the variables are checked for nil before passing down to docker. @@ -183,10 +197,9 @@ func initConfig() { viper.SetDefault("ENV_DIR", fmt.Sprintf("%v/.infra/env/%v", cwd, viper.Get("ENV"))) viper.SetDefault("HOME", fmt.Sprintf("%v", home)) viper.SetDefault("TF_LOG", fmt.Sprintf("")) - viper.SetDefault("TF_LOG_PATH", fmt.Sprintf("%v/tflog.txt",viper.Get("ENV_DIR") )) + viper.SetDefault("TF_LOG_PATH", fmt.Sprintf("%v/tflog.txt", viper.Get("ENV_DIR"))) viper.SetDefault("TERRAFORM_VERSION", fmt.Sprintf("0.12.29")) - // If a config file is found, read it in. if err := viper.ReadInConfig(); err == nil { fmt.Fprintln(os.Stderr, "Using config file:", viper.ConfigFileUsed())