-
-
Notifications
You must be signed in to change notification settings - Fork 384
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
stop and remove docker container #874
Conversation
CLA Assistant Lite bot All contributors have signed the CLA ✍️ ✅ |
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.
Thank you and congratulations 🎉 for opening your very first pull request in keploy
I have read the CLA Document and I hereby sign the CLA |
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.
Please resolve the mentioned issues
pkg/hooks/loader.go
Outdated
// StopUserApplication stops the user application | ||
func (h *Hook) StopUserApplication() { | ||
if h.userAppCmd != nil && h.userAppCmd.Process != nil { | ||
h.logger.Debug("the process state for the user process", zap.String("state", h.userAppCmd.ProcessState.String()), zap.Any("processState", h.userAppCmd.ProcessState)) | ||
if h.userAppCmd.ProcessState != nil && h.userAppCmd.ProcessState.Exited() { | ||
return | ||
} | ||
|
||
// Stop Docker Container and Remove it | ||
h.StopAndRemoveDockerContainer() |
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.
we need to stop docker only if we know that application is ran via docker. In native case this function shouldn't be executed
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.
And also if the user runs container and gives the container name or id then also we shouldn't stop the container.
pkg/hooks/launch.go
Outdated
@@ -25,6 +25,12 @@ import ( | |||
"go.keploy.io/server/pkg/models" | |||
) | |||
|
|||
type DockerInfo struct { |
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.
This struct can be part of client package . Keeping it in this Package may cause circular dependency in future .
pkg/hooks/loader.go
Outdated
@@ -334,13 +342,48 @@ func (h *Hook) findAndCollectChildProcesses(parentPID string, pids *[]int) { | |||
} | |||
} | |||
|
|||
// Stop and Remove the docker container | |||
func (h *Hook) StopAndRemoveDockerContainer() { |
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.
This can be a function of dockerInfo struct or dockerClient instead of hooks. All docker related things can be moved to client package itself.
pkg/hooks/launch.go
Outdated
@@ -202,6 +210,7 @@ func (h *Hook) processDockerEnv(appCmd, appContainer, appNetwork string) error { | |||
case e := <-messages: | |||
if e.Type == events.ContainerEventType && e.Action == "create" { | |||
// Fetch container details by inspecting using container ID to check if container is created | |||
h.dockerDetails.containerID = e.ID |
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.
Use setter and getter functions instead of assigning it directly
pkg/hooks/loader.go
Outdated
|
||
container, err := dockerClient.ContainerInspect(context.Background(), containerID) | ||
if err != nil { | ||
fmt.Println(err) |
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.
Use logger instead of print statements
pkg/hooks/loader.go
Outdated
container, err := dockerClient.ContainerInspect(context.Background(), containerID) | ||
if err != nil { | ||
fmt.Println(err) | ||
return |
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.
why is err not being returned..?
pkg/hooks/loader.go
Outdated
|
||
err = dockerClient.ContainerRemove(context.Background(), containerID, removeOptions) | ||
if err != nil { | ||
fmt.Println(err) |
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.
Use log statements
Signed-off-by: 404fixer <govindtomar94@gmail.com>
Signed-off-by: 404fixer <govindtomar94@gmail.com>
59bfbee
to
ea5fd98
Compare
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.
Everything else looks good to me. Please correct the logger statement
// Stop Docker Container and Remove it if Keploy ran using docker | ||
if len(h.idc.GetContainerID()) != 0 { | ||
err := h.idc.StopAndRemoveDockerContainer() | ||
if err != 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.
This should be an error log saying failed to stop container/ remove container , zap the error and suggest user to delete it manually
Signed-off-by: 404fixer <govindtomar94@gmail.com>
Signed-off-by: 404fixer <govindtomar94@gmail.com>
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.
Ship it!
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.
LGTM
Closes: #708
Describe the changes you've made
Earlier after stopping keploy, it used to stop the docker container but not remove it. Now, the container will be stopped and removed.
Type of change
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: