diff --git a/cmd/dc-installer/main.go b/cmd/dc-installer/main.go index 6c9051a..c1c3809 100644 --- a/cmd/dc-installer/main.go +++ b/cmd/dc-installer/main.go @@ -2,6 +2,7 @@ package main import ( "fmt" + "github.com/dragonchain/dragonchain-installer/internal/kubectl" "os" "strings" @@ -9,7 +10,6 @@ import ( "github.com/dragonchain/dragonchain-installer/internal/dragonchain" "github.com/dragonchain/dragonchain-installer/internal/dragonnet" "github.com/dragonchain/dragonchain-installer/internal/helm" - "github.com/dragonchain/dragonchain-installer/internal/kubectl" "github.com/dragonchain/dragonchain-installer/internal/minikube" "github.com/dragonchain/dragonchain-installer/internal/upnp" "github.com/dragonchain/dragonchain-installer/internal/virtualbox" @@ -26,29 +26,32 @@ func fatalLog(v ...interface{}) { } func installer() { - fmt.Print("Starting dragonchain installer\nChecking for required dependencies\n\n") - if err := kubectl.InstallKubectlIfNecessary(); err != nil { - fatalLog(err) - } - if err := helm.InstallHelmIfNecessary(); err != nil { - fatalLog(err) - } - if err := minikube.InstallMinikubeIfNecessary(); err != nil { - fatalLog(err) - } - fmt.Print("\nBase dependencies installed\nConfiguring dependencies now\n\n") + fmt.Print("Starting dragonchain installer\n") config, err := configuration.PromptForUserConfiguration() if err != nil { fatalLog(err) } - if config.UseVM { - fmt.Print("Virtualbox required for minikube VM. Checking and installing if necessary\n") - if err := virtualbox.InstallVirtualBoxIfNecessary(); err != nil { + fmt.Print("Starting dragonchain installer\nChecking for required dependencies\n\n") + if config.InstallKubernetes { + if err := kubectl.InstallKubectlIfNecessary(); err != nil { + fatalLog(err) + } + if err := helm.InstallHelmIfNecessary(); err != nil { + fatalLog(err) + } + if err := minikube.InstallMinikubeIfNecessary(); err != nil { + fatalLog(err) + } + fmt.Print("\nBase dependencies installed\nConfiguring dependencies now\n\n") + if config.UseVM { + fmt.Print("Virtualbox required for minikube VM. Checking and installing if necessary\n") + if err := virtualbox.InstallVirtualBoxIfNecessary(); err != nil { + fatalLog(err) + } + } + if err := minikube.StartMinikubeCluster(config.UseVM); err != nil { fatalLog(err) } - } - if err := minikube.StartMinikubeCluster(config.UseVM); err != nil { - fatalLog(err) } if err := helm.InitializeHelm(); err != nil { fatalLog(err) @@ -56,10 +59,13 @@ func installer() { if err := dragonchain.SetupDragonchainPreReqs(config); err != nil { fatalLog(err) } - if config.UseVM { + if config.UseVM && config.InstallKubernetes { if err := virtualbox.ConfigureVirtualboxVM(config); err != nil { fatalLog(err) } + } + if !config.UseVM && !config.InstallKubernetes { + } fmt.Print("\nConfiguration of dependencies complete\nNow installing Dragonchain\n") if err := dragonchain.InstallDragonchain(config); err != nil { @@ -71,9 +77,11 @@ func installer() { fatalLog(err) } fmt.Print("Dragonchain public id is: " + pubID + "\n\n") - startCommand, stopCommand := minikube.FriendlyStartStopCommand(config.UseVM) - fmt.Print("In order to stop the dragonchain, run the following command in a terminal:\n" + stopCommand + "\n\n") - fmt.Print("In order to restart the dragonchain, run the following command in a terminal:\n" + startCommand + "\n\n") + if config.InstallKubernetes { + startCommand, stopCommand := minikube.FriendlyStartStopCommand(config.UseVM) + fmt.Print("In order to stop the dragonchain, run the following command in a terminal:\n" + stopCommand + "\n\n") + fmt.Print("In order to restart the dragonchain, run the following command in a terminal:\n" + startCommand + "\n\n") + } if err := configuration.InstallDragonchainCredentials(config, pubID); err != nil { fatalLog(err) } diff --git a/internal/configuration/input.go b/internal/configuration/input.go index 1f6e457..facc7eb 100644 --- a/internal/configuration/input.go +++ b/internal/configuration/input.go @@ -26,6 +26,9 @@ type Configuration struct { InternalID string `json:"InternalID"` RegistrationToken string `json:"RegistrationToken"` UseVM bool `json:"UseVM"` + InstallKubernetes bool `json:"InstallKubernetes"` + Stage string `json:"Stage"` + S3Bucket string `json:"S3Bucket"` PrivateKey string HmacID string HmacKey string @@ -156,9 +159,6 @@ func getPort() (int, error) { if err != nil { return -1, errors.New("Couldn't parse provided port into integer:\n" + err.Error()) } - if parsedPort < 30000 || parsedPort > 32767 { - return -1, errors.New("Port must be between 30000 and 32767") - } port = int(parsedPort) } return port, nil @@ -188,7 +188,9 @@ func getEndpoint(port int) (string, error) { } } // add selected port to the endpoint - endpoint += ":" + strconv.Itoa(port) + if port != 80 && port != 8080 { + endpoint += ":" + strconv.Itoa(port) + } return endpoint, nil } @@ -221,6 +223,39 @@ func getVMDriver() (bool, error) { return false, errors.New("Must answer yes/no") } +func shouldInstallKubernetes() (bool, error) { + answer, err := getUserInput("Would you like to install on existing kubernetes architecture? (yes/no) ") + if err != nil { + return false, err + } + answer = strings.ToLower(answer) + if answer == "y" || answer == "yes" { + return true, nil + } else if answer == "n" || answer == "no" { + return false, nil + } + return false, errors.New("Must answer yes/no") +} + +func getStage() string { + stage := "dev" + answer, _ := getUserInput("Which stage would you like to use for your chain? (prod/dev) ") + answer = strings.ToLower(answer) + if answer == "p" || answer == "prod" { + stage = "prod" + } + return stage +} + +func getS3Bucket() string { + bucket := "" + answer, _ := getUserInput("S3 Bucket URL: (optional) ") + if answer != "" { + bucket = answer + } + return bucket +} + // PromptForUserConfiguration get user input for all the necessary configurable variables of a Dragonchain func PromptForUserConfiguration() (*Configuration, error) { // Check for existing configuration from previous run first @@ -234,6 +269,9 @@ func PromptForUserConfiguration() (*Configuration, error) { ChainID: ` + existingConf.InternalID + ` MatchmakingToken: ` + existingConf.RegistrationToken + ` UseVM: ` + strconv.FormatBool(existingConf.UseVM) + ` + InstallKubernetes: ` + strconv.FormatBool(existingConf.InstallKubernetes) + ` + Stage: ` + existingConf.Stage + ` + S3 Bucket: ` + existingConf.S3Bucket + ` Would you like to use this config? (yes/no) `) if err != nil { return nil, err @@ -247,6 +285,11 @@ func PromptForUserConfiguration() (*Configuration, error) { return nil, errors.New("Must answer yes/no") } } + stage := getStage() + installKubernetes, err := shouldInstallKubernetes() + if err != nil { + return nil, err + } // Get desired vm usage vmDriver, err := getVMDriver() if err != nil { @@ -285,6 +328,7 @@ func PromptForUserConfiguration() (*Configuration, error) { if err != nil { return nil, err } + s3Bucket := getS3Bucket() // Construct and save the config object config := new(Configuration) config.Level = level @@ -294,6 +338,9 @@ func PromptForUserConfiguration() (*Configuration, error) { config.InternalID = internalID config.RegistrationToken = registrationToken config.UseVM = vmDriver + config.InstallKubernetes = installKubernetes + config.Stage = stage + config.S3Bucket = s3Bucket configJSON, err := json.Marshal(config) if err != nil { return nil, err diff --git a/internal/configuration/variables.go b/internal/configuration/variables.go index 33c1f89..645905a 100644 --- a/internal/configuration/variables.go +++ b/internal/configuration/variables.go @@ -7,19 +7,19 @@ var Version string var DragonchainHelmVersion = "1.0.8" // OpenfaasHelmVersion helm version of openfaas (faas-netes) to use -var OpenfaasHelmVersion = "5.5.4" +var OpenfaasHelmVersion = "7.0.4" //"5.5.4" // RegistryHelmVersion helm version of docker container registry to use var RegistryHelmVersion = "1.9.1" // RegistryIP the clusterip to use for the docker registry deployment -var RegistryIP = "10.98.76.54" +var RegistryIP = "10.100.1.102" //"10.98.76.54" // RegistryPort the port to use for the docker registry deployment var RegistryPort = 5000 // MinikubeContext the name of the minikube profile to use, which is also the kubernetes context and VM name -var MinikubeContext = "dragonchain" +var MinikubeContext = "i-03908209c2eeff0ea@uw1-k8s-eks.us-west-1.eksctl.io" // KubernetesVersion the kubernetes version to use with the dragonchain's minikube cluster var KubernetesVersion = "v1.15.10" diff --git a/internal/dragonchain/installer.go b/internal/dragonchain/installer.go index 1a7048f..19afe2a 100644 --- a/internal/dragonchain/installer.go +++ b/internal/dragonchain/installer.go @@ -100,13 +100,30 @@ func getExistingSecret(config *configuration.Configuration) error { return nil } +// configuration.DragonchainHelmVersion + +func listDirectories() { + cmd := exec.Command("ls", "-la") + output, _ := cmd.Output() + fmt.Print(string(output[:])) +} + func upsertDragonchainHelmDeployment(config *configuration.Configuration) error { setStringStr := "global.environment.LEVEL=" + strconv.Itoa(config.Level) - setStr := "dragonchain.storage.spec.storageClassName=local-path,redis.storage.spec.storageClassName=local-path,redisearch.storage.spec.storageClassName=local-path,global.environment.DRAGONCHAIN_NAME=" + config.Name + ",global.environment.REGISTRATION_TOKEN=" + config.RegistrationToken + ",global.environment.INTERNAL_ID=" + config.InternalID + ",global.environment.DRAGONCHAIN_ENDPOINT=" + config.EndpointURL + ",service.port=" + strconv.Itoa(config.Port) + if config.Stage == "dev" { + setStringStr = setStringStr + ",global.environment.STAGE=" + config.Stage + } + if config.S3Bucket != "" { + setStringStr = setStringStr + ",global.environment.STORAGE_LOCATION=" + config.S3Bucket + ",global.environment.STORAGE_TYPE=s3" + } + setStr := "ingressEndpoint=eks.dragonchain.com,dragonchain.storage.spec.storageClassName=gp2,redis.storage.spec.storageClassName=gp2,redisearch.storage.spec.storageClassName=gp2,global.environment.DRAGONCHAIN_NAME=" + config.Name + ",global.environment.REGISTRATION_TOKEN=" + config.RegistrationToken + ",global.environment.INTERNAL_ID=" + config.InternalID + ",global.environment.DRAGONCHAIN_ENDPOINT=" + config.EndpointURL + ",service.port=" + strconv.Itoa(config.Port) if config.Level == 1 { setStr += ",faas.gateway=http://gateway.openfaas:8080,faas.mountFaasSecret=true,faas.registry=" + configuration.RegistryIP + ":" + strconv.Itoa(configuration.RegistryPort) } - cmd := exec.Command("helm", "upgrade", "--install", "d-"+config.InternalID, "dragonchain/dragonchain-k8s", "--namespace", "dragonchain", "--set-string", setStringStr, "--set", setStr, "--version", configuration.DragonchainHelmVersion, "--kube-context", configuration.MinikubeContext) + cmd := exec.Command("helm", "upgrade", "--install", "d-"+config.InternalID, "./dc-k8s-helm", "--namespace", "dragonchain", "--set-string", setStringStr, "--set", setStr, "--version", "1.0.9", "--kube-context", configuration.MinikubeContext) + if !config.InstallKubernetes { + cmd = exec.Command("helm", "upgrade", "--install", "-f", "./dragonchain-eks/dc-k8s-helm/values.eks.yaml", "d-"+config.InternalID, "./dragonchain-eks/dc-k8s-helm", "--namespace", "dragonchain", "--set-string", setStringStr, "--set", setStr, "--version", "1.0.9", "--kube-context", configuration.MinikubeContext) + } cmd.Stderr = os.Stderr if err := cmd.Run(); err != nil { return errors.New("Error installing dragonchain helm chart:\n" + err.Error()) diff --git a/internal/helm/configure.go b/internal/helm/configure.go index 2ec1eeb..ca792e6 100644 --- a/internal/helm/configure.go +++ b/internal/helm/configure.go @@ -92,7 +92,7 @@ func InitializeHelm() error { } if helmVersion >= 3 { // Stable repository is not added by default in helm 3+ - cmd = exec.Command("helm", "repo", "add", "stable", "https://kubernetes-charts.storage.googleapis.com") + cmd = exec.Command("helm", "repo", "add", "stable", "https://charts.helm.sh/stable") cmd.Stderr = os.Stderr if err := cmd.Run(); err != nil { return errors.New("Adding stable helm repo failed:\n" + err.Error())