Skip to content
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

[BUG]: Fixed docker start command bug #1586

Merged
merged 58 commits into from
May 21, 2024

Conversation

Yaxhveer
Copy link
Contributor

@Yaxhveer Yaxhveer commented Feb 16, 2024

Related Issue

  • Info about Issue or bug

Closes: #1539

Describe the changes you've made

Users can use docker start command to start the application. One have to specify the network and container name of the application using --networkName and --containerName tags.

Type of change

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Code style update (formatting, local variables)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • This change requires a documentation update

Please let us know if any test cases are added

Please describe the tests(if any). Provide instructions how its affecting the coverage.

Describe if there is any unusual behaviour of your code(Write NA if there isn't)

A clear and concise description of it.

Checklist:

  • My code follows the style guidelines of this project.
  • I have performed a self-review of my own code.
  • I have commented my code, particularly in hard-to-understand areas.
  • I have made corresponding changes to the documentation.
  • My changes generate no new warnings.
  • I have added tests that prove my fix is effective or that my feature works.
  • New and existing unit tests pass locally with my changes.

Screenshots (if any)

Original Updated
original screenshot updated screenshot

@Yaxhveer
Copy link
Contributor Author

@charankamarapu Kindly review this PR.

@charankamarapu
Copy link
Member

will review by 20 Feb EOD.

Yaxhveer and others added 7 commits February 19, 2024 23:41
Signed-off-by: Yaxhveer <yaxhcod@gmail.com>
Signed-off-by: Yaxhveer <yaxhcod@gmail.com>
Signed-off-by: Yaxhveer <yaxhcod@gmail.com>
Signed-off-by: Yaxhveer <yaxhcod@gmail.com>
Signed-off-by: Yaxhveer <yaxhcod@gmail.com>
Yaxhveer and others added 3 commits February 20, 2024 20:17
Signed-off-by: Yaxhveer <yaxhcod@gmail.com>
Signed-off-by: Yaxhveer <yaxhcod@gmail.com>
@charankamarapu
Copy link
Member

Hey @Yaxhveer are the changes done or anything let over..?

@Yaxhveer
Copy link
Contributor Author

@charankamarapu Yes they are done.

Copy link
Member

@charankamarapu charankamarapu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please address the comments.

if !initialisedValues.AbortStopHooksForcefully {
initialisedValues.AbortStopHooksInterrupt <- true
// stop listening for the eBPF events
initialisedValues.LoadedHooks.Stop(true)
initialisedValues.LoadedHooks.Stop(true, removeContainer)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not a preferred approach, We shouldn't signal things from service layer a lot.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Refactored

@@ -10,7 +10,7 @@ type InternalDockerClient interface {
ExtractNetworksForContainer(containerName string) (map[string]*network.EndpointSettings, error)
ConnectContainerToNetworks(containerName string, settings map[string]*network.EndpointSettings) error
ConnectContainerToNetworksByNames(containerName string, networkName []string) error
StopAndRemoveDockerContainer() error
StopDockerContainer(removeContainer bool) error
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

try to keep the same function and and use some param like skipRemove. It will be good if this skipRemove is give by hooks only and service shouldn't give this param to hooks and hooks to internalDockerClient.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Refactored

Yaxhveer and others added 7 commits February 22, 2024 11:17
Signed-off-by: Yaxhveer <yaxhcod@gmail.com>
Signed-off-by: Yaxhveer <yaxhcod@gmail.com>
Signed-off-by: Yaxhveer <yaxhcod@gmail.com>
Signed-off-by: Yaxhveer <yaxhcod@gmail.com>
Signed-off-by: Yaxhveer <yaxhcod@gmail.com>
Signed-off-by: Yaxhveer <yaxhcod@gmail.com>
Yaxhveer and others added 2 commits February 23, 2024 18:32
Signed-off-by: Yaxhveer <yaxhcod@gmail.com>
@Yaxhveer
Copy link
Contributor Author

Yaxhveer commented Feb 24, 2024

Hey @charankamarapu
Just wanted to clarify that here we are checking if command is docker related or not, since in docker start as well in docker detached mode the process is exited but still we have to remove the container.

@charankamarapu
Copy link
Member

charankamarapu commented Feb 28, 2024

The main idea is we have return to a previous state where user didn't use keploy. Like if the container was created before running keploy we shouldn't remove it after running with keploy. If keploy has created that container for him then we should remove it.

@Yaxhveer
Copy link
Contributor Author

Yaxhveer commented Feb 28, 2024

@charankamarapu Yes for the same logic we check if the command uses docker start or not. Also please review the changes and let me know if the implementation works.

gouravkrosx and others added 8 commits April 20, 2024 20:54
Signed-off-by: Yaxhveer <yaxhcod@gmail.com>
Signed-off-by: Yaxhveer <yaxhcod@gmail.com>
Signed-off-by: Yaxhveer <yaxhcod@gmail.com>
Signed-off-by: Yaxhveer <yaxhcod@gmail.com>
Signed-off-by: Yaxhveer <yaxhcod@gmail.com>
@Yaxhveer
Copy link
Contributor Author

@gouravkrosx Please review the changes.

@gouravkrosx
Copy link
Member

@Yaxhveer, I will try to review this EOD.

Signed-off-by: Yaxhveer <yaxhcod@gmail.com>
@Yaxhveer
Copy link
Contributor Author

@gouravkrosx Reminder! Review for the PR is pending.

@@ -69,12 +69,13 @@ func (a *App) Setup(_ context.Context) error {
}
a.docker = d

if (a.kind == utils.Docker || a.kind == utils.DockerCompose) && IsDetachMode(a.cmd) {
return fmt.Errorf("detach mode is not allowed in Keploy command")
if (a.kind == utils.DockerStart || a.kind == utils.DockerRun || a.kind == utils.DockerCompose) && isDetachMode(a.logger, a.cmd, a.kind) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

rather than this use a separate function for eg:

func isDockerKind(kind utils.CmdType) bool {
    return kind == utils.DockerStart || kind == utils.DockerRun || kind == utils.DockerCompose
}

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

Signed-off-by: Yaxhveer <yaxhcod@gmail.com>
@@ -339,7 +339,7 @@ func (r *Replayer) RunTestSet(ctx context.Context, testSetID string, testRunID s

cmdType := utils.FindDockerCmd(r.config.Command)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of using this function utils.FindDockerCmd() Can you please take the cmdType from r.Config.CommandType where it is being used.

Signed-off-by: Yaxhveer <yaxhcod@gmail.com>
@@ -349,7 +349,7 @@ func (r *Recorder) ReRecord(ctx context.Context, appID uint64) error {

}
cmdType := utils.FindDockerCmd(r.config.Command)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here also

Yaxhveer and others added 2 commits May 21, 2024 12:38
Signed-off-by: Yaxhveer <yaxhcod@gmail.com>
@gouravkrosx gouravkrosx self-requested a review May 21, 2024 07:48
@@ -117,6 +119,16 @@ func (a *App) SetupDocker() error {
a.logger.Warn(fmt.Sprintf("given docker network:(%v) is different from parsed docker network:(%v)", a.containerNetwork, net))
}

if a.kind == utils.DockerStart {
running, err := a.docker.IsContainerRunning(a.container)
Copy link
Member

@gouravkrosx gouravkrosx May 21, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Even if the given container is different from the parsed container, we should provide the parsed container. i.e cont here. We are already logging a warning msg.

running, err := a.docker.IsContainerRunning(a.container)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

corrected

Signed-off-by: Yaxhveer <yaxhcod@gmail.com>
Copy link
Member

@gouravkrosx gouravkrosx left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@gouravkrosx gouravkrosx merged commit 8f0abd6 into keploy:main May 21, 2024
18 checks passed
@github-actions github-actions bot locked and limited conversation to collaborators May 21, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[bug]: Keploy fails with "docker start <container>" as user app command
5 participants