-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
99 lines (76 loc) · 2.37 KB
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
package main
import (
"congest/network"
"log"
"path/filepath"
"time"
"github.com/pulumi/pulumi/sdk/v3/go/pulumi"
)
const (
// TestConfigKey is the key used to retrieve which test is being ran from
// the pulumi config. This value can be set by running `pulumi config set test TestName`
TestConfigKey = "test"
// RegionsConfgKey is the key used to retrieve the regions that the network
// should be deployed to from the pulumi config. This value can be set by
// running `pulumi config set regions Full`.
RegionsConfgKey = "regions"
// ChainIDConfigKey is the key used to retrieve the chain ID that the network
// should be deployed with from the pulumi config. This value can be set by
// running `pulumi config set chainID ChainID`.
ChainIDConfigKey = "chainID"
// GlobalTimeout is passed to all pulumi resources to ensure that they do
// not stay alive too long.
GlobalTimeoutString = "30m"
)
func main() {
payloadRoot := "./payload"
experiment, chainID, err := readEnv()
if err != nil {
log.Fatal(err)
}
// Call the function to generate the network with the provided arguments
n, err := network.NewNetwork(chainID)
if err != nil {
log.Fatal(err)
}
pulumi.Run(func(ctx *pulumi.Context) error {
cursor := 0
do, err := NewDigitalOcean(GlobalTimeoutString)
if err != nil {
log.Fatal(err)
}
linode, err := NewLinodeProvider(GlobalTimeoutString)
if err != nil {
log.Fatal(err)
}
var validators []network.NodeInfo
DOVals, cursor := DeployValidators(ctx, do, experiment.Regions.DigitalOcean, cursor)
validators = append(validators, DOVals...)
linodeVals, cursor := DeployValidators(ctx, linode, experiment.Regions.Linode, cursor)
validators = append(validators, linodeVals...)
ips := make([]pulumi.StringOutput, 0, len(validators))
for _, val := range validators {
n.AsyncAddValidator(val.Name, val.Region, payloadRoot, val.PendingIP)
ips = append(ips, val.PendingIP)
}
time.Sleep(time.Second)
pulumi.All(ips).ApplyT(func(_ []interface{}) error {
err = n.InitNodes(payloadRoot)
if err != nil {
panic(err)
}
err = n.SaveAddressBook(payloadRoot, n.Peers())
if err != nil {
panic(err)
}
err = n.SaveValidatorsToFile(filepath.Join(payloadRoot, "validators.json"))
if err != nil {
panic(err)
}
return nil
})
time.Sleep(time.Second * 20)
return nil
})
time.Sleep(time.Second * 30)
}