Skip to content

Commit 7438caf

Browse files
author
tok-kkk
committed
modify the update command
1 parent 9845393 commit 7438caf

13 files changed

Lines changed: 295 additions & 249 deletions

File tree

cmd/main.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ import (
1717
)
1818

1919
// This will be populated on build
20-
var binaryVersion = "undefined"
20+
var binaryVersion = "3.0.7"
2121

2222
func init() {
2323
rand.Seed(time.Now().UTC().UnixNano())

cmd/provider/aws.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,10 @@ func (p providerAws) Deploy(ctx *cli.Context) error {
6767
name := ctx.String("name")
6868
tags := ctx.String("tags")
6969

70+
latestVersion, err := util.LatestReleaseVersion()
71+
if err != nil {
72+
return err
73+
}
7074
region, instance, err := p.validateRegionAndInstance(ctx)
7175
if err != nil {
7276
return err
@@ -82,7 +86,7 @@ func (p providerAws) Deploy(ctx *cli.Context) error {
8286
}
8387

8488
// Generate terraform config and start deploying
85-
if err := p.tfConfig(name, region, instance, ipfsUrl(network)); err != nil {
89+
if err := p.tfConfig(name, region, instance, latestVersion); err != nil {
8690
return err
8791
}
8892
if err := runTerraform(name); err != nil {

cmd/provider/aws_template.go

Lines changed: 34 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -10,29 +10,31 @@ import (
1010
)
1111

1212
type awsTerraform struct {
13-
Name string
14-
Region string
15-
InstanceType string
16-
ConfigPath string
17-
PubKeyPath string
18-
PriKeyPath string
19-
AccessKey string
20-
SecretKey string
21-
IPFS string
13+
Name string
14+
Region string
15+
InstanceType string
16+
ConfigPath string
17+
PubKeyPath string
18+
PriKeyPath string
19+
AccessKey string
20+
SecretKey string
21+
ServiceFile string
22+
LatestVersion string
2223
}
2324

2425
// tfConfig generates the terraform config file for deploying to AWS.
25-
func (p providerAws) tfConfig(name, region, instance, ipfs string) error {
26+
func (p providerAws) tfConfig(name, region, instance, latestVersion string) error {
2627
tf := awsTerraform{
27-
Name: name,
28-
Region: region,
29-
InstanceType: instance,
30-
ConfigPath: fmt.Sprintf("~/.darknode/darknodes/%v/config.json", name),
31-
PubKeyPath: fmt.Sprintf("~/.darknode/darknodes/%v/ssh_keypair.pub", name),
32-
PriKeyPath: fmt.Sprintf("~/.darknode/darknodes/%v/ssh_keypair", name),
33-
AccessKey: p.accessKey,
34-
SecretKey: p.secretKey,
35-
IPFS: ipfs,
28+
Name: name,
29+
Region: region,
30+
InstanceType: instance,
31+
ConfigPath: fmt.Sprintf("~/.darknode/darknodes/%v/config.json", name),
32+
PubKeyPath: fmt.Sprintf("~/.darknode/darknodes/%v/ssh_keypair.pub", name),
33+
PriKeyPath: fmt.Sprintf("~/.darknode/darknodes/%v/ssh_keypair", name),
34+
AccessKey: p.accessKey,
35+
SecretKey: p.secretKey,
36+
ServiceFile: darknodeService,
37+
LatestVersion: latestVersion,
3638
}
3739

3840
t, err := template.New("aws").Parse(awsTemplate)
@@ -156,12 +158,20 @@ resource "aws_instance" "darknode" {
156158
provisioner "remote-exec" {
157159
158160
inline = [
159-
"wget -O darknode.gz {{.IPFS}}",
160-
"tar -zxvf darknode.gz",
161-
"mkdir -p $HOME/.darknode",
161+
"set -x",
162+
"mkdir -p $HOME/.darknode/bin",
163+
"mkdir -p $HOME/.config/systemd/user",
162164
"mv $HOME/config.json $HOME/.darknode/config.json",
163-
"./install.sh",
164-
"rm -r darknode.gz bin config install.sh",
165+
"curl -sL https://www.github.com/renproject/darknode-release/releases/latest/download/darknode > ~/.darknode/bin/darknode",
166+
"chmod +x ~/.darknode/bin/darknode",
167+
"echo {{.LatestVersion}} > ~/.darknode/version.md",
168+
<<EOT
169+
echo "{{.ServiceFile}}" > ~/.config/systemd/user/darknode.service
170+
EOT
171+
,
172+
"loginctl enable-linger darknode",
173+
"systemctl --user enable darknode.service",
174+
"systemctl --user start darknode.service",
165175
]
166176
167177
connection {

cmd/provider/do.go

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

36+
latestVersion, err := util.LatestReleaseVersion()
37+
if err != nil {
38+
return err
39+
}
3640
region, droplet, err := validateRegionAndDroplet(ctx)
3741
if err != nil {
3842
return err
3943
}
44+
45+
// Initialization
4046
network, err := darknode.NewNetwork(ctx.String("network"))
4147
if err != nil {
4248
return err
@@ -46,7 +52,7 @@ func (p providerDo) Deploy(ctx *cli.Context) error {
4652
}
4753

4854
// Generate terraform config and start deploying
49-
if err := p.tfConfig(name, region, droplet, ipfsUrl(network)); err != nil {
55+
if err := p.tfConfig(name, region, droplet, latestVersion); err != nil {
5056
return err
5157
}
5258
if err := runTerraform(name); err != nil {

cmd/provider/do_template.go

Lines changed: 32 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -10,26 +10,28 @@ import (
1010
)
1111

1212
type doTerraform struct {
13-
Name string
14-
Token string
15-
Region string
16-
Size string
17-
ConfigPath string
18-
PubKeyPath string
19-
PriKeyPath string
20-
IPFS string
13+
Name string
14+
Token string
15+
Region string
16+
Size string
17+
ConfigPath string
18+
PubKeyPath string
19+
PriKeyPath string
20+
ServiceFile string
21+
LatestVersion string
2122
}
2223

23-
func (p providerDo) tfConfig(name, region, droplet, ipfs string) error {
24+
func (p providerDo) tfConfig(name, region, droplet, latestVersion string) error {
2425
tf := doTerraform{
25-
Name: name,
26-
Token: p.token,
27-
Region: region,
28-
Size: droplet,
29-
ConfigPath: fmt.Sprintf("~/.darknode/darknodes/%v/config.json", name),
30-
PubKeyPath: fmt.Sprintf("~/.darknode/darknodes/%v/ssh_keypair.pub", name),
31-
PriKeyPath: fmt.Sprintf("~/.darknode/darknodes/%v/ssh_keypair", name),
32-
IPFS: ipfs,
26+
Name: name,
27+
Token: p.token,
28+
Region: region,
29+
Size: droplet,
30+
ConfigPath: fmt.Sprintf("~/.darknode/darknodes/%v/config.json", name),
31+
PubKeyPath: fmt.Sprintf("~/.darknode/darknodes/%v/ssh_keypair.pub", name),
32+
PriKeyPath: fmt.Sprintf("~/.darknode/darknodes/%v/ssh_keypair", name),
33+
ServiceFile: darknodeService,
34+
LatestVersion: latestVersion,
3335
}
3436

3537
t, err := template.New("do").Parse(doTemplate)
@@ -107,12 +109,20 @@ resource "digitalocean_droplet" "darknode" {
107109
provisioner "remote-exec" {
108110
109111
inline = [
110-
"wget -O darknode.gz {{.IPFS}}",
111-
"tar -zxvf darknode.gz",
112-
"mkdir -p $HOME/.darknode",
112+
"set -x",
113+
"mkdir -p $HOME/.darknode/bin",
114+
"mkdir -p $HOME/.config/systemd/user",
113115
"mv $HOME/config.json $HOME/.darknode/config.json",
114-
"./install.sh",
115-
"rm -r darknode.gz bin config install.sh",
116+
"curl -sL https://www.github.com/renproject/darknode-release/releases/latest/download/darknode > ~/.darknode/bin/darknode",
117+
"chmod +x ~/.darknode/bin/darknode",
118+
"echo {{.LatestVersion}} > ~/.darknode/version.md",
119+
<<EOT
120+
echo "{{.ServiceFile}}" > ~/.config/systemd/user/darknode.service
121+
EOT
122+
,
123+
"loginctl enable-linger darknode",
124+
"systemctl --user enable darknode.service",
125+
"systemctl --user start darknode.service",
116126
]
117127
118128
connection {

cmd/provider/gcp.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import (
1111
"time"
1212

1313
"github.com/renproject/darknode-cli/darknode"
14+
"github.com/renproject/darknode-cli/util"
1415
"github.com/urfave/cli"
1516
"golang.org/x/oauth2/google"
1617
"google.golang.org/api/cloudresourcemanager/v1"
@@ -70,6 +71,10 @@ func (p providerGcp) Deploy(ctx *cli.Context) error {
7071
name := ctx.String("name")
7172
tags := ctx.String("tags")
7273

74+
latestVersion, err := util.LatestReleaseVersion()
75+
if err != nil {
76+
return err
77+
}
7378
projectID, err := p.projectID()
7479
if err != nil {
7580
return err
@@ -89,7 +94,7 @@ func (p providerGcp) Deploy(ctx *cli.Context) error {
8994
}
9095

9196
// Generate terraform config and start deploying
92-
if err := p.tfConfig(name, projectID, zone, machine, ipfsUrl(network)); err != nil {
97+
if err := p.tfConfig(name, projectID, zone, machine, latestVersion); err != nil {
9398
return err
9499
}
95100
if err := runTerraform(name); err != nil {

cmd/provider/gcp_template.go

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,11 @@ type gcpTerraform struct {
1818
ConfigPath string
1919
PubKeyPath string
2020
PriKeyPath string
21-
IPFS string
21+
ServiceFile string
22+
LatestVersion string
2223
}
2324

24-
func (p providerGcp) tfConfig(name, project, zone, machine, ipfs string) error {
25+
func (p providerGcp) tfConfig(name, project, zone, machine, latestVersion string) error {
2526
tf := gcpTerraform{
2627
Name: name,
2728
CredentialFile: p.credFile,
@@ -31,7 +32,8 @@ func (p providerGcp) tfConfig(name, project, zone, machine, ipfs string) error {
3132
ConfigPath: fmt.Sprintf("~/.darknode/darknodes/%v/config.json", name),
3233
PubKeyPath: fmt.Sprintf("~/.darknode/darknodes/%v/ssh_keypair.pub", name),
3334
PriKeyPath: fmt.Sprintf("~/.darknode/darknodes/%v/ssh_keypair", name),
34-
IPFS: ipfs,
35+
ServiceFile: darknodeService,
36+
LatestVersion: latestVersion,
3537
}
3638

3739
t, err := template.New("gcp").Parse(gcpTemplate)
@@ -153,12 +155,20 @@ resource "google_compute_instance" "darknode" {
153155
provisioner "remote-exec" {
154156
155157
inline = [
156-
"wget -O darknode.gz {{.IPFS}}",
157-
"tar -zxvf darknode.gz",
158-
"mkdir -p $HOME/.darknode",
158+
"set -x",
159+
"mkdir -p $HOME/.darknode/bin",
160+
"mkdir -p $HOME/.config/systemd/user",
159161
"mv $HOME/config.json $HOME/.darknode/config.json",
160-
"./install.sh",
161-
"rm -r darknode.gz bin config install.sh",
162+
"curl -sL https://www.github.com/renproject/darknode-release/releases/latest/download/darknode > ~/.darknode/bin/darknode",
163+
"chmod +x ~/.darknode/bin/darknode",
164+
"echo {{.LatestVersion}} > ~/.darknode/version.md",
165+
<<EOT
166+
echo "{{.ServiceFile}}" > ~/.config/systemd/user/darknode.service
167+
EOT
168+
,
169+
"loginctl enable-linger darknode",
170+
"systemctl --user enable darknode.service",
171+
"systemctl --user start darknode.service",
162172
]
163173
164174
connection {

cmd/provider/provider.go

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,24 @@ var (
3232
NameGcp = "gcp"
3333
)
3434

35+
var darknodeService = `[Unit]
36+
Description=Republic Protocol's Darknode Daemon
37+
AssertPathExists=$HOME/.darknode
38+
39+
[Service]
40+
WorkingDirectory=$HOME/.darknode
41+
ExecStart=$HOME/.darknode/bin/darknode --config $HOME/.darknode/config.json
42+
Restart=on-failure
43+
PrivateTmp=true
44+
NoNewPrivileges=true
45+
46+
# Specifies which signal to use when killing a service. Defaults to SIGTERM.
47+
# SIGHUP gives parity time to exit cleanly before SIGKILL (default 90s)
48+
KillSignal=SIGHUP
49+
50+
[Install]
51+
WantedBy=default.target`
52+
3553
type Provider interface {
3654
Name() string
3755
Deploy(ctx *cli.Context) error

0 commit comments

Comments
 (0)