Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

testutil/compose: rename compose config #590

Merged
merged 3 commits into from
May 23, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions testutil/compose/compose/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
// using docker-compose.
//
// It consists of three steps:
// - compose define: Creates charon-compose.yml (and p2pkeys) that defines a desired cluster including keygen.
// - compose define: Creates config.json (and p2pkeys) and a docker-compose.yml to create a cluster definition file.
// - compose lock: Creates docker-compose.yml to generates keys and cluster lock file.
// - compose run: Creates docker-compose.yml that runs the cluster.
package main
Expand Down Expand Up @@ -57,7 +57,7 @@ func newRootCmd() *cobra.Command {
func newRunCmd() *cobra.Command {
cmd := &cobra.Command{
Use: "run",
Short: "Create a docker-compose.yml from charon-compose.yml to run the cluster.",
Short: "Creates docker-compose.yml that runs the cluster.",
}

up := addUpFlag(cmd.Flags())
Expand All @@ -81,7 +81,7 @@ func newRunCmd() *cobra.Command {
func newLockCmd() *cobra.Command {
cmd := &cobra.Command{
Use: "lock",
Short: "Create a docker-compose.yml for generating keys and a cluster lock file.",
Short: "Creates docker-compose.yml to generates keys and cluster lock file.",
}

up := addUpFlag(cmd.Flags())
Expand All @@ -105,7 +105,7 @@ func newLockCmd() *cobra.Command {
func newDefineCmd() *cobra.Command {
cmd := &cobra.Command{
Use: "define",
Short: "Create a charon-compose.yml definition and a docker-compose.yml for generating a cluster definition file",
Short: "Creates config.json (and p2pkeys) and a docker-compose.yml to create a cluster definition file",
}

conf := compose.NewDefaultConfig()
Expand Down
11 changes: 6 additions & 5 deletions testutil/compose/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ package compose

const (
version = "obol/charon/compose/1.0.0"
composeFile = "charon-compose.yml"
configFile = "config.json"
defaultImageTag = "latest"
defaultBeaconNode = "mock"
defaultKeyGen = keyGenCreate
Expand Down Expand Up @@ -64,6 +64,9 @@ type Config struct {
// Version defines the compose config version.
Version string `json:"version"`

// Step defines the current completed compose step.
Step step `json:"step"`

// NumNodes is the number of charon nodes in the cluster.
NumNodes int `json:"num_nodes"`

Expand All @@ -76,16 +79,14 @@ type Config struct {
// ImageTag defines the charon docker image tag: ghcr.io/obolnetwork/charon:{ImageTag}.
ImageTag string `json:"image_tag"`

// VCs define the types of validator clients to use.
VCs []vcType `json:"validator_clients"`

// KeyGen defines the key generation process.
KeyGen KeyGen `json:"key_gen"`

// BeaconNode url endpoint or "mock" for simnet.
BeaconNode string `json:"beacon_node"`

Step step `json:"step"`
// VCs define the types of validator clients to use.
VCs []vcType `json:"validator_clients"`
}

// NewDefaultConfig returns a new default config.
Expand Down
10 changes: 2 additions & 8 deletions testutil/compose/define.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ import (
"github.com/ethereum/go-ethereum/crypto"
"github.com/ethereum/go-ethereum/p2p/enode"
"github.com/ethereum/go-ethereum/p2p/enr"
"github.com/goccy/go-yaml"

"github.com/obolnetwork/charon/app/errors"
"github.com/obolnetwork/charon/app/log"
Expand Down Expand Up @@ -125,7 +124,7 @@ func Define(ctx context.Context, dir string, seed int, conf Config) error {
}
}

log.Info(ctx, "Creating charon-compose.yml")
log.Info(ctx, "Creating config.json")

if err := writeConfig(dir, conf); err != nil {
return err
Expand Down Expand Up @@ -225,12 +224,7 @@ func writeConfig(dir string, conf Config) error {
return errors.Wrap(err, "marshal config")
}

b, err = yaml.JSONToYAML(b)
if err != nil {
return errors.Wrap(err, "yaml config")
}

err = os.WriteFile(path.Join(dir, composeFile), b, 0o755) //nolint:gosec
err = os.WriteFile(path.Join(dir, configFile), b, 0o755) //nolint:gosec
if err != nil {
return errors.Wrap(err, "write config")
}
Expand Down
2 changes: 1 addition & 1 deletion testutil/compose/define_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ func TestDefineCompose(t *testing.T) {
err = compose.Define(context.Background(), dir, 1, compose.NewDefaultConfig())
require.NoError(t, err)

conf, err := os.ReadFile(path.Join(dir, "charon-compose.yml"))
conf, err := os.ReadFile(path.Join(dir, "config.json"))
require.NoError(t, err)

testutil.RequireGoldenBytes(t, conf)
Expand Down
9 changes: 1 addition & 8 deletions testutil/compose/lock.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,6 @@ import (
"os"
"path"

"github.com/goccy/go-yaml"

"github.com/obolnetwork/charon/app/errors"
"github.com/obolnetwork/charon/app/log"
)
Expand Down Expand Up @@ -112,16 +110,11 @@ func newNodeEnvs(index int, validatorMock, beaconMock bool) []kv {

// loadConfig returns the config loaded from disk.
func loadConfig(dir string) (Config, error) {
b, err := os.ReadFile(path.Join(dir, composeFile))
b, err := os.ReadFile(path.Join(dir, configFile))
if err != nil {
return Config{}, errors.Wrap(err, "load config")
}

b, err = yaml.YAMLToJSON(b)
if err != nil {
return Config{}, errors.Wrap(err, "yaml config")
}

var resp Config
if err := json.Unmarshal(b, &resp); err != nil {
return Config{}, errors.Wrap(err, "unmarshal Config")
Expand Down
2 changes: 1 addition & 1 deletion testutil/compose/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import (
"github.com/obolnetwork/charon/app/log"
)

// Run creates a docker-compose.yml from charon-compose.yml to run the cluster.
// Run creates a docker-compose.yml from config.json to run the cluster.
func Run(ctx context.Context, dir string) error {
ctx = log.WithTopic(ctx, "run")

Expand Down
27 changes: 15 additions & 12 deletions testutil/compose/testdata/TestDefineCompose.golden
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
version: obol/charon/compose/1.0.0
num_nodes: 4
threshold: 3
num_validators: 1
image_tag: latest
validator_clients:
- teku
- lighthouse
- mock
key_gen: create
beacon_node: mock
step: defined
{
"version": "obol/charon/compose/1.0.0",
"step": "defined",
"num_nodes": 4,
"threshold": 3,
"num_validators": 1,
"image_tag": "latest",
"key_gen": "create",
"beacon_node": "mock",
"validator_clients": [
"teku",
"lighthouse",
"mock"
]
}