-
Notifications
You must be signed in to change notification settings - Fork 123
Add container functionality, add initial dashboard start functionality #2785
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
Merged
FilipRudy
merged 6 commits into
kyma-project:main
from
FilipRudy:add-container-struct-and-methods
Dec 17, 2025
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
4cdaf95
add container functionality, add initial dashboard start functionality
FilipRudy 13e51c3
fix out. usage
FilipRudy bb133b5
apply code suggestions for review, remove kubeconfig variable
FilipRudy e95e533
update docs
FilipRudy 829f845
apply suggestions from code review, refactor docker package
FilipRudy 0d35602
Apply suggestions from code review
FilipRudy File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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,87 @@ | ||
| package busola | ||
|
|
||
| import ( | ||
| "context" | ||
| "fmt" | ||
|
|
||
| "github.com/docker/docker/api/types/container" | ||
| "github.com/kyma-project/cli.v3/internal/docker" | ||
| "github.com/kyma-project/cli.v3/internal/out" | ||
| "github.com/pkg/browser" | ||
| ) | ||
|
|
||
| const ( | ||
| dashboardImage = "europe-docker.pkg.dev/kyma-project/prod/kyma-dashboard-local-prod:latest" | ||
| ) | ||
|
|
||
| // Container is a wrapper around the kyma dashboard docker container, providing an easy to use API to manage the kyam dashboard. | ||
| type Container struct { | ||
| name string | ||
| id string | ||
| port string | ||
| docker *docker.Client | ||
| verbose bool | ||
| } | ||
|
|
||
| // New creates a new dashboard container with the given configuration | ||
| func New(name, port string, verbose bool) (*Container, error) { | ||
| dockerClient, err := docker.NewClient() | ||
| if err != nil { | ||
| return nil, fmt.Errorf("could not create docker client: %w", err) | ||
| } | ||
|
|
||
| return &Container{ | ||
| name: name, | ||
| port: port, | ||
| docker: dockerClient, | ||
| verbose: verbose, | ||
| }, nil | ||
| } | ||
|
|
||
| // Start runs the dashboard container. | ||
| func (c *Container) Start() error { | ||
| var envs []string | ||
|
|
||
| opts := c.containerOpts(envs) | ||
| out.Msg("\n") | ||
|
|
||
| var err error | ||
| if c.id, err = c.docker.PullImageAndStartContainer(context.Background(), opts); err != nil { | ||
| return fmt.Errorf("unable to start container: %w", err) | ||
| } | ||
| return nil | ||
| } | ||
|
|
||
| // Opens the kyma dashboard in a browser. | ||
| func (c *Container) Open(path string) error { | ||
| url := fmt.Sprintf("http://localhost:%s%s/clusters", c.port, path) | ||
|
|
||
| err := browser.OpenURL(url) | ||
| if err != nil { | ||
| return fmt.Errorf("dashboard at %q could not be opened: %w", url, err) | ||
| } | ||
| return nil | ||
| } | ||
|
|
||
| // Watch attaches to the running docker container and forwards its output. | ||
| func (c *Container) Watch(ctx context.Context) error { | ||
| return c.docker.ContainerFollowRun(ctx, c.id, c.verbose) | ||
| } | ||
|
|
||
| // Stop stops the dashboard container. | ||
| func (c *Container) Stop(ctx context.Context) error { | ||
| return c.docker.ContainerStop(ctx, c.id, container.StopOptions{}) | ||
| } | ||
|
|
||
| func (c *Container) containerOpts(envs []string) docker.ContainerRunOpts { | ||
| containerRunOpts := docker.ContainerRunOpts{ | ||
| Envs: envs, | ||
| ContainerName: c.name, | ||
| Image: dashboardImage, | ||
| Ports: map[string]string{ | ||
| "3001": c.port, | ||
| }, | ||
| } | ||
|
|
||
| return containerRunOpts | ||
| } | ||
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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,32 @@ | ||
| package docker | ||
|
|
||
| import ( | ||
| "context" | ||
| "io" | ||
|
|
||
| "github.com/docker/docker/api/types/container" | ||
| "github.com/docker/docker/pkg/stdcopy" | ||
| "github.com/kyma-project/cli.v3/internal/out" | ||
| ) | ||
|
|
||
| func (c *Client) ContainerFollowRun(ctx context.Context, containerID string, forwardOutput bool) error { | ||
| buf, err := c.ContainerAttach(ctx, containerID, container.AttachOptions{ | ||
| Stdout: true, | ||
| Stderr: true, | ||
| Stream: true, | ||
| }) | ||
| if err != nil { | ||
| return err | ||
| } | ||
| defer buf.Close() | ||
|
|
||
| dstout, dsterr := io.Discard, io.Discard | ||
| if forwardOutput { | ||
| dstout = out.Default.MsgWriter() | ||
| dsterr = out.Default.ErrWriter() | ||
| } | ||
|
|
||
| _, err = stdcopy.StdCopy(dstout, dsterr, buf.Reader) | ||
|
|
||
| return err | ||
| } |
This file contains hidden or 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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.