mirror of
https://github.com/containrrr/watchtower.git
synced 2025-09-22 05:40:50 +02:00
Wait for container stop after kill
This commit is contained in:
parent
13ec7ac94e
commit
1f460997cb
2 changed files with 32 additions and 0 deletions
|
@ -4,6 +4,7 @@ import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"log"
|
"log"
|
||||||
"strings"
|
"strings"
|
||||||
|
"time"
|
||||||
|
|
||||||
"github.com/samalba/dockerclient"
|
"github.com/samalba/dockerclient"
|
||||||
)
|
)
|
||||||
|
@ -104,6 +105,22 @@ func (client DockerClient) Stop(c Container) error {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Wait for container to exit, but proceed anyway after 10 seconds
|
||||||
|
timeout := time.After(10 * time.Second)
|
||||||
|
PollLoop:
|
||||||
|
for {
|
||||||
|
select {
|
||||||
|
case <-timeout:
|
||||||
|
break PollLoop
|
||||||
|
default:
|
||||||
|
ci, err := client.api.InspectContainer(c.containerInfo.Id)
|
||||||
|
if err != nil || !ci.State.Running {
|
||||||
|
break PollLoop
|
||||||
|
}
|
||||||
|
time.Sleep(1 * time.Second)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return client.api.RemoveContainer(c.containerInfo.Id, true, false)
|
return client.api.RemoveContainer(c.containerInfo.Id, true, false)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -164,8 +164,15 @@ func TestStop_DefaultSuccess(t *testing.T) {
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ci := &dockerclient.ContainerInfo{
|
||||||
|
State: &dockerclient.State{
|
||||||
|
Running: false,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
api := mockclient.NewMockClient()
|
api := mockclient.NewMockClient()
|
||||||
api.On("KillContainer", "abc123", "SIGTERM").Return(nil)
|
api.On("KillContainer", "abc123", "SIGTERM").Return(nil)
|
||||||
|
api.On("InspectContainer", "abc123").Return(ci, nil)
|
||||||
api.On("RemoveContainer", "abc123", true, false).Return(nil)
|
api.On("RemoveContainer", "abc123", true, false).Return(nil)
|
||||||
|
|
||||||
client := DockerClient{api: api}
|
client := DockerClient{api: api}
|
||||||
|
@ -185,8 +192,15 @@ func TestStop_CustomSignalSuccess(t *testing.T) {
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ci := &dockerclient.ContainerInfo{
|
||||||
|
State: &dockerclient.State{
|
||||||
|
Running: false,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
api := mockclient.NewMockClient()
|
api := mockclient.NewMockClient()
|
||||||
api.On("KillContainer", "abc123", "SIGUSR1").Return(nil)
|
api.On("KillContainer", "abc123", "SIGUSR1").Return(nil)
|
||||||
|
api.On("InspectContainer", "abc123").Return(ci, nil)
|
||||||
api.On("RemoveContainer", "abc123", true, false).Return(nil)
|
api.On("RemoveContainer", "abc123", true, false).Return(nil)
|
||||||
|
|
||||||
client := DockerClient{api: api}
|
client := DockerClient{api: api}
|
||||||
|
@ -227,6 +241,7 @@ func TestStop_RemoveContainerError(t *testing.T) {
|
||||||
|
|
||||||
api := mockclient.NewMockClient()
|
api := mockclient.NewMockClient()
|
||||||
api.On("KillContainer", "abc123", "SIGTERM").Return(nil)
|
api.On("KillContainer", "abc123", "SIGTERM").Return(nil)
|
||||||
|
api.On("InspectContainer", "abc123").Return(&dockerclient.ContainerInfo{}, errors.New("dangit"))
|
||||||
api.On("RemoveContainer", "abc123", true, false).Return(errors.New("whoops"))
|
api.On("RemoveContainer", "abc123", true, false).Return(errors.New("whoops"))
|
||||||
|
|
||||||
client := DockerClient{api: api}
|
client := DockerClient{api: api}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue