Skip to content

Commit f86bffe

Browse files
authored
Add artifacts command (#73)
1 parent 5ad1180 commit f86bffe

File tree

6 files changed

+107
-4
lines changed

6 files changed

+107
-4
lines changed

internal/artifacts.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ type Artifacts struct {
9191
}
9292

9393
func (b *ArtifactsBuilder) Build() (*Artifacts, error) {
94-
homeDir, err := getHomeDir()
94+
homeDir, err := GetHomeDir()
9595
if err != nil {
9696
return nil, err
9797
}
@@ -523,7 +523,7 @@ type sszObject interface {
523523
MarshalSSZ() ([]byte, error)
524524
}
525525

526-
func getHomeDir() (string, error) {
526+
func GetHomeDir() (string, error) {
527527
homeDir, err := os.UserHomeDir()
528528
if err != nil {
529529
return "", fmt.Errorf("error getting user home directory: %w", err)

internal/catalog.go

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
package internal
2+
3+
var components = []Service{}
4+
5+
func register(component Service) {
6+
components = append(components, component)
7+
}
8+
9+
func init() {
10+
register(&OpBatcher{})
11+
register(&OpGeth{})
12+
register(&OpNode{})
13+
register(&RethEL{})
14+
register(&LighthouseBeaconNode{})
15+
register(&LighthouseValidator{})
16+
register(&ClProxy{})
17+
register(&MevBoostRelay{})
18+
register(&RollupBoost{})
19+
}
20+
21+
func FindComponent(name string) Service {
22+
for _, component := range components {
23+
if component.Name() == name {
24+
return component
25+
}
26+
}
27+
return nil
28+
}

internal/components.go

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,10 @@ func (r *RollupBoost) Run(service *service, ctx *ExContext) {
2828
)
2929
}
3030

31+
func (r *RollupBoost) Name() string {
32+
return "rollup-boost"
33+
}
34+
3135
type OpBatcher struct {
3236
L1Node string
3337
L2Node string
@@ -51,6 +55,10 @@ func (o *OpBatcher) Run(service *service, ctx *ExContext) {
5155
)
5256
}
5357

58+
func (o *OpBatcher) Name() string {
59+
return "op-batcher"
60+
}
61+
5462
type OpNode struct {
5563
L1Node string
5664
L1Beacon string
@@ -90,6 +98,10 @@ func (o *OpNode) Run(service *service, ctx *ExContext) {
9098
)
9199
}
92100

101+
func (o *OpNode) Name() string {
102+
return "op-node"
103+
}
104+
93105
type OpGeth struct {
94106
UseDeterministicP2PKey bool
95107

@@ -159,6 +171,10 @@ func (o *OpGeth) Run(service *service, ctx *ExContext) {
159171
)
160172
}
161173

174+
func (o *OpGeth) Name() string {
175+
return "op-geth"
176+
}
177+
162178
var _ ServiceReady = &OpGeth{}
163179

164180
func (o *OpGeth) Ready(out io.Writer, service *service, ctx context.Context) error {
@@ -262,6 +278,10 @@ func (r *RethEL) Run(svc *service, ctx *ExContext) {
262278
}
263279
}
264280

281+
func (r *RethEL) Name() string {
282+
return "reth"
283+
}
284+
265285
var _ ServiceWatchdog = &RethEL{}
266286

267287
func (r *RethEL) Watchdog(out io.Writer, service *service, ctx context.Context) error {
@@ -318,6 +338,10 @@ func (l *LighthouseBeaconNode) Run(svc *service, ctx *ExContext) {
318338
}
319339
}
320340

341+
func (l *LighthouseBeaconNode) Name() string {
342+
return "lighthouse-beacon-node"
343+
}
344+
321345
var _ ServiceReady = &LighthouseBeaconNode{}
322346

323347
func (l *LighthouseBeaconNode) Ready(logOutput io.Writer, service *service, ctx context.Context) error {
@@ -351,6 +375,10 @@ func (l *LighthouseValidator) Run(service *service, ctx *ExContext) {
351375
)
352376
}
353377

378+
func (l *LighthouseValidator) Name() string {
379+
return "lighthouse-validator"
380+
}
381+
354382
type ClProxy struct {
355383
PrimaryBuilder string
356384
SecondaryBuilder string
@@ -368,6 +396,10 @@ func (c *ClProxy) Run(service *service, ctx *ExContext) {
368396
)
369397
}
370398

399+
func (c *ClProxy) Name() string {
400+
return "cl-proxy"
401+
}
402+
371403
type MevBoostRelay struct {
372404
BeaconClient string
373405
ValidationServer string
@@ -389,6 +421,10 @@ func (m *MevBoostRelay) Run(service *service, ctx *ExContext) {
389421
}
390422
}
391423

424+
func (m *MevBoostRelay) Name() string {
425+
return "mev-boost-relay"
426+
}
427+
392428
var _ ServiceWatchdog = &MevBoostRelay{}
393429

394430
func (m *MevBoostRelay) Watchdog(out io.Writer, service *service, ctx context.Context) error {

internal/manifest.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ type ExContext struct {
7777

7878
type Service interface {
7979
Run(service *service, ctx *ExContext)
80+
Name() string
8081
}
8182

8283
type ServiceReady interface {
@@ -213,7 +214,7 @@ func (s *Manifest) Validate() error {
213214
return fmt.Errorf("service '%s' must implement the ReleaseService interface", ss.Name)
214215
}
215216
releaseArtifact := releaseService.ReleaseArtifact()
216-
bin, err := downloadRelease(s.out.homeDir, releaseArtifact)
217+
bin, err := DownloadRelease(s.out.homeDir, releaseArtifact)
217218
if err != nil {
218219
return fmt.Errorf("failed to download release artifact for service '%s': %w", ss.Name, err)
219220
}

internal/releases.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ type release struct {
2020
Arch func(string, string) string
2121
}
2222

23-
func downloadRelease(outputFolder string, artifact *release) (string, error) {
23+
func DownloadRelease(outputFolder string, artifact *release) (string, error) {
2424
goos := runtime.GOOS
2525
goarch := runtime.GOARCH
2626

main.go

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,39 @@ var cookCmd = &cobra.Command{
4545
},
4646
}
4747

48+
var artifactsCmd = &cobra.Command{
49+
Use: "artifacts",
50+
Short: "List available artifacts",
51+
RunE: func(cmd *cobra.Command, args []string) error {
52+
if len(args) != 1 {
53+
return fmt.Errorf("please specify a service name")
54+
}
55+
serviceName := args[0]
56+
component := internal.FindComponent(serviceName)
57+
if component == nil {
58+
return fmt.Errorf("service %s not found", serviceName)
59+
}
60+
releaseService, ok := component.(internal.ReleaseService)
61+
if !ok {
62+
return fmt.Errorf("service %s is not a release service", serviceName)
63+
}
64+
output := outputFlag
65+
if output == "" {
66+
homeDir, err := internal.GetHomeDir()
67+
if err != nil {
68+
return fmt.Errorf("failed to get home directory: %w", err)
69+
}
70+
output = homeDir
71+
}
72+
location, err := internal.DownloadRelease(output, releaseService.ReleaseArtifact())
73+
if err != nil {
74+
return fmt.Errorf("failed to download release: %w", err)
75+
}
76+
fmt.Println(location)
77+
return nil
78+
},
79+
}
80+
4881
var recipes = []internal.Recipe{
4982
&internal.L1Recipe{},
5083
&internal.OpRecipe{},
@@ -75,7 +108,12 @@ func main() {
75108
cookCmd.AddCommand(recipeCmd)
76109
}
77110

111+
// reuse the same output flag for the artifacts command
112+
artifactsCmd.Flags().StringVar(&outputFlag, "output", "", "Output folder for the artifacts")
113+
78114
rootCmd.AddCommand(cookCmd)
115+
rootCmd.AddCommand(artifactsCmd)
116+
79117
if err := rootCmd.Execute(); err != nil {
80118
fmt.Println(err)
81119
os.Exit(1)

0 commit comments

Comments
 (0)