mirror of
https://github.com/docker/compose.git
synced 2025-07-23 05:34:36 +02:00
handle "stop" event
Signed-off-by: Nicolas De Loof <nicolas.deloof@gmail.com>
This commit is contained in:
parent
40bca10250
commit
740276f550
@ -14,7 +14,7 @@
|
|||||||
limitations under the License.
|
limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package main
|
package compatibility
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
@ -43,7 +43,7 @@ func getStringFlags() []string {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func convert(args []string) []string {
|
func Convert(args []string) []string {
|
||||||
var rootFlags []string
|
var rootFlags []string
|
||||||
command := []string{compose.PluginName}
|
command := []string{compose.PluginName}
|
||||||
l := len(args)
|
l := len(args)
|
@ -14,7 +14,7 @@
|
|||||||
limitations under the License.
|
limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package main
|
package compatibility
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"testing"
|
"testing"
|
||||||
@ -71,7 +71,7 @@ func Test_convert(t *testing.T) {
|
|||||||
}
|
}
|
||||||
for _, tt := range tests {
|
for _, tt := range tests {
|
||||||
t.Run(tt.name, func(t *testing.T) {
|
t.Run(tt.name, func(t *testing.T) {
|
||||||
got := convert(tt.args)
|
got := Convert(tt.args)
|
||||||
assert.DeepEqual(t, tt.want, got)
|
assert.DeepEqual(t, tt.want, got)
|
||||||
})
|
})
|
||||||
}
|
}
|
@ -25,6 +25,7 @@ import (
|
|||||||
"github.com/docker/cli/cli/command"
|
"github.com/docker/cli/cli/command"
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
|
|
||||||
|
"github.com/docker/compose/v2/cmd/compatibility"
|
||||||
commands "github.com/docker/compose/v2/cmd/compose"
|
commands "github.com/docker/compose/v2/cmd/compose"
|
||||||
"github.com/docker/compose/v2/internal"
|
"github.com/docker/compose/v2/internal"
|
||||||
"github.com/docker/compose/v2/pkg/api"
|
"github.com/docker/compose/v2/pkg/api"
|
||||||
@ -68,7 +69,7 @@ func pluginMain() {
|
|||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
if commands.RunningAsStandalone() {
|
if commands.RunningAsStandalone() {
|
||||||
os.Args = append([]string{"docker"}, convert(os.Args[1:])...)
|
os.Args = append([]string{"docker"}, compatibility.Convert(os.Args[1:])...)
|
||||||
}
|
}
|
||||||
pluginMain()
|
pluginMain()
|
||||||
}
|
}
|
||||||
|
@ -436,6 +436,8 @@ const (
|
|||||||
ContainerEventLog = iota
|
ContainerEventLog = iota
|
||||||
// ContainerEventAttach is a ContainerEvent of type attach. First event sent about a container
|
// ContainerEventAttach is a ContainerEvent of type attach. First event sent about a container
|
||||||
ContainerEventAttach
|
ContainerEventAttach
|
||||||
|
// ContainerEventStopped is a ContainerEvent of type stopped.
|
||||||
|
ContainerEventStopped
|
||||||
// ContainerEventExit is a ContainerEvent of type exit. ExitCode is set
|
// ContainerEventExit is a ContainerEvent of type exit. ExitCode is set
|
||||||
ContainerEventExit
|
ContainerEventExit
|
||||||
// UserCancel user cancelled compose up, we are stopping containers
|
// UserCancel user cancelled compose up, we are stopping containers
|
||||||
|
@ -79,7 +79,7 @@ func (p *printer) Run(ctx context.Context, cascadeStop bool, exitCodeFrom string
|
|||||||
}
|
}
|
||||||
containers[container] = struct{}{}
|
containers[container] = struct{}{}
|
||||||
p.consumer.Register(container)
|
p.consumer.Register(container)
|
||||||
case api.ContainerEventExit:
|
case api.ContainerEventExit, api.ContainerEventStopped:
|
||||||
if !event.Restarting {
|
if !event.Restarting {
|
||||||
delete(containers, container)
|
delete(containers, container)
|
||||||
}
|
}
|
||||||
|
@ -111,6 +111,21 @@ func (s *composeService) watchContainers(ctx context.Context, projectName string
|
|||||||
}
|
}
|
||||||
name := getContainerNameWithoutProject(container)
|
name := getContainerNameWithoutProject(container)
|
||||||
|
|
||||||
|
if event.Status == "stop" {
|
||||||
|
listener(api.ContainerEvent{
|
||||||
|
Type: api.ContainerEventStopped,
|
||||||
|
Container: name,
|
||||||
|
Service: container.Labels[api.ServiceLabel],
|
||||||
|
})
|
||||||
|
|
||||||
|
delete(watched, container.ID)
|
||||||
|
if len(watched) == 0 {
|
||||||
|
// all project containers stopped, we're done
|
||||||
|
stop()
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
if event.Status == "die" {
|
if event.Status == "die" {
|
||||||
restarted := watched[container.ID]
|
restarted := watched[container.ID]
|
||||||
watched[container.ID] = restarted + 1
|
watched[container.ID] = restarted + 1
|
||||||
|
Loading…
x
Reference in New Issue
Block a user