Skip to content

Commit 1fbbbca

Browse files
author
Yunshi Sun
authored
Merge pull request #66 from renproject/release/3.0.10
3.0.10
2 parents ec9d579 + 9cc88f4 commit 1fbbbca

File tree

12 files changed

+164
-43
lines changed

12 files changed

+164
-43
lines changed

CHANGELOG.md

+71
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
## 3.0.10
2+
- Improve `update` command to support suffix tags #61
3+
- Show darknodes versions when from the `list` command.
4+
5+
## 3.0.9
6+
- Update bootstrap node's multi-address
7+
8+
## 3.0.8
9+
- Update the terraform version when installing the CLI.
10+
- Update protocol contract addresses
11+
- Support mainnet deployment
12+
13+
## 3.0.7
14+
- Check existence of the Darknode when running commands which darknode name as parameter #55
15+
- `up` command gets latest release from github, instead of ipfs.
16+
- Remove auto-updater and modify the `update` command #56
17+
- Make sure the CI script does not overwrite the previous release
18+
19+
## 3.0.6
20+
Minor fix and improvement #52
21+
- Fix concurrent writes issue when running `darknode list`
22+
- Hide the error message when checking version against github.
23+
- Ignore the `ECDSADistKeyShare` field when reading the config.
24+
25+
## 3.0.5
26+
Issue #49
27+
- Show messages when starting executing the script.
28+
29+
Issue #51
30+
- Update config format to the latest version in darknode.
31+
- Remove `--config` flag form the `update` command to avoid conflicts in the config file.
32+
- Show messages to tell if nodes have successfully been started/stopped/restarted.
33+
- Minor tweak with the darknode installation script.
34+
- Fix incorrect bootstrap addresses on testnet and devnet.
35+
36+
## 3.0.4
37+
- Add Google Cloud Platform support
38+
Thanks to @Pega88 for contributing to this release
39+
40+
## 3.0.3
41+
- Fix an issue which could cause fail deployment on digital ocean.
42+
- Successful deployment on Windows(WSL) will automatically open the registering link.
43+
- Hide the red error message when cannot find any command to open the registering link.
44+
45+
## 3.0.2
46+
- set `DisablePeerDiscovery` to true when initializing a new darknode config.
47+
- manually install the metrics agent for digital ocean to enable detail monitoring
48+
49+
## 3.0.1
50+
- Build binary for `arm` architecture and include it in the release.
51+
- Update bindings for darknode registry contract to the latest version.
52+
- Not showing any error when failed to open registering url in a browser.
53+
- Update prompt message to show the correct command when a new release is detected.
54+
55+
## 3.0.0
56+
57+
New CLI for Chaosnet darknodes deployment.
58+
59+
> 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.
60+
61+
Changelog:
62+
- Windows support with WSL
63+
- Use updated `terraform` version `v0.12.12`
64+
- Release check before running any commands, it will warn users if they are using an old version.
65+
- Support `start/stop/restart` commands to start/stop/restart the service on darknode.
66+
- Add `exec` command which allow users to run script/file on remote instance.
67+
- Add `register` command which shows the link to register a particular node and try opening it using the default browser.
68+
- Show provider information when running `darknode list`
69+
- `resize` command will not increase the disk size for digital ocean. (This allows users to downgrade their droplets after upgrading the plan)
70+
- Detail monitoring is enabled for all providers.
71+
- Code has been refactored to be self-contained

VERSION

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
3.0.9
1+
3.0.10

cmd/flag.go

+4
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,10 @@ var (
4040
Name: "version",
4141
Usage: "Version of darknode you want to upgrade to",
4242
}
43+
DowngradeFlag = cli.BoolFlag{
44+
Name: "downgrade",
45+
Usage: "Force downgrading to an older version without interactive prompts",
46+
}
4347
)
4448

4549
// AWS flags

cmd/list.go

+4-3
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,8 @@ func listAllNodes(ctx *cli.Context) error {
4848
if err != nil {
4949
return nil, err
5050
}
51-
return []string{name, id.String(), ip, provider, string(tags), ethAddr.Hex()}, nil
51+
version := util.Version(name)
52+
return []string{name, id.String(), ip, provider, string(tags), ethAddr.Hex(), version}, nil
5253
}()
5354
if err != nil {
5455
color.Red("[%v] cannot get detail of the darknode, err = %v", name, err)
@@ -61,10 +62,10 @@ func listAllNodes(ctx *cli.Context) error {
6162
return fmt.Errorf("cannot find any node")
6263
}
6364

64-
fmt.Printf("%-20s | %-30s | %-15s | %-8s | %-15s | %-45s \n", "name", "id", "ip", "provider", "tags", "ethereum address")
65+
fmt.Printf("%-20s | %-30s | %-15s | %-8s | %-15s | %-45s | %-15s\n", "name", "id", "ip", "provider", "tags", "ethereum address", "version")
6566
for _, node := range nodes {
6667
if node != nil {
67-
fmt.Printf("%-20s | %-30s | %-15s | %-8s | %-15s | %-45s\n", node[0], node[1], node[2], node[3], node[4], node[5])
68+
fmt.Printf("%-20s | %-30s | %-15s | %-8s | %-15s | %-45s | %-15s\n", node[0], node[1], node[2], node[3], node[4], node[5], node[6])
6869
}
6970
}
7071
return nil

cmd/main.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ func main() {
6868
{
6969
Name: "update",
7070
Usage: "Update your Darknodes to the latest software and configuration",
71-
Flags: []cli.Flag{TagsFlag, VersionFlag},
71+
Flags: []cli.Flag{TagsFlag, VersionFlag, DowngradeFlag},
7272
Action: func(c *cli.Context) error {
7373
return updateNode(c)
7474
},

cmd/provider/aws.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ func (p providerAws) Deploy(ctx *cli.Context) error {
6767
name := ctx.String("name")
6868
tags := ctx.String("tags")
6969

70-
latestVersion, err := util.LatestReleaseVersion()
70+
latestVersion, err := util.LatestStableRelease()
7171
if err != nil {
7272
return err
7373
}

cmd/provider/do.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ func (p providerDo) Deploy(ctx *cli.Context) error {
3333
name := ctx.String("name")
3434
tags := ctx.String("tags")
3535

36-
latestVersion, err := util.LatestReleaseVersion()
36+
latestVersion, err := util.LatestStableRelease()
3737
if err != nil {
3838
return err
3939
}

cmd/provider/gcp.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ func (p providerGcp) Deploy(ctx *cli.Context) error {
7171
name := ctx.String("name")
7272
tags := ctx.String("tags")
7373

74-
latestVersion, err := util.LatestReleaseVersion()
74+
latestVersion, err := util.LatestStableRelease()
7575
if err != nil {
7676
return err
7777
}

cmd/update.go

+37-21
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,15 @@
11
package main
22

33
import (
4+
"context"
45
"fmt"
56
"io/ioutil"
67
"net/http"
78
"strings"
9+
"time"
810

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

2731
// Use latest version if user doesn't provide a version number
2832
if version == "" {
29-
version, err = util.LatestReleaseVersion()
33+
version, err = util.LatestStableRelease()
3034
if err != nil {
3135
return err
3236
}
3337
}
38+
3439
// Check if the target release exists on github
3540
color.Green("Verifying darknode release ...")
3641
if err := validateVersion(version); err != nil {
@@ -40,13 +45,13 @@ func updateNode(ctx *cli.Context) error {
4045
color.Green("Updating darknodes...")
4146
errs := make([]error, len(nodes))
4247
phi.ParForAll(nodes, func(i int) {
43-
errs[i] = updateSingleNode(nodes[i], version)
48+
errs[i] = updateSingleNode(nodes[i], version, force)
4449
})
4550
return util.HandleErrs(errs)
4651
}
4752

48-
func updateSingleNode(name, ver string) error {
49-
v, _ := util.Version(name)
53+
func updateSingleNode(name, ver string, force bool) error {
54+
v := util.Version(name)
5055
curVersion, err := version.NewVersion(strings.TrimSpace(v))
5156
if err != nil {
5257
return err
@@ -57,34 +62,45 @@ func updateSingleNode(name, ver string) error {
5762
case 0:
5863
color.Green("darknode [%v] is running version [%v] already.", name, ver)
5964
case 1:
60-
color.Red("darknode [%v] is running with version %v, you cannot downgrade to a lower version %v", name, curVersion.String(), newVersion.String())
65+
if !force {
66+
color.Red("darknode [%v] is running with version %v, you cannot downgrade to a lower version %v", name, curVersion.String(), newVersion.String())
67+
return nil
68+
}
69+
if err := update(name, ver); err != nil {
70+
color.Red("cannot downgrade darknode %v, error = %v", name, err)
71+
} else {
72+
color.Green("[%s] has been downgraded to version %v", name, ver)
73+
}
6174
default:
62-
url := fmt.Sprintf("https://github.com/renproject/darknode-release/releases/download/%v", ver)
63-
script := fmt.Sprintf(`mv ~/.darknode/bin/darknode ~/.darknode/bin/darknode-backup &&
75+
if err := update(name, ver); err != nil {
76+
color.Red("cannot update darknode %v, error = %v", name, err)
77+
} else {
78+
color.Green("[%s] has been updated to version %v", name, ver)
79+
}
80+
}
81+
return nil
82+
}
83+
84+
func update(name, ver string) error {
85+
url := fmt.Sprintf("https://github.com/renproject/darknode-release/releases/download/%v", ver)
86+
script := fmt.Sprintf(`mv ~/.darknode/bin/darknode ~/.darknode/bin/darknode-backup &&
6487
curl -sL %v/darknode > ~/.darknode/bin/darknode &&
65-
curl -sL %v/migration > ~/.darknode/bin/migration &&
6688
chmod +x ~/.darknode/bin/darknode &&
67-
chmod +x ~/.darknode/bin/migration &&
6889
systemctl --user stop darknode &&
6990
cp -a ~/.darknode/db/. ~/.darknode/db_bak/ &&
70-
~/.darknode/bin/migration &&
7191
rm -rf ~/.darknode/db &&
7292
mv ~/.darknode/db_bak ~/.darknode/db &&
7393
echo %v > ~/.darknode/version &&
74-
systemctl --user restart darknode`, url, url, ver)
75-
err = util.RemoteRun(name, script)
76-
if err != nil {
77-
color.Red("cannot update darknode %v, error = %v", name, err)
78-
} else {
79-
color.Green("[%s] has been updated to version %v", name, ver)
80-
}
81-
}
82-
return nil
94+
systemctl --user restart darknode`, url, ver)
95+
return util.RemoteRun(name, script)
8396
}
8497

8598
func validateVersion(version string) error {
86-
url := fmt.Sprintf("https://api.github.com/repos/renproject/darknode-release/releases/tags/%v", version)
87-
response, err := http.Get(url)
99+
ctx, cancel := context.WithTimeout(context.Background(), 5 *time.Second)
100+
defer cancel()
101+
102+
client := github.NewClient(nil)
103+
_, response, err := client.Repositories.GetReleaseByTag(ctx, "renproject", "darknode-release", version)
88104
if err != nil {
89105
return err
90106
}

go.mod

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ require (
88
github.com/ethereum/go-ethereum v1.9.6
99
github.com/fatih/color v1.7.0
1010
github.com/google/go-github v17.0.0+incompatible
11-
github.com/google/go-querystring v1.0.0 // indirect
11+
github.com/google/go-github/v31 v31.0.0
1212
github.com/hashicorp/go-version v1.2.0
1313
github.com/jbenet/go-base58 v0.0.0-20150317085156-6237cf65f3a6
1414
github.com/multiformats/go-multiaddr v0.1.1

go.sum

+2
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,8 @@ github.com/google/go-cmp v0.3.1 h1:Xye71clBPdm5HgqGwUkwhbynsUJZhDbS20FvLhQ2izg=
112112
github.com/google/go-cmp v0.3.1/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU=
113113
github.com/google/go-github v17.0.0+incompatible h1:N0LgJ1j65A7kfXrZnUDaYCs/Sf4rEjNlfyDHW9dolSY=
114114
github.com/google/go-github v17.0.0+incompatible/go.mod h1:zLgOLi98H3fifZn+44m+umXrS52loVEgC2AApnigrVQ=
115+
github.com/google/go-github/v31 v31.0.0 h1:JJUxlP9lFK+ziXKimTCprajMApV1ecWD4NB6CCb0plo=
116+
github.com/google/go-github/v31 v31.0.0/go.mod h1:NQPZol8/1sMoWYGN2yaALIBytu17gAWfhbweiEed3pM=
115117
github.com/google/go-querystring v1.0.0 h1:Xkwi/a1rcvNg1PPYe5vI8GbeBY/jrVuDX5ASuANWTrk=
116118
github.com/google/go-querystring v1.0.0/go.mod h1:odCYkC5MyYFN7vkCjXpyrEuKhc/BUO6wN/zVPAxq5ck=
117119
github.com/google/martian v2.1.0+incompatible/go.mod h1:9I4somxYTbIHy5NJKHRl3wXiIaQGbYVAs8BPL6v8lEs=

util/node.go

+40-13
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,19 @@
11
package util
22

33
import (
4+
"context"
45
"encoding/hex"
5-
"encoding/json"
66
"errors"
77
"fmt"
88
"io/ioutil"
99
"net/http"
1010
"path/filepath"
11+
"regexp"
1112
"strings"
13+
"time"
1214

15+
"github.com/google/go-github/v31/github"
16+
"github.com/hashicorp/go-version"
1317
"github.com/renproject/darknode-cli/darknode"
1418
"github.com/renproject/darknode-cli/darknode/addr"
1519
"golang.org/x/crypto/ssh"
@@ -82,13 +86,13 @@ func IP(name string) (string, error) {
8286
}
8387

8488
// Version gets the version of the software the darknode currently is running.
85-
func Version(name string) (string, error) {
89+
func Version(name string) string {
8690
script := "cat ~/.darknode/version"
8791
version, err := RemoteOutput(name, script)
8892
if err != nil {
89-
return "0.0.0", err
93+
return "unknown"
9094
}
91-
return string(version), nil
95+
return strings.TrimSpace(string(version))
9296
}
9397

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

163-
// LatestReleaseVersion checks the darknode release repo and return the version
167+
// LatestStableRelease checks the darknode release repo and return the version
164168
// of the latest release.
165-
func LatestReleaseVersion() (string, error) {
166-
url := "https://api.github.com/repos/renproject/darknode-release/releases/latest"
167-
response, err := http.Get(url)
169+
func LatestStableRelease() (string, error) {
170+
ctx, cancel := context.WithTimeout(context.Background(), 5 *time.Second)
171+
defer cancel()
172+
173+
client := github.NewClient(nil)
174+
releases, response, err := client.Repositories.ListReleases(ctx, "renproject", "darknode-release", nil)
168175
if err != nil {
169176
return "", err
170177
}
171178
if response.StatusCode != http.StatusOK {
172179
return "", fmt.Errorf("cannot get latest darknode release from github, error code = %v", response.StatusCode)
173180
}
174181

175-
resp := struct {
176-
TagName string `json:"tag_name"`
177-
}{}
178-
err = json.NewDecoder(response.Body).Decode(&resp)
179-
return resp.TagName, err
182+
latest, err := version.NewVersion("0.0.0")
183+
if err != nil {
184+
return "", err
185+
}
186+
verReg := "^v?[0-9]+\\.[0-9]+\\.[0-9]+$"
187+
for _, release := range releases {
188+
match, err := regexp.MatchString(verReg, *release.TagName)
189+
if err != nil {
190+
return "", err
191+
}
192+
if match {
193+
ver, err := version.NewVersion(*release.TagName)
194+
if err != nil {
195+
return "", err
196+
}
197+
if ver.GreaterThan(latest) {
198+
latest = ver
199+
}
200+
}
201+
}
202+
if latest.String() == "0.0.0" {
203+
return "", errors.New("cannot find any stable release")
204+
}
205+
206+
return latest.String(), nil
180207
}
181208

182209
func isDeployed(name string) bool {

0 commit comments

Comments
 (0)