Skip to content

Commit

Permalink
Merge branch 'master' into feat/CI
Browse files Browse the repository at this point in the history
  • Loading branch information
tok-kkk committed Jan 19, 2021
2 parents 755ab42 + 35d516c commit d6d88b3
Show file tree
Hide file tree
Showing 7 changed files with 38 additions and 11 deletions.
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
3.0.14
3.0.15
4 changes: 4 additions & 0 deletions cmd/flag.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@ var (
Value: "mainnet",
Usage: "Network of your Darknode (default: mainnet)",
}
ConfigFlag = cli.StringFlag{
Name: "config",
Usage: "Path of the config file",
}
AddressFlag = cli.StringFlag{
Name: "address",
Usage: "Ethereum address you want to withdraw the tokens to",
Expand Down
2 changes: 1 addition & 1 deletion cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ func main() {
Usage: "Deploy a new Darknode",
Flags: []cli.Flag{
// General
NameFlag, TagsFlag, NetworkFlag,
NameFlag, TagsFlag, NetworkFlag, ConfigFlag,
// AWS
AwsFlag, AwsAccessKeyFlag, AwsSecretKeyFlag, AwsInstanceFlag, AwsRegionFlag, AwsProfileFlag,
// Digital Ocean
Expand Down
3 changes: 2 additions & 1 deletion cmd/provider/aws.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ func (p providerAws) Name() string {
func (p providerAws) Deploy(ctx *cli.Context) error {
name := ctx.String("name")
tags := ctx.String("tags")
config := ctx.String("config")

latestVersion, err := util.LatestStableRelease()
if err != nil {
Expand All @@ -81,7 +82,7 @@ func (p providerAws) Deploy(ctx *cli.Context) error {
if err != nil {
return err
}
if err := initNode(name, tags, network); err != nil {
if err := initNode(name, tags, network, config); err != nil {
return err
}

Expand Down
3 changes: 2 additions & 1 deletion cmd/provider/do.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ func (p providerDo) Name() string {
func (p providerDo) Deploy(ctx *cli.Context) error {
name := ctx.String("name")
tags := ctx.String("tags")
config := ctx.String("config")

latestVersion, err := util.LatestStableRelease()
if err != nil {
Expand All @@ -47,7 +48,7 @@ func (p providerDo) Deploy(ctx *cli.Context) error {
if err != nil {
return err
}
if err := initNode(name, tags, network); err != nil {
if err := initNode(name, tags, network, config); err != nil {
return err
}

Expand Down
3 changes: 2 additions & 1 deletion cmd/provider/gcp.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ func (p providerGcp) Name() string {
func (p providerGcp) Deploy(ctx *cli.Context) error {
name := ctx.String("name")
tags := ctx.String("tags")
config := ctx.String("config")

latestVersion, err := util.LatestStableRelease()
if err != nil {
Expand All @@ -89,7 +90,7 @@ func (p providerGcp) Deploy(ctx *cli.Context) error {
if err != nil {
return err
}
if err := initNode(name, tags, network); err != nil {
if err := initNode(name, tags, network, config); err != nil {
return err
}

Expand Down
32 changes: 26 additions & 6 deletions cmd/provider/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,20 +83,40 @@ func GetProvider(name string) (string, error) {
}

// initialise all files needed by deploying a new node
func initNode(name, tags string, network darknode.Network) error {
func initNode(name, tags string, network darknode.Network, configFile string) error {
if err := initNodeDirectory(name, tags); err != nil {
return err
}
if err := util.GenerateSshKeyAndWriteToDir(name); err != nil {
return err
}

// Generate a new config and write to a file.
config, err := darknode.NewConfig(network)
if err != nil {
return err
// Use given config for the new darknode
var conf darknode.Config
if configFile != "" {
path, err := filepath.Abs(configFile)
if err != nil{
return errors.New("invalid config path")
}

file, err := os.Open(path)
if err != nil {
return fmt.Errorf("cannot open config file, err = %v", err)
}
defer file.Close()

if err := json.NewDecoder(file).Decode(&conf); err != nil {
return err
}
} else {
var err error
conf, err = darknode.NewConfig(network)
if err != nil {
return err
}
}
configData, err := json.MarshalIndent(config, "", " ")

configData, err := json.MarshalIndent(conf, "", " ")
if err != nil {
return err
}
Expand Down

0 comments on commit d6d88b3

Please sign in to comment.