Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

EKS Changes #5

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 30 additions & 22 deletions cmd/dc-installer/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@ package main

import (
"fmt"
"github.com/dragonchain/dragonchain-installer/internal/kubectl"
"os"
"strings"

"github.com/dragonchain/dragonchain-installer/internal/configuration"
"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"
Expand All @@ -26,40 +26,46 @@ 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)
}
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 {
Expand All @@ -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)
}
Expand Down
55 changes: 51 additions & 4 deletions internal/configuration/input.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
}

Expand Down Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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 {
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down
6 changes: 3 additions & 3 deletions internal/configuration/variables.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 = "[email protected]"

// KubernetesVersion the kubernetes version to use with the dragonchain's minikube cluster
var KubernetesVersion = "v1.15.10"
Expand Down
21 changes: 19 additions & 2 deletions internal/dragonchain/installer.go
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand Down
2 changes: 1 addition & 1 deletion internal/helm/configure.go
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand Down