-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
14 changed files
with
386 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
module github.com/cosmology-tech/starship | ||
|
||
go 1.21.0 | ||
|
||
require gopkg.in/yaml.v3 v3.0.1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM= | ||
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= | ||
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= | ||
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,15 @@ | ||
go 1.19 | ||
go 1.21.0 | ||
|
||
use ( | ||
|
||
. | ||
./clients/go/client | ||
./cmd/starship | ||
|
||
./examples/upgrade-test | ||
./exposer | ||
./registry | ||
./faucet | ||
./registry | ||
./tests/e2e | ||
./tools | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package loader | ||
|
||
import "github.com/cosmology-tech/starship/pkg/types" | ||
|
||
type Loader interface { | ||
LoadFile(files []string, defaultFile string) (types.StarshipObject, error) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
package starship | ||
|
||
import ( | ||
"github.com/cosmology-tech/starship/pkg/types" | ||
"strings" | ||
) | ||
|
||
func getChainPorts(chainConfig types.Chain) []types.Ports { | ||
// default ports | ||
ports := []types.Ports{ | ||
{Name: "p2p", ContainerPort: 26656, Protocol: "TCP"}, | ||
{Name: "rpc", ContainerPort: 26657, Protocol: "TCP"}, | ||
{Name: "address", ContainerPort: 26658, Protocol: "TCP"}, | ||
{Name: "grpc", ContainerPort: 9090, Protocol: "TCP"}, | ||
{Name: "rest", ContainerPort: 1317, Protocol: "TCP"}, | ||
} | ||
|
||
for i, port := range ports { | ||
hostPort := chainConfig.Ports.GetPort(port.Name) | ||
if hostPort != 0 { | ||
ports[i].HostPort = int32(hostPort) | ||
} | ||
} | ||
|
||
return ports | ||
} | ||
|
||
// convertChainToServiceConfig creates a list of serviceConfig objects based on chain defination in config | ||
// when a chain is converted to NodeConfig, then these containers are created: | ||
// - {chain}-genesis | ||
// init: [init-genesis, init-config] | ||
// sidecars: [exposer, faucet(optional)] | ||
// - {chain}-validator | ||
// dependson: genesis | ||
// init: [init-validator, init-config] | ||
// sidecars: [exposer] | ||
// - {chain}-cometmock (optional) | ||
// dependson: genesis, validator | ||
// init: [init-cometmock] | ||
func convertChainToServiceConfig(chainConfig types.Chain) ([]types.NodeConfig, error) { | ||
allNodes := []types.NodeConfig{} | ||
|
||
// initialize genesis node | ||
genesis := types.NodeConfig{ | ||
Name: chainConfig.Name, | ||
ContainerName: strings.Replace(chainConfig.Name, "_", "-", -1), | ||
Controller: "statefulsets", // this is specific to k8s, and is ignored for others | ||
Image: chainConfig.Image, | ||
Port: getChainPorts(chainConfig), | ||
Command: nil, | ||
ScriptFiles: nil, | ||
WorkingDir: "", | ||
Init: nil, | ||
DependsOn: nil, | ||
Replicas: 0, | ||
Labels: nil, | ||
Annotations: nil, | ||
Sidecars: nil, | ||
Resources: types.Resource{}, | ||
ImagePullPolicy: "", | ||
Files: nil, | ||
} | ||
|
||
allNodes = append(allNodes, genesis) | ||
|
||
return allNodes, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
package starship | ||
|
||
import ( | ||
"errors" | ||
"github.com/cosmology-tech/starship/pkg/types" | ||
"gopkg.in/yaml.v3" | ||
"os" | ||
) | ||
|
||
// Starship is starship config file loader, implements Loader interface | ||
type Starship struct { | ||
} | ||
|
||
func (s *Starship) LoadFile(files []string, defaultFile string) (types.StarshipObject, error) { | ||
if len(files) > 0 { | ||
return types.StarshipObject{}, errors.New("loading from multiple files not supported, yet") | ||
} | ||
config, err := s.loadConfig(files[0]) | ||
if err != nil { | ||
return types.StarshipObject{}, nil | ||
} | ||
// todo: override defaults into config | ||
|
||
return convertConfigToObject(config) | ||
} | ||
|
||
// loadConfig reads the file into config object | ||
func (s *Starship) loadConfig(file string) (types.Config, error) { | ||
config := types.Config{} | ||
yamlFile, err := os.ReadFile(file) | ||
if err != nil { | ||
return types.Config{}, err | ||
} | ||
err = yaml.Unmarshal(yamlFile, config) | ||
if err != nil { | ||
return types.Config{}, err | ||
} | ||
|
||
return config, nil | ||
} | ||
|
||
// convertConfigToObject converts basic Config object into Starship object, this would prefill informations | ||
// based on chains, relayers and explorers | ||
func convertConfigToObject(config types.Config) (types.StarshipObject, error) { | ||
return types.StarshipObject{}, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package kubernetes | ||
|
||
import "github.com/cosmology-tech/starship/pkg/types" | ||
|
||
// Kubernetes implements Transformer interface and represents Kubernetes transformer | ||
type Kubernetes struct { | ||
// the user provided options from the command line | ||
Opt types.ConvertOptions | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package transformer | ||
|
||
import ( | ||
"github.com/cosmology-tech/starship/pkg/types" | ||
) | ||
|
||
type Object interface { | ||
WriteToFile(dir string) error | ||
Validate() error | ||
} | ||
|
||
type Transformer interface { | ||
Transform(types.StarshipObject, types.ConvertOptions) (Object, error) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,160 @@ | ||
package types | ||
|
||
import ( | ||
"fmt" | ||
"strings" | ||
) | ||
|
||
type Chain struct { | ||
Name string `name:"name" json:"name,omitempty" yaml:"name"` | ||
Type string `name:"type" json:"type,omitempty" yaml:"type"` | ||
NumValidators int `name:"num-validators" json:"num_validators,omitempty" yaml:"numValidators"` | ||
Image string `name:"image" json:"image,omitempty" yaml:"image,omitempty"` | ||
// Chain specifics | ||
Home string `name:"home" json:"home,omitempty" yaml:"home,omitempty"` | ||
Binary string `name:"binary" json:"binary,omitempty" yaml:"binary,omitempty"` | ||
Prefix string `name:"prefix" json:"prefix,omitempty" yaml:"prefix,omitempty"` | ||
Denom string `name:"denom" json:"denom,omitempty" yaml:"denom,omitempty"` | ||
PrettyName string `name:"pretty-name" json:"pretty_name,omitempty" yaml:"prettyName,omitempty"` | ||
Coins string `name:"coins" json:"coins,omitempty" yaml:"coins,omitempty"` | ||
HDPath string `name:"hd-path" json:"hd_path,omitempty" yaml:"hdPath,omitempty"` | ||
CoinType string `name:"coin-type" json:"coin_type,omitempty" yaml:"coinType,omitempty"` | ||
Repo string `name:"repo" json:"repo,omitempty" yaml:"repo,omitempty"` | ||
// Custom modifications | ||
Scripts map[string]ScriptData `name:"scripts" json:"scripts,omitempty" yaml:"scripts"` | ||
Upgrade Upgrade `name:"upgrade" json:"upgrade,omitempty" yaml:"upgrade"` | ||
Genesis map[string]interface{} `name:"genesis" json:"genesis,omitempty" yaml:"genesis"` | ||
// Feature toggles | ||
Build Build `name:"build" json:"build,omitempty" yaml:"build,omitempty"` | ||
Cometmock *Feature `name:"cometmock" json:"cometmock,omitempty" yaml:"cometmock,omitempty"` | ||
Faucet *Feature `name:"facuet" json:"faucet,omitempty" yaml:"faucet,omitempty"` | ||
ICS *Feature `name:"ics" json:"ics,omitempty" yaml:"ics,omitempty"` | ||
// Additional information | ||
Ports HostPort `name:"ports" json:"ports,omitempty" yaml:"ports,omitempty"` | ||
Resources Resource `name:"resource" json:"resources,omitempty" yaml:"resources,omitempty"` | ||
} | ||
|
||
func (c *Chain) GetName() string { | ||
return strings.Replace(c.Name, "_", "-", -1) | ||
} | ||
|
||
func (c *Chain) GetChainID() string { | ||
return c.Name | ||
} | ||
|
||
func (c *Chain) GetRPCAddr() string { | ||
return fmt.Sprintf("http://localhost:%d", c.Ports.Rpc) | ||
} | ||
|
||
func (c *Chain) GetRESTAddr() string { | ||
return fmt.Sprintf("http://localhost:%d", c.Ports.Rest) | ||
} | ||
|
||
type ScriptData struct { | ||
File string `name:"file" json:"file,omitempty" yaml:"file"` | ||
Data string `name:"data" json:"data,omitempty" yaml:"data"` | ||
} | ||
|
||
type Upgrade struct { | ||
Enabled bool `name:"eanbled" json:"enabled" yaml:"enabled"` | ||
Type string `name:"type" json:"type" yaml:"type"` | ||
Genesis string `name:"genesis" json:"genesis" yaml:"genesis"` | ||
Upgrades []struct { | ||
Name string `name:"name" json:"name" yaml:"name"` | ||
Version string `name:"version" json:"version" yaml:"version"` | ||
} `name:"upgrades" json:"upgrades" yaml:"upgrades"` | ||
} | ||
|
||
type Build struct { | ||
Enabled bool `name:"enabled" json:"enabled,omitempty" yaml:"enabled,omitempty"` | ||
Source string `name:"source" json:"source,omitempty" yaml:"source,omitempty"` | ||
} | ||
|
||
type HostPort struct { | ||
Rest int `name:"rest" json:"rest" yaml:"rest"` | ||
Rpc int `name:"rpc" json:"rpc" yaml:"rpc"` | ||
Grpc int `name:"grpc" json:"grpc" yaml:"grpc"` | ||
Exposer int `name:"exposer" json:"exposer" yaml:"exposer"` | ||
Faucet int `name:"faucet" json:"faucet" yaml:"faucet"` | ||
} | ||
|
||
func (p HostPort) GetPort(port string) int { | ||
switch port { | ||
case "rpc": | ||
return p.Rpc | ||
case "rest": | ||
return p.Rest | ||
case "grpc": | ||
return p.Grpc | ||
case "exposer": | ||
return p.Exposer | ||
case "faucet": | ||
return p.Faucet | ||
default: | ||
return 0 | ||
} | ||
} | ||
|
||
type Relayer struct { | ||
Name string `name:"name" json:"name" yaml:"name"` | ||
Type string `name:"type" json:"type" yaml:"type"` | ||
Image string `name:"image" json:"image,omitempty" yaml:"image,omitempty"` | ||
Replicas int `name:"replicas" json:"replicas" yaml:"replicas"` | ||
Chains []string `name:"chains" json:"chains" yaml:"chains"` | ||
Config interface{} `name:"config" json:"config,omitempty" yaml:"config,omitempty"` | ||
} | ||
|
||
type Faucet struct { | ||
Enabled bool `name:"enabled" json:"enabled" yaml:"enabled"` | ||
Image string `name:"image" json:"image" yaml:"image"` | ||
Ports HostPort `name:"ports" json:"ports" yaml:"ports"` | ||
Concurrency int `name:"concurrency" json:"concurrency,omitempty" yaml:"concurrency,omitempty"` | ||
} | ||
|
||
type Feature struct { | ||
Enabled bool `name:"enabled" json:"enabled" yaml:"enabled"` | ||
Image string `name:"image" json:"image" yaml:"image"` | ||
Ports HostPort `name:"ports" json:"ports" yaml:"ports"` | ||
} | ||
|
||
func (f *Feature) GetRPCAddr() string { | ||
return fmt.Sprintf("http://localhost:%d", f.Ports.Rpc) | ||
} | ||
|
||
func (f *Feature) GetRESTAddr() string { | ||
return fmt.Sprintf("http://localhost:%d", f.Ports.Rest) | ||
} | ||
|
||
// Config is the struct for the config.yaml setup file | ||
// Need not be fully compatible with the values.schema.json file, just need | ||
// parts of the config file for performing various functions, mainly port-forwarding | ||
// todo: move this to a more common place, outside just tests | ||
// todo: can be moved to proto defination | ||
type Config struct { | ||
Chains []*Chain `name:"chains" json:"chains" yaml:"chains"` | ||
Relayers []*Relayer `name:"relayers" json:"relayers" yaml:"relayers"` | ||
Explorer *Feature `name:"explorer" json:"explorer" yaml:"explorer"` | ||
Registry *Feature `name:"registry" json:"registry" yaml:"registry"` | ||
} | ||
|
||
// HasChainId returns true if chain id found in list of chains | ||
func (c *Config) HasChainId(chainId string) bool { | ||
for _, chain := range c.Chains { | ||
if chain.Name == chainId { | ||
return true | ||
} | ||
} | ||
|
||
return false | ||
} | ||
|
||
// GetChain returns the Chain object pointer for the given chain id | ||
func (c *Config) GetChain(chainId string) *Chain { | ||
for _, chain := range c.Chains { | ||
if chain.Name == chainId { | ||
return chain | ||
} | ||
} | ||
|
||
return nil | ||
} |
Oops, something went wrong.