Skip to content

Commit

Permalink
add arm support and additional features (#1)
Browse files Browse the repository at this point in the history
Signed-off-by: Adam Crowder <[email protected]>
  • Loading branch information
cheeseandcereal authored Dec 31, 2019
1 parent c45a0dc commit 67f3b8a
Show file tree
Hide file tree
Showing 19 changed files with 378 additions and 72 deletions.
2 changes: 1 addition & 1 deletion .version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
v0.5.1
v0.6.0
23 changes: 23 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,28 @@
# Changelog

## v0.6.0

- **Features:**
- Use new dragonchain version 4.3.2
- Add support for vmdriver=none with minikube on linux
- Add partial-support for arm64 on linux (using vmdriver=none option) (experimental; not yet fully working due to [minikube support](https://github.com/kubernetes/minikube/issues/5667))
- Use [local-path-provisioner](https://github.com/rancher/local-path-provisioner) for pvc storage
- Add support to restart installation with previous installation configuration
- **Packaging:**
- Use openfaas chart version 5.4.0
- Use docker-registry chart version 1.9.1
- Update default installed helm to v3.0.2
- Update default installed kubectl to v1.17.0
- Update default installed minikube to v1.6.2
- Update default installed virtualbox to v6.1.0

## v0.5.1

- **Features:**
- Use new Dragonchain version 4.3.0
- **Bugs:**
- Make initializing helm more reliable

## v0.5.0

- **Features:**
Expand Down
7 changes: 6 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,13 @@ windows:
GOOS=$(os) GOARCH=amd64 go build -v -ldflags '-s -w $(LDFLAGS)' -o release/$(BINARY)-$(os)-amd64.exe github.com/dragonchain/dragonchain-installer/cmd/dc-installer
rm cmd/dc-installer/windows_amd64.syso

.PHONY: linux-arm64
linux-arm64:
mkdir -p release
GOOS=linux GOARCH=arm64 go build -v -ldflags '-s -w $(LDFLAGS)' -o release/$(BINARY)-linux-arm64 github.com/dragonchain/dragonchain-installer/cmd/dc-installer

.PHONY: release
release: linux darwin windows
release: linux linux-arm64 darwin windows

clean:
rm -rf release
30 changes: 22 additions & 8 deletions cmd/dc-installer/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,15 +36,18 @@ func installer() {
if err := minikube.InstallMinikubeIfNecessary(); err != nil {
fatalLog(err)
}
if err := virtualbox.InstallVirtualBoxIfNecessary(); err != nil {
fatalLog(err)
}
fmt.Print("\nAll dependencies installed\nConfiguring dependencies now\n\n")
fmt.Print("\nBase dependencies installed\nConfiguring dependencies now\n\n")
config, err := configuration.PromptForUserConfiguration()
if err != nil {
fatalLog(err)
}
if err := minikube.StartMinikubeCluster(); err != nil {
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 := helm.InitializeHelm(); err != nil {
Expand All @@ -53,8 +56,10 @@ func installer() {
if err := dragonchain.SetupDragonchainPreReqs(config); err != nil {
fatalLog(err)
}
if err := virtualbox.ConfigureVirtualboxVM(config); err != nil {
fatalLog(err)
if config.UseVM {
if err := virtualbox.ConfigureVirtualboxVM(config); err != nil {
fatalLog(err)
}
}
fmt.Print("\nConfiguration of dependencies complete\nNow installing Dragonchain\n")
if err := dragonchain.InstallDragonchain(config); err != nil {
Expand All @@ -66,7 +71,7 @@ func installer() {
fatalLog(err)
}
fmt.Print("Dragonchain public id is: " + pubID + "\n\n")
startCommand, stopCommand := minikube.FriendlyStartStopCommand()
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 {
Expand Down Expand Up @@ -98,6 +103,15 @@ func installer() {
}

func main() {
if !(configuration.Windows || configuration.Linux || configuration.Macos) {
fatalLog("Unsupported OS")
}
if !configuration.AMD64 {
// Only non-amd64 architecture supported is arm64 on linux
if !(configuration.ARM64 && configuration.Linux) {
fatalLog("Unsupported OS/Architecture")
}
}
if len(os.Args) > 1 && (os.Args[1] == "-V" || os.Args[1] == "--version" || os.Args[1] == "version") {
fmt.Println(configuration.Version)
} else {
Expand Down
118 changes: 111 additions & 7 deletions internal/configuration/input.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,14 @@ package configuration

import (
"bufio"
"encoding/json"
"errors"
"fmt"
"io/ioutil"
"net/http"
"os"
"os/exec"
"path/filepath"
"regexp"
"strconv"
"strings"
Expand All @@ -16,19 +19,47 @@ import (

// Configuration is all of the data needed to configure a new chain
type Configuration struct {
Level int
Name string
EndpointURL string
Port int
InternalID string
RegistrationToken string
Level int `json:"Level"`
Name string `json:"Name"`
EndpointURL string `json:"EndpointURL"`
Port int `json:"Port"`
InternalID string `json:"InternalID"`
RegistrationToken string `json:"RegistrationToken"`
UseVM bool `json:"UseVM"`
PrivateKey string
HmacID string
HmacKey string
}

var lowerCharNum = []byte("abcdefghijklmnopqrstuvxyz0123456789")

func configFilePath() (string, error) {
credentialFolder, err := credentialFolderPath()
if err != nil {
return "", err
}
return filepath.Join(credentialFolder, "installation_config"), nil
}

func checkExistingConfig() (*Configuration, error) {
existingConfigFile, err := configFilePath()
if err != nil {
return nil, err
}
if _, err := os.Stat(existingConfigFile); os.IsNotExist(err) {
return nil, err
}
file, err := ioutil.ReadFile(existingConfigFile)
if err != nil {
return nil, err
}
existingConf := new(Configuration)
if err = json.Unmarshal([]byte(file), existingConf); err != nil {
return nil, err
}
return existingConf, nil
}

func getPublicIP() (string, error) {
resp, err := http.Get("https://ifconfig.co/")
if err != nil {
Expand Down Expand Up @@ -161,13 +192,74 @@ func getEndpoint(port int) (string, error) {
return endpoint, nil
}

func getVMDriver() (bool, error) {
if !Linux {
// VM Driver must be used if not on linux
return true, nil
}
if !AMD64 {
// VM Driver false is required if not AMD64
return false, nil
}
driver, err := getUserInput("Would you like to use your machine's native docker and run kubernetes outside of a VM? (yes/no) ")
if err != nil {
return false, err
}
driver = strings.ToLower(driver)
if driver == "y" || driver == "yes" {
// ensure docker is installed and running
cmd := exec.Command("sudo", "docker", "version")
cmd.Stderr = os.Stderr
cmd.Stdin = os.Stdin
if err := cmd.Run(); err != nil {
return false, errors.New("Error checking for running docker daemon:\n" + err.Error())
}
return false, nil
} else if driver == "n" || driver == "no" {
return true, nil
}
return false, errors.New("Must answer yes/no")
}

// 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
existingConf, err := checkExistingConfig()
if err == nil {
answer, err := getUserInput(`Existing config found:
Level: ` + strconv.Itoa(existingConf.Level) + `
Name: ` + existingConf.Name + `
EndpointURL: ` + existingConf.EndpointURL + `
Port: ` + strconv.Itoa(existingConf.Port) + `
ChainID: ` + existingConf.InternalID + `
MatchmakingToken: ` + existingConf.RegistrationToken + `
UseVM: ` + strconv.FormatBool(existingConf.UseVM) + `
Would you like to use this config? (yes/no) `)
if err != nil {
return nil, err
}
answer = strings.ToLower(answer)
if answer == "y" || answer == "yes" {
return existingConf, nil
} else if answer == "n" || answer == "no" {
// Nothing happens, simply continue as normal
} else {
return nil, errors.New("Must answer yes/no")
}
}
// Get desired vm usage
vmDriver, err := getVMDriver()
if err != nil {
return nil, err
}
// Get desired level
level, err := getLevel()
if err != nil {
return nil, err
}
if level == 1 && !AMD64 {
return nil, errors.New("Level 1 chains are not supported on your cpu architecture")
}
// Get desired name
name, err := getName()
if err != nil {
Expand All @@ -193,13 +285,25 @@ func PromptForUserConfiguration() (*Configuration, error) {
if err != nil {
return nil, err
}
// Construct and return the config object
// Construct and save the config object
config := new(Configuration)
config.Level = level
config.Name = name
config.EndpointURL = endpoint
config.Port = port
config.InternalID = internalID
config.RegistrationToken = registrationToken
config.UseVM = vmDriver
configJSON, err := json.Marshal(config)
if err != nil {
return nil, err
}
configFile, err := configFilePath()
if err != nil {
return nil, err
}
if err = ioutil.WriteFile(configFile, configJSON, 0664); err != nil {
return nil, err
}
return config, nil
}
6 changes: 6 additions & 0 deletions internal/configuration/os.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,9 @@ var Macos bool = runtime.GOOS == "darwin"

// Linux boolean if running on windows
var Linux bool = runtime.GOOS == "linux"

// AMD64 boolean if running on amd64 architecture
var AMD64 bool = runtime.GOARCH == "amd64"

// ARM64 boolean if running on arm64 architecture
var ARM64 bool = runtime.GOARCH == "arm64"
39 changes: 24 additions & 15 deletions internal/configuration/variables.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@ package configuration
var Version string

// DragonchainHelmVersion helm version of dragonchain to use
var DragonchainHelmVersion = "1.0.4"
var DragonchainHelmVersion = "1.0.6"

// OpenfaasHelmVersion helm version of openfaas (faas-netes) to use
var OpenfaasHelmVersion = "5.2.2"
var OpenfaasHelmVersion = "5.4.0"

// RegistryHelmVersion helm version of docker container registry to use
var RegistryHelmVersion = "1.8.3"
var RegistryHelmVersion = "1.9.1"

// RegistryIP the clusterip to use for the docker registry deployment
var RegistryIP = "10.98.76.54"
Expand All @@ -31,40 +31,49 @@ var MinikubeVMMemory = "4000mb"
var MinikubeCpus = 2

// LinuxVirtualboxLink direct link for linux virtualbox installer download
var LinuxVirtualboxLink = "https://download.virtualbox.org/virtualbox/6.0.14/VirtualBox-6.0.14-133895-Linux_amd64.run"
var LinuxVirtualboxLink = "https://download.virtualbox.org/virtualbox/6.1.0/VirtualBox-6.1.0-135406-Linux_amd64.run"

// MacosVirtualboxLink direct link for macos virtualbox installer download
var MacosVirtualboxLink = "https://download.virtualbox.org/virtualbox/6.0.14/VirtualBox-6.0.14-133895-OSX.dmg"
var MacosVirtualboxLink = "https://download.virtualbox.org/virtualbox/6.1.0/VirtualBox-6.1.0-135406-OSX.dmg"

// WindowsVirtualboxLink direct link for windows virtualbox installer download
var WindowsVirtualboxLink = "https://download.virtualbox.org/virtualbox/6.0.14/VirtualBox-6.0.14-133895-Win.exe"
var WindowsVirtualboxLink = "https://download.virtualbox.org/virtualbox/6.1.0/VirtualBox-6.1.0-135406-Win.exe"

// LinuxMinikubeArm64Link direct link for minikube aarch64 executable
var LinuxMinikubeArm64Link = "https://storage.googleapis.com/minikube/releases/v1.6.2/minikube-linux-arm64"

// LinuxMinikubeLink direct link for linux minikube executable
var LinuxMinikubeLink = "https://github.com/kubernetes/minikube/releases/download/v1.5.2/minikube-linux-amd64"
var LinuxMinikubeLink = "https://storage.googleapis.com/minikube/releases/v1.6.2/minikube-linux-amd64"

// MacosMinikubeLink direct link for macos minikube executable
var MacosMinikubeLink = "https://github.com/kubernetes/minikube/releases/download/v1.5.2/minikube-darwin-amd64"
var MacosMinikubeLink = "https://storage.googleapis.com/minikube/releases/v1.6.2/minikube-darwin-amd64"

// WindowsMinikubeLink direct link for windows minikube executable
var WindowsMinikubeLink = "https://github.com/kubernetes/minikube/releases/download/v1.5.2/minikube-windows-amd64.exe"
var WindowsMinikubeLink = "https://storage.googleapis.com/minikube/releases/v1.6.2/minikube-windows-amd64.exe"

// LinuxHelmLink direct link for linux helm package
var LinuxHelmLink = "https://get.helm.sh/helm-v2.16.1-linux-amd64.tar.gz"
var LinuxHelmLink = "https://get.helm.sh/helm-v3.0.2-linux-amd64.tar.gz"

// LinuxHelmArm64Link direct link for linux arm64 helm package
var LinuxHelmArm64Link = "https://get.helm.sh/helm-v3.0.2-linux-arm64.tar.gz"

// MacosHelmLink direct link for macos helm package
var MacosHelmLink = "https://get.helm.sh/helm-v2.16.1-darwin-amd64.tar.gz"
var MacosHelmLink = "https://get.helm.sh/helm-v3.0.2-darwin-amd64.tar.gz"

// WindowsHelmLink direct link for windows helm package
var WindowsHelmLink = "https://get.helm.sh/helm-v2.16.1-windows-amd64.zip"
var WindowsHelmLink = "https://get.helm.sh/helm-v3.0.2-windows-amd64.zip"

// LinuxKubectlLink direct link for linux kubectl executable
var LinuxKubectlLink = "https://storage.googleapis.com/kubernetes-release/release/v1.16.2/bin/linux/amd64/kubectl"
var LinuxKubectlLink = "https://storage.googleapis.com/kubernetes-release/release/v1.17.0/bin/linux/amd64/kubectl"

// LinuxKubectlArm64Link directl link for linux arm64 kubectl executable
var LinuxKubectlArm64Link = "https://storage.googleapis.com/kubernetes-release/release/v1.17.0/bin/linux/arm64/kubectl"

// MacosKubectlLink direct link for macos kubectl executable
var MacosKubectlLink = "https://storage.googleapis.com/kubernetes-release/release/v1.16.2/bin/darwin/amd64/kubectl"
var MacosKubectlLink = "https://storage.googleapis.com/kubernetes-release/release/v1.17.0/bin/darwin/amd64/kubectl"

// WindowsKubectlLink direct link for windows kubectl executable
var WindowsKubectlLink = "https://storage.googleapis.com/kubernetes-release/release/v1.16.2/bin/windows/amd64/kubectl.exe"
var WindowsKubectlLink = "https://storage.googleapis.com/kubernetes-release/release/v1.17.0/bin/windows/amd64/kubectl.exe"

// SetDefaultCredentials indicates whether or not to set the default chain whe configuring the credentials ini file
var SetDefaultCredentials = true
9 changes: 7 additions & 2 deletions internal/dragonchain/confirm.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package dragonchain
import (
"encoding/json"
"errors"
"fmt"
"os"
"os/exec"
"strings"
Expand Down Expand Up @@ -65,10 +66,14 @@ func dragonchainPubIDRecurse(config *configuration.Configuration, tries int) (st
}

func waitForDragonchainToBeReady(config *configuration.Configuration) error {
// Wait up to 90-ish seconds for dragonchain to be ready before erroring
for i := 0; i < 90; i++ {
// Wait up to 120-ish seconds for dragonchain to be ready before erroring
for i := 0; i < 120; i++ {
// Wait before checking
time.Sleep(1 * time.Second)
// Print a '.' every 10 seconds to show that the program is still running
if i%10 == 0 {
fmt.Print(".")
}
cmd := exec.Command("kubectl", "get", "pod", "-n", "dragonchain", "-l", "dragonchainId="+config.InternalID, "-o", "json", "--context="+configuration.MinikubeContext)
cmd.Stderr = os.Stderr
output, err := cmd.Output()
Expand Down
Loading

0 comments on commit 67f3b8a

Please sign in to comment.