Skip to content

Commit

Permalink
Merge pull request #66 from renproject/release/3.0.10
Browse files Browse the repository at this point in the history
3.0.10
  • Loading branch information
Yunshi Sun committed May 25, 2020
2 parents ec9d579 + 9cc88f4 commit 1fbbbca
Show file tree
Hide file tree
Showing 12 changed files with 164 additions and 43 deletions.
71 changes: 71 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
## 3.0.10
- Improve `update` command to support suffix tags #61
- Show darknodes versions when from the `list` command.

## 3.0.9
- Update bootstrap node's multi-address

## 3.0.8
- Update the terraform version when installing the CLI.
- Update protocol contract addresses
- Support mainnet deployment

## 3.0.7
- Check existence of the Darknode when running commands which darknode name as parameter #55
- `up` command gets latest release from github, instead of ipfs.
- Remove auto-updater and modify the `update` command #56
- Make sure the CI script does not overwrite the previous release

## 3.0.6
Minor fix and improvement #52
- Fix concurrent writes issue when running `darknode list`
- Hide the error message when checking version against github.
- Ignore the `ECDSADistKeyShare` field when reading the config.

## 3.0.5
Issue #49
- Show messages when starting executing the script.

Issue #51
- Update config format to the latest version in darknode.
- Remove `--config` flag form the `update` command to avoid conflicts in the config file.
- Show messages to tell if nodes have successfully been started/stopped/restarted.
- Minor tweak with the darknode installation script.
- Fix incorrect bootstrap addresses on testnet and devnet.

## 3.0.4
- Add Google Cloud Platform support
Thanks to @Pega88 for contributing to this release

## 3.0.3
- Fix an issue which could cause fail deployment on digital ocean.
- Successful deployment on Windows(WSL) will automatically open the registering link.
- Hide the red error message when cannot find any command to open the registering link.

## 3.0.2
- set `DisablePeerDiscovery` to true when initializing a new darknode config.
- manually install the metrics agent for digital ocean to enable detail monitoring

## 3.0.1
- Build binary for `arm` architecture and include it in the release.
- Update bindings for darknode registry contract to the latest version.
- Not showing any error when failed to open registering url in a browser.
- Update prompt message to show the correct command when a new release is detected.

## 3.0.0

New CLI for Chaosnet darknodes deployment.

> Since the config format for darknode is changed and we move from terraform 0.11.x to 0.12.x. New cli will not be backwards compatible with old darknodes. Users need to deregister and destroy old nodes first before updating to this version.
Changelog:
- Windows support with WSL
- Use updated `terraform` version `v0.12.12`
- Release check before running any commands, it will warn users if they are using an old version.
- Support `start/stop/restart` commands to start/stop/restart the service on darknode.
- Add `exec` command which allow users to run script/file on remote instance.
- Add `register` command which shows the link to register a particular node and try opening it using the default browser.
- Show provider information when running `darknode list`
- `resize` command will not increase the disk size for digital ocean. (This allows users to downgrade their droplets after upgrading the plan)
- Detail monitoring is enabled for all providers.
- Code has been refactored to be self-contained
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
3.0.9
3.0.10
4 changes: 4 additions & 0 deletions cmd/flag.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,10 @@ var (
Name: "version",
Usage: "Version of darknode you want to upgrade to",
}
DowngradeFlag = cli.BoolFlag{
Name: "downgrade",
Usage: "Force downgrading to an older version without interactive prompts",
}
)

// AWS flags
Expand Down
7 changes: 4 additions & 3 deletions cmd/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,8 @@ func listAllNodes(ctx *cli.Context) error {
if err != nil {
return nil, err
}
return []string{name, id.String(), ip, provider, string(tags), ethAddr.Hex()}, nil
version := util.Version(name)
return []string{name, id.String(), ip, provider, string(tags), ethAddr.Hex(), version}, nil
}()
if err != nil {
color.Red("[%v] cannot get detail of the darknode, err = %v", name, err)
Expand All @@ -61,10 +62,10 @@ func listAllNodes(ctx *cli.Context) error {
return fmt.Errorf("cannot find any node")
}

fmt.Printf("%-20s | %-30s | %-15s | %-8s | %-15s | %-45s \n", "name", "id", "ip", "provider", "tags", "ethereum address")
fmt.Printf("%-20s | %-30s | %-15s | %-8s | %-15s | %-45s | %-15s\n", "name", "id", "ip", "provider", "tags", "ethereum address", "version")
for _, node := range nodes {
if node != nil {
fmt.Printf("%-20s | %-30s | %-15s | %-8s | %-15s | %-45s\n", node[0], node[1], node[2], node[3], node[4], node[5])
fmt.Printf("%-20s | %-30s | %-15s | %-8s | %-15s | %-45s | %-15s\n", node[0], node[1], node[2], node[3], node[4], node[5], node[6])
}
}
return nil
Expand Down
2 changes: 1 addition & 1 deletion cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ func main() {
{
Name: "update",
Usage: "Update your Darknodes to the latest software and configuration",
Flags: []cli.Flag{TagsFlag, VersionFlag},
Flags: []cli.Flag{TagsFlag, VersionFlag, DowngradeFlag},
Action: func(c *cli.Context) error {
return updateNode(c)
},
Expand Down
2 changes: 1 addition & 1 deletion cmd/provider/aws.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ func (p providerAws) Deploy(ctx *cli.Context) error {
name := ctx.String("name")
tags := ctx.String("tags")

latestVersion, err := util.LatestReleaseVersion()
latestVersion, err := util.LatestStableRelease()
if err != nil {
return err
}
Expand Down
2 changes: 1 addition & 1 deletion cmd/provider/do.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ func (p providerDo) Deploy(ctx *cli.Context) error {
name := ctx.String("name")
tags := ctx.String("tags")

latestVersion, err := util.LatestReleaseVersion()
latestVersion, err := util.LatestStableRelease()
if err != nil {
return err
}
Expand Down
2 changes: 1 addition & 1 deletion cmd/provider/gcp.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ func (p providerGcp) Deploy(ctx *cli.Context) error {
name := ctx.String("name")
tags := ctx.String("tags")

latestVersion, err := util.LatestReleaseVersion()
latestVersion, err := util.LatestStableRelease()
if err != nil {
return err
}
Expand Down
58 changes: 37 additions & 21 deletions cmd/update.go
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
package main

import (
"context"
"fmt"
"io/ioutil"
"net/http"
"strings"
"time"

"github.com/fatih/color"
"github.com/google/go-github/v31/github"
"github.com/hashicorp/go-version"
"github.com/renproject/darknode-cli/util"
"github.com/renproject/phi"
Expand All @@ -18,6 +21,7 @@ import (
func updateNode(ctx *cli.Context) error {
name := ctx.Args().First()
tags := ctx.String("tags")
force := ctx.Bool("downgrade")
version := strings.TrimSpace(ctx.String("version"))
nodes, err := util.ParseNodesFromNameAndTags(name, tags)
if err != nil {
Expand All @@ -26,11 +30,12 @@ func updateNode(ctx *cli.Context) error {

// Use latest version if user doesn't provide a version number
if version == "" {
version, err = util.LatestReleaseVersion()
version, err = util.LatestStableRelease()
if err != nil {
return err
}
}

// Check if the target release exists on github
color.Green("Verifying darknode release ...")
if err := validateVersion(version); err != nil {
Expand All @@ -40,13 +45,13 @@ func updateNode(ctx *cli.Context) error {
color.Green("Updating darknodes...")
errs := make([]error, len(nodes))
phi.ParForAll(nodes, func(i int) {
errs[i] = updateSingleNode(nodes[i], version)
errs[i] = updateSingleNode(nodes[i], version, force)
})
return util.HandleErrs(errs)
}

func updateSingleNode(name, ver string) error {
v, _ := util.Version(name)
func updateSingleNode(name, ver string, force bool) error {
v := util.Version(name)
curVersion, err := version.NewVersion(strings.TrimSpace(v))
if err != nil {
return err
Expand All @@ -57,34 +62,45 @@ func updateSingleNode(name, ver string) error {
case 0:
color.Green("darknode [%v] is running version [%v] already.", name, ver)
case 1:
color.Red("darknode [%v] is running with version %v, you cannot downgrade to a lower version %v", name, curVersion.String(), newVersion.String())
if !force {
color.Red("darknode [%v] is running with version %v, you cannot downgrade to a lower version %v", name, curVersion.String(), newVersion.String())
return nil
}
if err := update(name, ver); err != nil {
color.Red("cannot downgrade darknode %v, error = %v", name, err)
} else {
color.Green("[%s] has been downgraded to version %v", name, ver)
}
default:
url := fmt.Sprintf("https://github.com/renproject/darknode-release/releases/download/%v", ver)
script := fmt.Sprintf(`mv ~/.darknode/bin/darknode ~/.darknode/bin/darknode-backup &&
if err := update(name, ver); err != nil {
color.Red("cannot update darknode %v, error = %v", name, err)
} else {
color.Green("[%s] has been updated to version %v", name, ver)
}
}
return nil
}

func update(name, ver string) error {
url := fmt.Sprintf("https://github.com/renproject/darknode-release/releases/download/%v", ver)
script := fmt.Sprintf(`mv ~/.darknode/bin/darknode ~/.darknode/bin/darknode-backup &&
curl -sL %v/darknode > ~/.darknode/bin/darknode &&
curl -sL %v/migration > ~/.darknode/bin/migration &&
chmod +x ~/.darknode/bin/darknode &&
chmod +x ~/.darknode/bin/migration &&
systemctl --user stop darknode &&
cp -a ~/.darknode/db/. ~/.darknode/db_bak/ &&
~/.darknode/bin/migration &&
rm -rf ~/.darknode/db &&
mv ~/.darknode/db_bak ~/.darknode/db &&
echo %v > ~/.darknode/version &&
systemctl --user restart darknode`, url, url, ver)
err = util.RemoteRun(name, script)
if err != nil {
color.Red("cannot update darknode %v, error = %v", name, err)
} else {
color.Green("[%s] has been updated to version %v", name, ver)
}
}
return nil
systemctl --user restart darknode`, url, ver)
return util.RemoteRun(name, script)
}

func validateVersion(version string) error {
url := fmt.Sprintf("https://api.github.com/repos/renproject/darknode-release/releases/tags/%v", version)
response, err := http.Get(url)
ctx, cancel := context.WithTimeout(context.Background(), 5 *time.Second)
defer cancel()

client := github.NewClient(nil)
_, response, err := client.Repositories.GetReleaseByTag(ctx, "renproject", "darknode-release", version)
if err != nil {
return err
}
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ require (
github.com/ethereum/go-ethereum v1.9.6
github.com/fatih/color v1.7.0
github.com/google/go-github v17.0.0+incompatible
github.com/google/go-querystring v1.0.0 // indirect
github.com/google/go-github/v31 v31.0.0
github.com/hashicorp/go-version v1.2.0
github.com/jbenet/go-base58 v0.0.0-20150317085156-6237cf65f3a6
github.com/multiformats/go-multiaddr v0.1.1
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,8 @@ github.com/google/go-cmp v0.3.1 h1:Xye71clBPdm5HgqGwUkwhbynsUJZhDbS20FvLhQ2izg=
github.com/google/go-cmp v0.3.1/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU=
github.com/google/go-github v17.0.0+incompatible h1:N0LgJ1j65A7kfXrZnUDaYCs/Sf4rEjNlfyDHW9dolSY=
github.com/google/go-github v17.0.0+incompatible/go.mod h1:zLgOLi98H3fifZn+44m+umXrS52loVEgC2AApnigrVQ=
github.com/google/go-github/v31 v31.0.0 h1:JJUxlP9lFK+ziXKimTCprajMApV1ecWD4NB6CCb0plo=
github.com/google/go-github/v31 v31.0.0/go.mod h1:NQPZol8/1sMoWYGN2yaALIBytu17gAWfhbweiEed3pM=
github.com/google/go-querystring v1.0.0 h1:Xkwi/a1rcvNg1PPYe5vI8GbeBY/jrVuDX5ASuANWTrk=
github.com/google/go-querystring v1.0.0/go.mod h1:odCYkC5MyYFN7vkCjXpyrEuKhc/BUO6wN/zVPAxq5ck=
github.com/google/martian v2.1.0+incompatible/go.mod h1:9I4somxYTbIHy5NJKHRl3wXiIaQGbYVAs8BPL6v8lEs=
Expand Down
53 changes: 40 additions & 13 deletions util/node.go
Original file line number Diff line number Diff line change
@@ -1,15 +1,19 @@
package util

import (
"context"
"encoding/hex"
"encoding/json"
"errors"
"fmt"
"io/ioutil"
"net/http"
"path/filepath"
"regexp"
"strings"
"time"

"github.com/google/go-github/v31/github"
"github.com/hashicorp/go-version"
"github.com/renproject/darknode-cli/darknode"
"github.com/renproject/darknode-cli/darknode/addr"
"golang.org/x/crypto/ssh"
Expand Down Expand Up @@ -82,13 +86,13 @@ func IP(name string) (string, error) {
}

// Version gets the version of the software the darknode currently is running.
func Version(name string) (string, error) {
func Version(name string) string {
script := "cat ~/.darknode/version"
version, err := RemoteOutput(name, script)
if err != nil {
return "0.0.0", err
return "unknown"
}
return string(version), nil
return strings.TrimSpace(string(version))
}

// Network gets the network of the darknode.
Expand Down Expand Up @@ -160,23 +164,46 @@ func ValidateTags(have, required string) bool {
return true
}

// LatestReleaseVersion checks the darknode release repo and return the version
// LatestStableRelease checks the darknode release repo and return the version
// of the latest release.
func LatestReleaseVersion() (string, error) {
url := "https://api.github.com/repos/renproject/darknode-release/releases/latest"
response, err := http.Get(url)
func LatestStableRelease() (string, error) {
ctx, cancel := context.WithTimeout(context.Background(), 5 *time.Second)
defer cancel()

client := github.NewClient(nil)
releases, response, err := client.Repositories.ListReleases(ctx, "renproject", "darknode-release", nil)
if err != nil {
return "", err
}
if response.StatusCode != http.StatusOK {
return "", fmt.Errorf("cannot get latest darknode release from github, error code = %v", response.StatusCode)
}

resp := struct {
TagName string `json:"tag_name"`
}{}
err = json.NewDecoder(response.Body).Decode(&resp)
return resp.TagName, err
latest, err := version.NewVersion("0.0.0")
if err != nil {
return "", err
}
verReg := "^v?[0-9]+\\.[0-9]+\\.[0-9]+$"
for _, release := range releases {
match, err := regexp.MatchString(verReg, *release.TagName)
if err != nil {
return "", err
}
if match {
ver, err := version.NewVersion(*release.TagName)
if err != nil {
return "", err
}
if ver.GreaterThan(latest) {
latest = ver
}
}
}
if latest.String() == "0.0.0" {
return "", errors.New("cannot find any stable release")
}

return latest.String(), nil
}

func isDeployed(name string) bool {
Expand Down

0 comments on commit 1fbbbca

Please sign in to comment.