From a9a5bc34fb30442fbd8949fcf4173282d1e9b80d Mon Sep 17 00:00:00 2001 From: Jonas Pfannschmidt Date: Fri, 21 Sep 2018 18:55:35 +0100 Subject: [PATCH] cmd/puppeth: allow specifying a version for geth and faucet --- cmd/puppeth/module_faucet.go | 3 ++- cmd/puppeth/module_node.go | 4 +++- cmd/puppeth/wizard.go | 29 +++++++++++++++++++++++++++++ cmd/puppeth/wizard_faucet.go | 7 ++++++- cmd/puppeth/wizard_node.go | 6 ++++++ 5 files changed, 46 insertions(+), 3 deletions(-) diff --git a/cmd/puppeth/module_faucet.go b/cmd/puppeth/module_faucet.go index 06c9fc0f58..aaf5331942 100644 --- a/cmd/puppeth/module_faucet.go +++ b/cmd/puppeth/module_faucet.go @@ -33,7 +33,7 @@ import ( // faucetDockerfile is the Dockerfile required to build a faucet container to // grant crypto tokens based on GitHub authentications. var faucetDockerfile = ` -FROM ethereum/client-go:alltools-latest +FROM ethereum/client-go:alltools-{{.Version}} ADD genesis.json /genesis.json ADD account.json /account.json @@ -90,6 +90,7 @@ func deployFaucet(client *sshClient, network string, bootnodes []string, config dockerfile := new(bytes.Buffer) template.Must(template.New("").Parse(faucetDockerfile)).Execute(dockerfile, map[string]interface{}{ + "Version": config.node.version, "NetworkID": config.node.network, "Bootnodes": strings.Join(bootnodes, ","), "Ethstats": config.node.ethstats, diff --git a/cmd/puppeth/module_node.go b/cmd/puppeth/module_node.go index 038152a3e4..aabca3041c 100644 --- a/cmd/puppeth/module_node.go +++ b/cmd/puppeth/module_node.go @@ -32,7 +32,7 @@ import ( // nodeDockerfile is the Dockerfile required to run an Ethereum node. var nodeDockerfile = ` -FROM ethereum/client-go:latest +FROM ethereum/client-go:{{.Version}} ADD genesis.json /genesis.json {{if .Unlock}} @@ -97,6 +97,7 @@ func deployNode(client *sshClient, network string, bootnodes []string, config *n } dockerfile := new(bytes.Buffer) template.Must(template.New("").Parse(nodeDockerfile)).Execute(dockerfile, map[string]interface{}{ + "Version": config.version, "NetworkID": config.network, "Port": config.port, "Peers": config.peersTotal, @@ -165,6 +166,7 @@ type nodeInfos struct { gasTarget float64 gasLimit float64 gasPrice float64 + version string } // Report converts the typed struct into a plain string->string map, containing diff --git a/cmd/puppeth/wizard.go b/cmd/puppeth/wizard.go index b88a61de7d..bde538a0fa 100644 --- a/cmd/puppeth/wizard.go +++ b/cmd/puppeth/wizard.go @@ -25,6 +25,7 @@ import ( "net" "os" "path/filepath" + "regexp" "sort" "strconv" "strings" @@ -324,3 +325,31 @@ func (w *wizard) readIPAddress() string { return text } } + +// readDefaultAddress reads a single line from stdin, trimming if from spaces and +// converts it to either a version in the form "v1.8.15" or "latest". If an empty +// line is entered, the default value is returned. +func (w *wizard) readDefaultVersion(def string) string { + for { + fmt.Printf("> ") + text, err := w.in.ReadString('\n') + if err != nil { + log.Crit("Failed to read user input", "err", err) + } + if text = strings.TrimSpace(text); text == "" { + return def + } else if text == "latest" { + return text + } + + // Match something like 1.8.15 or 1.8.0 + regex := regexp.MustCompile("^\\d+\\.\\d+\\.\\d+$") + if !regex.Match([]byte(strings.TrimSpace(text))) { + log.Error("Invalid input, expected a semantic version in the form 1.8.15") + continue + } + + // Convert to v1.8.15 (the format used for the ethereum docker images) + return "v" + text + } +} diff --git a/cmd/puppeth/wizard_faucet.go b/cmd/puppeth/wizard_faucet.go index 6f08408947..af2bab9081 100644 --- a/cmd/puppeth/wizard_faucet.go +++ b/cmd/puppeth/wizard_faucet.go @@ -38,7 +38,7 @@ func (w *wizard) deployFaucet() { infos, err := checkFaucet(client, w.network) if err != nil { infos = &faucetInfos{ - node: &nodeInfos{port: 30303, peersTotal: 25}, + node: &nodeInfos{port: 30303, peersTotal: 25, version: "latest"}, port: 80, host: client.server, amount: 1, @@ -102,6 +102,11 @@ func (w *wizard) deployFaucet() { infos.captchaSecret = w.readPassword() } } + // Figure out which version of faucet to use + fmt.Println() + fmt.Printf("Which version of faucet to use? (default = %s)\n", infos.node.version) + infos.node.version = w.readDefaultVersion(infos.node.version) + // Figure out where the user wants to store the persistent data fmt.Println() if infos.node.datadir == "" { diff --git a/cmd/puppeth/wizard_node.go b/cmd/puppeth/wizard_node.go index 49b10a023a..17f531df64 100644 --- a/cmd/puppeth/wizard_node.go +++ b/cmd/puppeth/wizard_node.go @@ -55,9 +55,15 @@ func (w *wizard) deployNode(boot bool) { } existed := err == nil + infos.version = "latest" infos.genesis, _ = json.MarshalIndent(w.conf.Genesis, "", " ") infos.network = w.conf.Genesis.Config.ChainID.Int64() + // Figure out which version of geth to use + fmt.Println() + fmt.Printf("Which version of geth to use? (default = %s)\n", infos.version) + infos.version = w.readDefaultVersion(infos.version) + // Figure out where the user wants to store the persistent data fmt.Println() if infos.datadir == "" {