code.vegaprotocol.io/vega@v0.79.0/visor/config/run_config.go (about)

     1  // Copyright (C) 2023 Gobalsky Labs Limited
     2  //
     3  // This program is free software: you can redistribute it and/or modify
     4  // it under the terms of the GNU Affero General Public License as
     5  // published by the Free Software Foundation, either version 3 of the
     6  // License, or (at your option) any later version.
     7  //
     8  // This program is distributed in the hope that it will be useful,
     9  // but WITHOUT ANY WARRANTY; without even the implied warranty of
    10  // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    11  // GNU Affero General Public License for more details.
    12  //
    13  // You should have received a copy of the GNU Affero General Public License
    14  // along with this program.  If not, see <http://www.gnu.org/licenses/>.
    15  
    16  package config
    17  
    18  import (
    19  	"fmt"
    20  
    21  	"code.vegaprotocol.io/vega/paths"
    22  )
    23  
    24  /*
    25  description: Configuration options for the Vega binary and its arguments.
    26  example:
    27  
    28  	type: toml
    29  	value: |
    30  		path = "/path/binary"
    31  		args = ["--arg1", "val1", "--arg2"]
    32  */
    33  type BinaryConfig struct {
    34  	/*
    35  		description: Path to the Vega binary.
    36  		note: |
    37  			The absolute or relative path can be used.
    38  			Relative path is relative to a parent folder of this config file.
    39  	*/
    40  	Path string `toml:"path"`
    41  	/*
    42  		description: Arguments that will be applied to the binary.
    43  		note: |
    44  			Each element the list represents one space separated argument.
    45  	*/
    46  	Args []string `toml:"args"`
    47  }
    48  
    49  /*
    50  description: Configures a connection to a core node's exposed UNIX socket RPC API.
    51  example:
    52  
    53  	type: toml
    54  	value: |
    55  		[vega.rpc]
    56  			socketPath = "/path/socket.sock"
    57  			httpPath = "/rpc"
    58  */
    59  type RPCConfig struct {
    60  	/*
    61  		description: Path of the mounted socket.
    62  		note: This path can be configured in the Vega core node configuration and can be found in the [Admin.Server] section.
    63  	*/
    64  	SocketPath string `toml:"socketPath"`
    65  	/*
    66  		description: HTTP path of the socket path.
    67  		note: This path can be configured in the Vega core node configuration and can be found in the [Admin.Server] section.
    68  	*/
    69  	HTTPPath string `toml:"httpPath"`
    70  }
    71  
    72  /*
    73  description: Configuration options for the Vega binary and its arguments.
    74  example:
    75  
    76  	type: toml
    77  	value: |
    78  		[vega]
    79  			[vega.binary]
    80  				path = "/path/vega-binary"
    81  				args = ["--arg1", "val1", "--arg2"]
    82  			[vega.rpc]
    83  				socketPath = "/path/socket.sock"
    84  				httpPath = "/rpc"
    85  */
    86  type VegaConfig struct {
    87  	/*
    88  		description: Configuration of Vega binary and the arguments to run it.
    89  		example:
    90  			type: toml
    91  			value: |
    92  				[vega.binary]
    93  					path = "/path/vega-binary"
    94  					args = ["--arg1", "val1", "--arg2"]
    95  	*/
    96  	Binary BinaryConfig `toml:"binary"`
    97  
    98  	/*
    99  		description: |
   100  			Visor communicates with the core node via RPC API that runs over a UNIX socket.
   101  			This parameter configures the UNIX socket to match the core node configuration.
   102  			This value can be found in the config.toml file used by the core node under the heading [Admin.Server]
   103  		example:
   104  			type: toml
   105  			value: |
   106  				[vega.binary]
   107  					path = "/path/vega-binary"
   108  					args = ["--arg1", "val1", "--arg2"]
   109  	*/
   110  	RCP RPCConfig `toml:"rpc"`
   111  }
   112  
   113  /*
   114  description: Configures a data node binary and its arguments.
   115  example:
   116  
   117  	type: toml
   118  	value: |
   119  		[data_node]
   120  			[data_node.binary]
   121  				path = "/path/data-node-binary"
   122  				args = ["--arg1", "val1", "--arg2"]
   123  */
   124  type DataNodeConfig struct {
   125  	Binary BinaryConfig `toml:"binary"`
   126  }
   127  
   128  /*
   129  description: Root of the config file
   130  example:
   131  
   132  	type: toml
   133  	value: |
   134  		name = "v1.65.0"
   135  
   136  		[vega]
   137  			[vega.binary]
   138  				path = "/path/vega-binary"
   139  				args = ["--arg1", "val1", "--arg2"]
   140  			[vega.rpc]
   141  				socketPath = "/path/socket.sock"
   142  				httpPath = "/rpc"
   143  */
   144  type RunConfig struct {
   145  	/*
   146  		description: Name of the upgrade.
   147  		note: |
   148  			It is recommended to use the Vega version you wish to upgrade to as the name. These can be found in the releases list of the Vega Github repository
   149  			(https://github.com/vegaprotocol/vega/releases).
   150  
   151  	*/
   152  	Name string `toml:"name"`
   153  	// description: Configuration of a Vega node.
   154  	Vega VegaConfig `toml:"vega"`
   155  	// description: Configuration of a data node.
   156  	DataNode *DataNodeConfig `toml:"data_node"`
   157  }
   158  
   159  func ExampleRunConfig(name string, withDataNode bool) *RunConfig {
   160  	c := &RunConfig{
   161  		Name: name,
   162  		Vega: VegaConfig{
   163  			Binary: BinaryConfig{
   164  				Path: "vega",
   165  				Args: []string{"arg1", "arg2", "..."},
   166  			},
   167  		},
   168  	}
   169  
   170  	if withDataNode {
   171  		c.DataNode = &DataNodeConfig{
   172  			Binary: BinaryConfig{
   173  				Path: "vega data-node",
   174  				Args: []string{"arg1", "arg2", "..."},
   175  			},
   176  		}
   177  	}
   178  
   179  	return c
   180  }
   181  
   182  func ParseRunConfig(path string) (*RunConfig, error) {
   183  	conf := RunConfig{}
   184  	if err := paths.ReadStructuredFile(path, &conf); err != nil {
   185  		return nil, fmt.Errorf("failed to parse RunConfig: %w", err)
   186  	}
   187  
   188  	return &conf, nil
   189  }
   190  
   191  func (rc *RunConfig) WriteToFile(path string) error {
   192  	return paths.WriteStructuredFile(path, rc)
   193  }