Skip to content

Commit 6993055

Browse files
authored
Add manifest JSON (#123)
1 parent 1b36788 commit 6993055

File tree

5 files changed

+129
-117
lines changed

5 files changed

+129
-117
lines changed

internal/catalog.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
package internal
22

3-
var Components = []Service{}
3+
var Components = []ServiceGen{}
44

5-
func register(component Service) {
5+
func register(component ServiceGen) {
66
Components = append(Components, component)
77
}
88

@@ -22,7 +22,7 @@ func init() {
2222
register(&BuilderHubMockProxy{})
2323
}
2424

25-
func FindComponent(name string) Service {
25+
func FindComponent(name string) ServiceGen {
2626
for _, component := range Components {
2727
if component.Name() == name {
2828
return component

internal/components.go

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ type RollupBoost struct {
1616
Builder string
1717
}
1818

19-
func (r *RollupBoost) Run(service *service, ctx *ExContext) {
19+
func (r *RollupBoost) Run(service *Service, ctx *ExContext) {
2020
service.
2121
WithImage("docker.io/flashbots/rollup-boost").
2222
WithTag("0.4rc1").
@@ -40,7 +40,7 @@ type OpBatcher struct {
4040
MaxChannelDuration uint64
4141
}
4242

43-
func (o *OpBatcher) Run(service *service, ctx *ExContext) {
43+
func (o *OpBatcher) Run(service *Service, ctx *ExContext) {
4444
if o.MaxChannelDuration == 0 {
4545
o.MaxChannelDuration = 2
4646
}
@@ -70,7 +70,7 @@ type OpNode struct {
7070
L2Node string
7171
}
7272

73-
func (o *OpNode) Run(service *service, ctx *ExContext) {
73+
func (o *OpNode) Run(service *Service, ctx *ExContext) {
7474
service.
7575
WithImage("us-docker.pkg.dev/oplabs-tools-artifacts/images/op-node").
7676
WithTag("v1.13.0-rc.1").
@@ -135,7 +135,7 @@ func logLevelToGethVerbosity(logLevel LogLevel) string {
135135
}
136136
}
137137

138-
func (o *OpGeth) Run(service *service, ctx *ExContext) {
138+
func (o *OpGeth) Run(service *Service, ctx *ExContext) {
139139
var nodeKeyFlag string
140140
if o.UseDeterministicP2PKey {
141141
nodeKeyFlag = "--nodekey /data/deterministic_p2p_key.txt "
@@ -252,7 +252,7 @@ func logLevelToRethVerbosity(logLevel LogLevel) string {
252252
}
253253
}
254254

255-
func (r *RethEL) Run(svc *service, ctx *ExContext) {
255+
func (r *RethEL) Run(svc *Service, ctx *ExContext) {
256256
// start the reth el client
257257
svc.
258258
WithImage("ghcr.io/paradigmxyz/reth").
@@ -306,7 +306,7 @@ type LighthouseBeaconNode struct {
306306
MevBoostNode string
307307
}
308308

309-
func (l *LighthouseBeaconNode) Run(svc *service, ctx *ExContext) {
309+
func (l *LighthouseBeaconNode) Run(svc *Service, ctx *ExContext) {
310310
svc.
311311
WithImage("sigp/lighthouse").
312312
WithTag("v7.0.0-beta.0").
@@ -364,7 +364,7 @@ type LighthouseValidator struct {
364364
BeaconNode string
365365
}
366366

367-
func (l *LighthouseValidator) Run(service *service, ctx *ExContext) {
367+
func (l *LighthouseValidator) Run(service *Service, ctx *ExContext) {
368368
// start validator client
369369
service.
370370
WithImage("sigp/lighthouse").
@@ -393,7 +393,7 @@ type ClProxy struct {
393393
SecondaryBuilder string
394394
}
395395

396-
func (c *ClProxy) Run(service *service, ctx *ExContext) {
396+
func (c *ClProxy) Run(service *Service, ctx *ExContext) {
397397
service.
398398
WithImage("docker.io/flashbots/playground-utils").
399399
WithTag("latest").
@@ -414,7 +414,7 @@ type MevBoostRelay struct {
414414
ValidationServer string
415415
}
416416

417-
func (m *MevBoostRelay) Run(service *service, ctx *ExContext) {
417+
func (m *MevBoostRelay) Run(service *Service, ctx *ExContext) {
418418
service.
419419
WithImage("docker.io/flashbots/playground-utils").
420420
WithTag("latest").
@@ -455,7 +455,7 @@ func (m *MevBoostRelay) Watchdog(out io.Writer, instance *instance, ctx context.
455455
type BuilderHubPostgres struct {
456456
}
457457

458-
func (b *BuilderHubPostgres) Run(service *service, ctx *ExContext) {
458+
func (b *BuilderHubPostgres) Run(service *Service, ctx *ExContext) {
459459
service.
460460
WithImage("docker.io/flashbots/builder-hub-db").
461461
WithTag("latest").
@@ -480,7 +480,7 @@ type BuilderHub struct {
480480
postgres string
481481
}
482482

483-
func (b *BuilderHub) Run(service *service, ctx *ExContext) {
483+
func (b *BuilderHub) Run(service *Service, ctx *ExContext) {
484484
service.
485485
WithImage("docker.io/flashbots/builder-hub").
486486
WithTag("latest").
@@ -501,7 +501,7 @@ type BuilderHubMockProxy struct {
501501
TargetService string
502502
}
503503

504-
func (b *BuilderHubMockProxy) Run(service *service, ctx *ExContext) {
504+
func (b *BuilderHubMockProxy) Run(service *Service, ctx *ExContext) {
505505
service.
506506
WithImage("docker.io/flashbots/builder-hub-mock-proxy").
507507
WithTag("latest").
@@ -519,7 +519,7 @@ func (b *BuilderHubMockProxy) Name() string {
519519
type OpReth struct {
520520
}
521521

522-
func (o *OpReth) Run(service *service, ctx *ExContext) {
522+
func (o *OpReth) Run(service *Service, ctx *ExContext) {
523523
service.WithImage("ghcr.io/paradigmxyz/op-reth").
524524
WithTag("nightly").
525525
WithEntrypoint("op-reth").

internal/local_runner.go

Lines changed: 26 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -129,9 +129,9 @@ func NewLocalRunner(out *output, manifest *Manifest, overrides map[string]string
129129
logRef: log_output,
130130
path: log_output.Name(),
131131
}
132-
component := FindComponent(service.componentName)
132+
component := FindComponent(service.ComponentName)
133133
if component == nil {
134-
return nil, fmt.Errorf("component not found '%s'", service.componentName)
134+
return nil, fmt.Errorf("component not found '%s'", service.ComponentName)
135135
}
136136
instance := &instance{
137137
service: service,
@@ -145,7 +145,7 @@ func NewLocalRunner(out *output, manifest *Manifest, overrides map[string]string
145145
// TODO: it feels a bit weird to have all this logic on the new command. We should split it later on.
146146
for _, instance := range instances {
147147
ss := instance.service
148-
if ss.labels[useHostExecutionLabel] == "true" {
148+
if ss.Labels[useHostExecutionLabel] == "true" {
149149
// If the service wants to run on the host, it must implement the ReleaseService interface
150150
// which provides functions to download the release artifact.
151151
releaseService, ok := instance.component.(ReleaseService)
@@ -176,8 +176,8 @@ func NewLocalRunner(out *output, manifest *Manifest, overrides map[string]string
176176
}
177177

178178
srv := manifest.MustGetService(k)
179-
srv.image = parts[0]
180-
srv.tag = parts[1]
179+
srv.Image = parts[0]
180+
srv.Tag = parts[1]
181181

182182
delete(overrides, k)
183183
continue
@@ -443,7 +443,7 @@ func (d *LocalRunner) reservePort(startPort int, protocol string) int {
443443
panic("BUG: could not reserve a port")
444444
}
445445

446-
func (d *LocalRunner) getService(name string) *service {
446+
func (d *LocalRunner) getService(name string) *Service {
447447
for _, svc := range d.manifest.services {
448448
if svc.Name == name {
449449
return svc
@@ -454,7 +454,7 @@ func (d *LocalRunner) getService(name string) *service {
454454

455455
// applyTemplate resolves the templates from the manifest (Dir, Port, Connect) into
456456
// the actual values for this specific docker execution.
457-
func (d *LocalRunner) applyTemplate(s *service) ([]string, map[string]string, error) {
457+
func (d *LocalRunner) applyTemplate(s *Service) ([]string, map[string]string, error) {
458458
var input map[string]interface{}
459459

460460
// For {{.Dir}}:
@@ -535,7 +535,7 @@ func (d *LocalRunner) applyTemplate(s *service) ([]string, map[string]string, er
535535

536536
// apply the templates to the arguments
537537
var argsResult []string
538-
for _, arg := range s.args {
538+
for _, arg := range s.Args {
539539
newArg, err := runTemplate(arg)
540540
if err != nil {
541541
return nil, nil, err
@@ -545,7 +545,7 @@ func (d *LocalRunner) applyTemplate(s *service) ([]string, map[string]string, er
545545

546546
// apply the templates to the environment variables
547547
envs := map[string]string{}
548-
for k, v := range s.env {
548+
for k, v := range s.Env {
549549
newV, err := runTemplate(v)
550550
if err != nil {
551551
return nil, nil, err
@@ -577,7 +577,7 @@ func (d *LocalRunner) validateImageExists(image string) error {
577577
return fmt.Errorf("image %s not found: %w", image)
578578
}
579579

580-
func (d *LocalRunner) toDockerComposeService(s *service) (map[string]interface{}, error) {
580+
func (d *LocalRunner) toDockerComposeService(s *Service) (map[string]interface{}, error) {
581581
// apply the template again on the arguments to figure out the connections
582582
// at this point all of them are valid, we just have to resolve them again. We assume for now
583583
// everyone is going to be on docker at the same network.
@@ -594,7 +594,7 @@ func (d *LocalRunner) toDockerComposeService(s *service) (map[string]interface{}
594594
}
595595

596596
// Validate that the image exists
597-
imageName := fmt.Sprintf("%s:%s", s.image, s.tag)
597+
imageName := fmt.Sprintf("%s:%s", s.Image, s.Tag)
598598
if err := d.validateImageExists(imageName); err != nil {
599599
return nil, fmt.Errorf("failed to validate image %s: %w", imageName, err)
600600
}
@@ -610,20 +610,20 @@ func (d *LocalRunner) toDockerComposeService(s *service) (map[string]interface{}
610610
// add the local ports exposed by the service as labels
611611
// we have to do this for now since we do not store the manifest in JSON yet.
612612
// Otherwise, we could use that directly
613-
for _, port := range s.ports {
613+
for _, port := range s.Ports {
614614
labels[fmt.Sprintf("port.%s", port.Name)] = fmt.Sprintf("%d", port.Port)
615615
}
616616

617617
// Use files mapped to figure out which files from the artifacts is using the service
618618
volumes := map[string]string{
619619
outputFolder: "/artifacts", // placeholder
620620
}
621-
for k, v := range s.filesMapped {
621+
for k, v := range s.FilesMapped {
622622
volumes[filepath.Join(outputFolder, v)] = k
623623
}
624624

625625
// create the bind volumes
626-
for localPath, volumeName := range s.volumesMapped {
626+
for localPath, volumeName := range s.VolumesMapped {
627627
volumeDirAbsPath, err := d.createVolume(s.Name, volumeName)
628628
if err != nil {
629629
return nil, err
@@ -669,10 +669,10 @@ func (d *LocalRunner) toDockerComposeService(s *service) (map[string]interface{}
669669
}
670670
}
671671

672-
if s.dependsOn != nil {
672+
if s.DependsOn != nil {
673673
depends := map[string]interface{}{}
674674

675-
for _, d := range s.dependsOn {
675+
for _, d := range s.DependsOn {
676676
if d.Condition == "" {
677677
depends[d.Name] = struct{}{}
678678
} else {
@@ -694,13 +694,13 @@ func (d *LocalRunner) toDockerComposeService(s *service) (map[string]interface{}
694694
}
695695
}
696696

697-
if s.entrypoint != "" {
698-
service["entrypoint"] = s.entrypoint
697+
if s.Entrypoint != "" {
698+
service["entrypoint"] = s.Entrypoint
699699
}
700700

701-
if len(s.ports) > 0 {
701+
if len(s.Ports) > 0 {
702702
ports := []string{}
703-
for _, p := range s.ports {
703+
for _, p := range s.Ports {
704704
protocol := ""
705705
if p.Protocol == ProtocolUDP {
706706
protocol = "/udp"
@@ -740,7 +740,7 @@ func (d *LocalRunner) generateDockerCompose() ([]byte, error) {
740740
// both to have access to the services from localhost but also to do communication
741741
// between services running inside docker and the ones running on the host machine.
742742
for _, svc := range d.manifest.services {
743-
for _, port := range svc.ports {
743+
for _, port := range svc.Ports {
744744
port.HostPort = d.reservePort(port.Port, port.Protocol)
745745
}
746746
}
@@ -775,7 +775,7 @@ func (d *LocalRunner) createVolume(service, volumeName string) (string, error) {
775775
}
776776

777777
// runOnHost runs the service on the host machine
778-
func (d *LocalRunner) runOnHost(ss *service) error {
778+
func (d *LocalRunner) runOnHost(ss *Service) error {
779779
// TODO: Use env vars in host processes
780780
args, _, err := d.applyTemplate(ss)
781781
if err != nil {
@@ -784,7 +784,7 @@ func (d *LocalRunner) runOnHost(ss *service) error {
784784

785785
// Create the volumes for this service
786786
volumesMapped := map[string]string{}
787-
for pathInDocker, volumeName := range ss.volumesMapped {
787+
for pathInDocker, volumeName := range ss.VolumesMapped {
788788
volumeDirAbsPath, err := d.createVolume(ss.Name, volumeName)
789789
if err != nil {
790790
return err
@@ -796,7 +796,7 @@ func (d *LocalRunner) runOnHost(ss *service) error {
796796
// Just a string replacement should be enough
797797
for i, arg := range args {
798798
// If any of the args contains any of the files mapped, we need to replace it
799-
for pathInDocker, artifactName := range ss.filesMapped {
799+
for pathInDocker, artifactName := range ss.FilesMapped {
800800
if strings.Contains(arg, pathInDocker) {
801801
args[i] = strings.ReplaceAll(arg, pathInDocker, filepath.Join(d.out.dst, artifactName))
802802
}
@@ -914,10 +914,10 @@ func CreatePrometheusServices(manifest *Manifest, out *output) error {
914914
})
915915

916916
for _, c := range manifest.services {
917-
for _, port := range c.ports {
917+
for _, port := range c.Ports {
918918
if port.Name == "metrics" {
919919
metricsPath := "/metrics"
920-
if overrideMetricsPath, ok := c.labels["metrics_path"]; ok {
920+
if overrideMetricsPath, ok := c.Labels["metrics_path"]; ok {
921921
metricsPath = overrideMetricsPath
922922
}
923923

0 commit comments

Comments
 (0)