Skip to content

Commit

Permalink
Fix installer tracetest dev docker warning and add options to run ins…
Browse files Browse the repository at this point in the history
…taller directly without user input. (#2462)

* Adding options to run installer with previously chosen options

* Adding empty TRACETEST_DEV env when loading docker-compose on installation to avoid warning
  • Loading branch information
danielbdias committed May 2, 2023
1 parent c133ffb commit 5282b36
Show file tree
Hide file tree
Showing 5 changed files with 115 additions and 9 deletions.
14 changes: 12 additions & 2 deletions cli/cmd/server_install_cmd.go
Expand Up @@ -7,7 +7,9 @@ import (
)

var (
force = false
force = false
runEnvironment = installer.NoneRunEnvironmentType
installationMode = installer.NotChosenInstallationModeType
)

var serverInstallCmd = &cobra.Command{
Expand All @@ -17,13 +19,21 @@ 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()
},
PostRun: teardownCommand,
}

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)
}
3 changes: 3 additions & 0 deletions cli/installer/docker_compose.go
Expand Up @@ -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())
Expand Down
40 changes: 35 additions & 5 deletions cli/installer/installer.go
Expand Up @@ -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"
Expand All @@ -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)
Expand Down Expand Up @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions cli/installer/kubernetes.go
Expand Up @@ -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)
Expand Down
63 changes: 63 additions & 0 deletions 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)"
}

0 comments on commit 5282b36

Please sign in to comment.