Skip to content

Commit de2eb70

Browse files
authored
Unify components and recipes (#227)
This PR consolidates the interfaces for recipes and components by having both operate directly on manifests rather than returning services/manifests. This simplifies the architecture and makes the system more composable. Previously, recipes and components had different interfaces for modifying manifests: - Recipes: Accepted an ExContext and Artifacts, returned a complete Manifest - Components: Accepted a Service reference and ExContext, modified the service in-place This distinction created unnecessary complexity since both are fundamentally doing the same thing: configuring and adding services to a manifest. The only real difference is that recipes are public CLI entry points while components are internal execution units - but this semantic difference doesn't justify different technical interfaces.
1 parent acfda87 commit de2eb70

File tree

13 files changed

+216
-375
lines changed

13 files changed

+216
-375
lines changed

.github/workflows/checks.yaml

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -49,21 +49,3 @@ jobs:
4949
name: playground-logs-${{ matrix.flags }}
5050
path: /tmp/playground-logs
5151
retention-days: 5
52-
53-
artifacts:
54-
name: Artifacts
55-
strategy:
56-
matrix:
57-
os: [ubuntu-latest, macos-latest]
58-
runs-on: ${{ matrix.os }}
59-
steps:
60-
- name: Check out code
61-
uses: actions/checkout@v2
62-
63-
- name: Set up Go
64-
uses: actions/setup-go@v2
65-
with:
66-
go-version: 1.24
67-
68-
- name: Download and test artifacts
69-
run: go run main.go artifacts-all

main.go

Lines changed: 5 additions & 76 deletions
Original file line numberDiff line numberDiff line change
@@ -57,73 +57,6 @@ var cookCmd = &cobra.Command{
5757
},
5858
}
5959

60-
var artifactsCmd = &cobra.Command{
61-
Use: "artifacts",
62-
Short: "List available artifacts",
63-
RunE: func(cmd *cobra.Command, args []string) error {
64-
if len(args) != 1 {
65-
return fmt.Errorf("please specify a service name")
66-
}
67-
serviceName := args[0]
68-
component := playground.FindComponent(serviceName)
69-
if component == nil {
70-
return fmt.Errorf("service %s not found", serviceName)
71-
}
72-
releaseService, ok := component.(playground.ReleaseService)
73-
if !ok {
74-
return fmt.Errorf("service %s is not a release service", serviceName)
75-
}
76-
output := outputFlag
77-
if output == "" {
78-
homeDir, err := playground.GetHomeDir()
79-
if err != nil {
80-
return fmt.Errorf("failed to get home directory: %w", err)
81-
}
82-
output = homeDir
83-
}
84-
location, err := playground.DownloadRelease(output, releaseService.ReleaseArtifact())
85-
if err != nil {
86-
return fmt.Errorf("failed to download release: %w", err)
87-
}
88-
fmt.Println(location)
89-
return nil
90-
},
91-
}
92-
93-
var artifactsAllCmd = &cobra.Command{
94-
Use: "artifacts-all",
95-
Short: "Download all the artifacts available in the catalog (Used for testing purposes)",
96-
RunE: func(cmd *cobra.Command, args []string) error {
97-
fmt.Println("Downloading all artifacts...")
98-
99-
output := outputFlag
100-
if output == "" {
101-
homeDir, err := playground.GetHomeDir()
102-
if err != nil {
103-
return fmt.Errorf("failed to get home directory: %w", err)
104-
}
105-
output = homeDir
106-
}
107-
for _, component := range playground.Components {
108-
releaseService, ok := component.(playground.ReleaseService)
109-
if !ok {
110-
continue
111-
}
112-
location, err := playground.DownloadRelease(output, releaseService.ReleaseArtifact())
113-
if err != nil {
114-
return fmt.Errorf("failed to download release: %w", err)
115-
}
116-
117-
// make sure the artifact is valid to be executed on this platform
118-
log.Printf("Downloaded %s to %s\n", releaseService.ReleaseArtifact().Name, location)
119-
if err := isExecutableValid(location); err != nil {
120-
return fmt.Errorf("failed to check if artifact is valid: %w", err)
121-
}
122-
}
123-
return nil
124-
},
125-
}
126-
12760
var inspectCmd = &cobra.Command{
12861
Use: "inspect",
12962
Short: "Inspect a connection between two services",
@@ -192,15 +125,9 @@ func main() {
192125
cookCmd.AddCommand(recipeCmd)
193126
}
194127

195-
// reuse the same output flag for the artifacts command
196-
artifactsCmd.Flags().StringVar(&outputFlag, "output", "", "Output folder for the artifacts")
197-
artifactsAllCmd.Flags().StringVar(&outputFlag, "output", "", "Output folder for the artifacts")
198-
199128
cmd.InitWaitReadyCmd()
200129

201130
rootCmd.AddCommand(cookCmd)
202-
rootCmd.AddCommand(artifactsCmd)
203-
rootCmd.AddCommand(artifactsAllCmd)
204131
rootCmd.AddCommand(inspectCmd)
205132
rootCmd.AddCommand(cmd.WaitReadyCmd)
206133

@@ -236,15 +163,17 @@ func runIt(recipe playground.Recipe) error {
236163
return err
237164
}
238165

239-
// if contender.tps is set, assume contender is enabled
240-
svcManager := recipe.Apply(&playground.ExContext{
166+
exCtx := &playground.ExContext{
241167
LogLevel: logLevel,
168+
// if contender.tps is set, assume contender is enabled
242169
Contender: &playground.ContenderContext{
243170
Enabled: contenderEnabled,
244171
ExtraArgs: contenderArgs,
245172
TargetChain: contenderTarget,
246173
},
247-
}, artifacts)
174+
}
175+
svcManager := playground.NewManifest(exCtx, artifacts.Out)
176+
recipe.Apply(svcManager)
248177
if err := svcManager.Validate(); err != nil {
249178
return fmt.Errorf("failed to validate manifest: %w", err)
250179
}

playground/catalog.go

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -28,12 +28,3 @@ func init() {
2828
register(&BProxy{})
2929
register(&WebsocketProxy{})
3030
}
31-
32-
func FindComponent(name string) ServiceGen {
33-
for _, component := range Components {
34-
if component.Name() == name {
35-
return component
36-
}
37-
}
38-
return nil
39-
}

playground/catalog_test.go

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
package playground
2+
3+
import (
4+
"testing"
5+
6+
"github.com/stretchr/testify/require"
7+
)
8+
9+
func TestCatalogReleases(t *testing.T) {
10+
out := newTestOutput(t)
11+
12+
tests := []*release{
13+
opRethRelease,
14+
rethELRelease,
15+
}
16+
17+
for _, tc := range tests {
18+
_, err := DownloadRelease(out.dst, tc)
19+
require.NoError(t, err)
20+
}
21+
}

0 commit comments

Comments
 (0)