diff --git a/cli/cmd/server_install_cmd.go b/cli/cmd/server_install_cmd.go index 88b01006d9..270e0cd508 100644 --- a/cli/cmd/server_install_cmd.go +++ b/cli/cmd/server_install_cmd.go @@ -7,7 +7,9 @@ import ( ) var ( - force = false + force = false + runEnvironment = installer.NoneRunEnvironmentType + installationMode = installer.NotChosenInstallationModeType ) var serverInstallCmd = &cobra.Command{ @@ -17,6 +19,9 @@ var serverInstallCmd = &cobra.Command{ PreRun: setupCommand(SkipConfigValidation()), Run: func(cmd *cobra.Command, args []string) { installer.Force = force + installer.RunEnvironment = runEnvironment + installer.InstallationMode = installationMode + analytics.Track("Server Install", "cmd", map[string]string{}) installer.Start() }, @@ -24,6 +29,11 @@ var serverInstallCmd = &cobra.Command{ } func init() { - serverInstallCmd.Flags().BoolVarP(&force, "force", "f", false, "overwrite existing files") + serverInstallCmd.Flags().BoolVarP(&force, "force", "f", false, "Overwrite existing files") + + // these commands will not have shorthand parameters to avoid colision with existing ones in other commands + serverInstallCmd.Flags().Var(&installationMode, "mode", "Indicate the type of demo environment to be installed with Tracetest. It can be 'with-demo' or 'just-tracetest'.") + serverInstallCmd.Flags().Var(&runEnvironment, "run-environment", "Type of environment were Tracetest will be installed. It can be 'docker' or 'kubernetes'.") + serverCmd.AddCommand(serverInstallCmd) } diff --git a/cli/installer/docker_compose.go b/cli/installer/docker_compose.go index 6da0b5b1be..c284be74b4 100644 --- a/cli/installer/docker_compose.go +++ b/cli/installer/docker_compose.go @@ -325,6 +325,9 @@ func getCompleteProject(ui cliUI.UI, config configuration) *types.Project { project, err := loader.Load(types.ConfigDetails{ WorkingDir: workingDir, ConfigFiles: configFiles, + Environment: map[string]string{ + "TRACETEST_DEV": "", + }, }) if err != nil { ui.Exit(fmt.Errorf("cannot parse docker-compose file: %w", err).Error()) diff --git a/cli/installer/installer.go b/cli/installer/installer.go index 617462373c..ad8770da58 100644 --- a/cli/installer/installer.go +++ b/cli/installer/installer.go @@ -8,7 +8,9 @@ import ( ) var ( - Force = false + Force = false + RunEnvironment = NoneRunEnvironmentType + InstallationMode = NotChosenInstallationModeType ) const createIssueMsg = "If you need help, please create an issue: https://github.com/kubeshop/tracetest/issues/new/choose" @@ -30,9 +32,23 @@ or reach us on Discord https://discord.gg/6zupCZFQbe `) + if RunEnvironment == DockerRunEnvironmentType { // check if docker was previously chosen as a CLI arg + ui.Println("How do you want to run TraceTest?") + ui.Println(" > Using Docker Compose") + dockerCompose.Install(ui) + return + } + + if RunEnvironment == KubernetesRunEnvironmentType { // check if kubernetes was previously chosen as a CLI arg + ui.Println("How do you want to run TraceTest?") + ui.Println(" > Using Kubernetes") + kubernetes.Install(ui) + return + } + option := ui.Select("How do you want to run TraceTest?", []cliUI.Option{ - {"Using Docker Compose", dockerCompose.Install}, - {"Using Kubernetes", kubernetes.Install}, + {Text: "Using Docker Compose", Fn: dockerCompose.Install}, + {Text: "Using Kubernetes", Fn: kubernetes.Install}, }, 0) option.Fn(ui) @@ -82,11 +98,25 @@ func (i installer) Install(ui cliUI.UI) { type preChecker func(ui cliUI.UI) func setInstallationType(ui cliUI.UI, config configuration) { + if InstallationMode == WithoutDemoInstallationModeType { // check if it was previously chosen + ui.Println("Do you have OpenTelemetry based tracing already set up, or would you like us to install a demo tracing environment and app?") + ui.Println(" > I have a tracing environment already. Just install Tracetest") + config.set("installer.only_tracetest", true) + return + } + + if InstallationMode == WithDemoInstallationModeType { // check if it was previously chosen + ui.Println("Do you have OpenTelemetry based tracing already set up, or would you like us to install a demo tracing environment and app?") + ui.Println(" > Just learning tracing! Install Tracetest, OpenTelemetry Collector and the sample app.") + config.set("installer.only_tracetest", false) + return + } + option := ui.Select("Do you have OpenTelemetry based tracing already set up, or would you like us to install a demo tracing environment and app?", []cliUI.Option{ - {"I have a tracing environment already. Just install Tracetest", func(ui cliUI.UI) { + {Text: "I have a tracing environment already. Just install Tracetest", Fn: func(ui cliUI.UI) { config.set("installer.only_tracetest", true) }}, - {"Just learning tracing! Install Tracetest, OpenTelemetry Collector and the sample app.", func(ui cliUI.UI) { + {Text: "Just learning tracing! Install Tracetest, OpenTelemetry Collector and the sample app.", Fn: func(ui cliUI.UI) { config.set("installer.only_tracetest", false) }}, }, 0) diff --git a/cli/installer/kubernetes.go b/cli/installer/kubernetes.go index daee99c53b..ad73257c44 100644 --- a/cli/installer/kubernetes.go +++ b/cli/installer/kubernetes.go @@ -40,8 +40,8 @@ func windowsGnuToolsChecker(ui cliUI.UI) { ui.Warning("I didn't find sed in your system") option := ui.Select("What do you want to do?", []cliUI.Option{ - {"Install sed", installSed}, - {"Fix it manually", exitOption( + {Text: "Install sed", Fn: installSed}, + {Text: "Fix it manually", Fn: exitOption( "Check the helm install docs on https://community.chocolatey.org/packages/sed", )}, }, 0) diff --git a/cli/installer/types.go b/cli/installer/types.go new file mode 100644 index 0000000000..a7c90c6770 --- /dev/null +++ b/cli/installer/types.go @@ -0,0 +1,63 @@ +package installer + +import ( + "errors" + + "github.com/spf13/pflag" +) + +type RunEnvironmentType string + +var _ pflag.Value = (*RunEnvironmentType)(nil) + +const ( + DockerRunEnvironmentType RunEnvironmentType = "docker" + KubernetesRunEnvironmentType RunEnvironmentType = "kubernetes" + NoneRunEnvironmentType RunEnvironmentType = "none" // stands for "no option chosen" +) + +func (e *RunEnvironmentType) String() string { + return string(*e) +} + +func (e *RunEnvironmentType) Set(v string) error { + switch v { + case "docker", "kubernetes": + *e = RunEnvironmentType(v) + return nil + default: + return errors.New(`must be "docker" or "kubernetes"`) + } +} + +func (e *RunEnvironmentType) Type() string { + return "(docker|kubernetes)" +} + +type InstallationModeType string + +var _ pflag.Value = (*InstallationModeType)(nil) + +const ( + WithDemoInstallationModeType InstallationModeType = "with-demo" + WithoutDemoInstallationModeType InstallationModeType = "just-tracetest" + NotChosenInstallationModeType InstallationModeType = "none" // stands for "no option chosen" +) + +func (e *InstallationModeType) String() string { + return string(*e) +} + +func (e *InstallationModeType) Set(v string) error { + switch v { + case "with-demo", "just-tracetest": + *e = InstallationModeType(v) + return nil + default: + return errors.New(`must be "with-demo" or "just-tracetest"`) + } +} + +func (e *InstallationModeType) Type() string { + return "(with-demo|just-tracetest)" +}