-
Notifications
You must be signed in to change notification settings - Fork 9
feat: forward brick container ports #296
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
base: main
Are you sure you want to change the base?
Changes from all commits
ca24ca8
a2514ad
bde542e
be51851
fd19bc8
1ffa99f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -16,14 +16,14 @@ | |
| package bricksindex | ||
|
|
||
| import ( | ||
| "io" | ||
| "iter" | ||
| "slices" | ||
| "strings" | ||
|
|
||
| "github.com/arduino/go-paths-helper" | ||
| yaml "github.com/goccy/go-yaml" | ||
|
|
||
| "github.com/arduino/arduino-app-cli/internal/orchestrator/peripherals" | ||
| "github.com/arduino/arduino-app-cli/internal/store" | ||
| ) | ||
|
|
||
| type BricksIndex struct { | ||
|
|
@@ -65,6 +65,8 @@ type Brick struct { | |
| ModelName string `yaml:"model_name,omitempty"` | ||
| MountDevicesIntoContainer bool `yaml:"mount_devices_into_container,omitempty"` | ||
| RequiredDevices []peripherals.DeviceClass `yaml:"required_devices,omitempty"` | ||
|
|
||
| containerPorts []string `yaml:"-"` | ||
| } | ||
|
|
||
| func (b Brick) GetVariable(name string) (BrickVariable, bool) { | ||
|
|
@@ -87,19 +89,64 @@ func (b Brick) GetDefaultVariables() iter.Seq2[string, string] { | |
| } | ||
| } | ||
|
|
||
| func unmarshalBricksIndex(content io.Reader) (*BricksIndex, error) { | ||
| var index BricksIndex | ||
| if err := yaml.NewDecoder(content).Decode(&index); err != nil { | ||
| return nil, err | ||
| } | ||
| return &index, nil | ||
| func (b Brick) GetPorts() []string { | ||
| ports := make([]string, 0, len(b.Ports)+len(b.containerPorts)) | ||
| ports = append(ports, b.Ports...) | ||
| ports = append(ports, b.containerPorts...) | ||
| slices.Sort(ports) | ||
| return slices.Compact(ports) | ||
| } | ||
|
|
||
| func Load(dir *paths.Path) (*BricksIndex, error) { | ||
| content, err := dir.Join("bricks-list.yaml").Open() | ||
| func Load(staticstore *store.StaticStore) (*BricksIndex, error) { | ||
| content, err := staticstore.GetAssetsFolder().Join("bricks-list.yaml").Open() | ||
| if err != nil { | ||
| return nil, err | ||
| } | ||
| defer content.Close() | ||
| return unmarshalBricksIndex(content) | ||
|
|
||
| var index BricksIndex | ||
| if err := yaml.NewDecoder(content).Decode(&index); err != nil { | ||
| return nil, err | ||
| } | ||
|
|
||
| // Parse the compose file to read the extra ports. | ||
| for i := range index.Bricks { | ||
| composeFilePath, err := staticstore.GetBrickComposeFilePathFromID(index.Bricks[i].ID) | ||
| if err != nil { | ||
| return nil, err | ||
| } | ||
|
|
||
| if !index.Bricks[i].RequireContainer || composeFilePath.NotExist() { | ||
| continue | ||
| } | ||
|
|
||
| f, err := composeFilePath.Open() | ||
| if err != nil { | ||
| return nil, err | ||
| } | ||
| defer f.Close() | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. having a defer f.Close() inside the loop causes many pending f.Close() at the same time, since the defer will be called at the end of Load(). |
||
|
|
||
| var compose struct { | ||
| Services map[string]struct { | ||
| Ports []string `yaml:"ports,omitempty"` | ||
| } `yaml:"services"` | ||
| } | ||
| if err := yaml.NewDecoder(f).Decode(&compose); err != nil { | ||
| return nil, err | ||
| } | ||
|
|
||
| for _, service := range compose.Services { | ||
| for _, portStr := range service.Ports { | ||
| if strings.Contains(portStr, ":") { | ||
| parts := strings.Split(portStr, ":") | ||
| hostPort := parts[len(parts)-2] // Extract the host port (the one before the last colon) | ||
| index.Bricks[i].containerPorts = append(index.Bricks[i].containerPorts, hostPort) | ||
| } else { | ||
| index.Bricks[i].containerPorts = append(index.Bricks[i].containerPorts, portStr) | ||
| } | ||
| } | ||
|
Comment on lines
+140
to
+147
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I would add a unit test for the port parsing |
||
| } | ||
| } | ||
|
|
||
| return &index, nil | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am ok to remove the webview from the app.yaml definition.
Having this change, it is not possible to define a port in the app.yaml with webview behaviour.
It is only possible to set it from the brick definition.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree. I think we have a bigger problem here.
requires_displayin thebrick_config.yamlis at the root level. If you have multiple ports, it's not clear which one should be opened.app.yamlfile.It would be nice to have the "port type" (which includes the concept of "requires display") for each port, and make it work the same both in
brick_config.yamlandapp.yaml.Something like (see comments):