-
Notifications
You must be signed in to change notification settings - Fork 80
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
testutil/compose: add lock command (#570)
Adds the first version of the lock command that creates a docker-compose file to run `charon create cluster` to generate keys and cluster lock file. category: feature ticket: #568
- Loading branch information
1 parent
f31efa6
commit ac67cd8
Showing
10 changed files
with
408 additions
and
29 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
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,77 @@ | ||
version: "3.8" | ||
|
||
x-node-base: &node-base | ||
image: ghcr.io/obolnetwork/charon:{{.CharonImageTag}} | ||
entrypoint: {{.CharonEntrypoint}} | ||
command: {{.CharonCommand}} | ||
networks: [compose] | ||
volumes: [{{.ComposeDir}}:/compose] | ||
{{if not .NodeOnly }}depends_on: [bootnode] {{end}} | ||
|
||
services: | ||
{{ range $i, $node := .Nodes}} | ||
node{{$i}}: | ||
<<: *node-base | ||
environment: | ||
{{- range $node.EnvVars}} | ||
CHARON_{{.KeyUpper}}: {{.Value}} | ||
{{- end}} | ||
{{if .Ports}} | ||
ports: | ||
{{- range $node.Ports}} | ||
- "{{.External}}:{{.Internal}}" | ||
{{- end}} | ||
{{- end}} | ||
{{ end -}} | ||
|
||
{{if not .NodeOnly }} | ||
bootnode: | ||
<<: *node-base | ||
command: bootnode | ||
depends_on: [] | ||
environment: | ||
CHARON_BOOTNODE_HTTP_ADDRESS: 0.0.0.0:16000 | ||
CHARON_DATA_DIR: /compose/bootnode | ||
CHARON_P2P_BOOTNODES: "" | ||
CHARON_P2P_EXTERNAL_HOSTNAME: bootnode | ||
|
||
{{- range $i, $vc := .VCs}} | ||
vc{{$i}}-{{$vc.Label}}: | ||
{{if $vc.Build}} build: {{$vc.Build}} {{end}} | ||
{{if $vc.Image}} image: {{$vc.Image}} {{end}} | ||
{{if $vc.Command}} command: {{$vc.Command}} {{end}} | ||
networks: [compose] | ||
depends_on: [node{{$i}}] | ||
environment: | ||
NODE: node{{$i}} | ||
volumes: | ||
- .:/compose | ||
{{end}} | ||
|
||
prometheus: | ||
image: prom/prometheus:latest | ||
ports: | ||
- "9090:9090" | ||
networks: [compose] | ||
volumes: | ||
- ./prometheus/prometheus.yml:/etc/prometheus/prometheus.yml | ||
|
||
grafana: | ||
image: grafana/grafana:latest | ||
ports: | ||
- "3000:3000" | ||
networks: [compose] | ||
volumes: | ||
- ./grafana/datasource.yml:/etc/grafana/provisioning/datasources/datasource.yml | ||
- ./grafana/dashboards.yml:/etc/grafana/provisioning/dashboards/datasource.yml | ||
- ./grafana/grafana.ini:/etc/grafana/grafana.ini:ro | ||
- ./grafana/simnet_dash.json:/etc/dashboards/simnet_dash.json | ||
|
||
jaeger: | ||
image: jaegertracing/all-in-one:latest | ||
networks: [compose] | ||
ports: | ||
- "16686:16686" | ||
{{end}} | ||
networks: | ||
compose: |
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,93 @@ | ||
// Copyright © 2022 Obol Labs Inc. | ||
// | ||
// This program is free software: you can redistribute it and/or modify it | ||
// under the terms of the GNU General Public License as published by the Free | ||
// Software Foundation, either version 3 of the License, or (at your option) | ||
// any later version. | ||
// | ||
// This program is distributed in the hope that it will be useful, but WITHOUT | ||
// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | ||
// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for | ||
// more details. | ||
// | ||
// You should have received a copy of the GNU General Public License along with | ||
// this program. If not, see <http://www.gnu.org/licenses/>. | ||
|
||
package compose | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
"os" | ||
"path" | ||
|
||
"github.com/goccy/go-yaml" | ||
|
||
"github.com/obolnetwork/charon/app/errors" | ||
"github.com/obolnetwork/charon/app/log" | ||
) | ||
|
||
func Lock(ctx context.Context, dir string) error { | ||
ctx = log.WithTopic(ctx, "lock") | ||
|
||
conf, err := loadConfig(dir) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
if conf.KeyGen != keyGenCreate { | ||
return errors.New("only keygen create supported") | ||
} | ||
|
||
// Only single node to call charon create cluster generate keys | ||
n := node{EnvVars: []kv{ | ||
{"threshold", fmt.Sprint(conf.Def.Threshold)}, | ||
{"nodes", fmt.Sprint(len(conf.Def.Operators))}, | ||
{"cluster_dir", "/compose"}, | ||
}} | ||
|
||
data := tmplData{ | ||
NodeOnly: true, | ||
ComposeDir: dir, | ||
CharonImageTag: conf.ImageTag, | ||
CharonEntrypoint: containerBinary, | ||
CharonCommand: cmdCreateCluster, | ||
Nodes: []node{n}, | ||
} | ||
|
||
log.Info(ctx, "Created docker-compose.yml") | ||
log.Info(ctx, "Create keys and cluster lock with: docker-compose up") | ||
|
||
return writeDockerCompose(dir, data) | ||
} | ||
|
||
//nolint:deadcode // Busy implementing. | ||
func newNodeEnvs(mockValidator bool) []kv { | ||
return []kv{ | ||
{"jaeger_address", "jaeger:6831"}, | ||
{"definition_file", "/compose/cluster-definition.json"}, | ||
{"lock_file", "/compose/cluster-lock.json"}, | ||
{"monitoring_address", "0.0.0.0:16001"}, | ||
{"validator_api_address", "0.0.0.0:16002"}, | ||
{"p2p_tcp_address", "0.0.0.0:16003"}, | ||
{"p2p_udp_address", "0.0.0.0:16004"}, | ||
{"p2p_bootnodes", "http://bootnode:16000/enr"}, | ||
{"simnet_validator_mock", fmt.Sprint(mockValidator)}, | ||
{"log_level", "info"}, | ||
} | ||
} | ||
|
||
// loadConfig returns the config loaded from disk. | ||
func loadConfig(dir string) (config, error) { | ||
b, err := os.ReadFile(path.Join(dir, composeFile)) | ||
if err != nil { | ||
return config{}, errors.Wrap(err, "load config") | ||
} | ||
|
||
var resp config | ||
if err := yaml.Unmarshal(b, &resp); err != nil { | ||
return config{}, errors.Wrap(err, "unmarshal config") | ||
} | ||
|
||
return resp, nil | ||
} |
Oops, something went wrong.