mirror of https://github.com/docker/compose.git
Merge pull request #8638 from ulyssessouza/fix-ctrl-c-2x-deps
Stop only the service ran by it's up command
This commit is contained in:
commit
aa4b01212e
|
@ -175,6 +175,7 @@ func runUp(ctx context.Context, backend api.Service, createOptions createOptions
|
|||
}
|
||||
|
||||
create := api.CreateOptions{
|
||||
Services: services,
|
||||
RemoveOrphans: createOptions.removeOrphans,
|
||||
Recreate: createOptions.recreateStrategy(),
|
||||
RecreateDependencies: createOptions.dependenciesRecreateStrategy(),
|
||||
|
|
|
@ -186,6 +186,8 @@ type ImagesOptions struct {
|
|||
|
||||
// KillOptions group options of the Kill API
|
||||
type KillOptions struct {
|
||||
// Services passed in the command line to be killed
|
||||
Services []string
|
||||
// Signal to send to containers
|
||||
Signal string
|
||||
}
|
||||
|
|
|
@ -36,8 +36,13 @@ func (s *composeService) Kill(ctx context.Context, project *types.Project, optio
|
|||
func (s *composeService) kill(ctx context.Context, project *types.Project, options api.KillOptions) error {
|
||||
w := progress.ContextWriter(ctx)
|
||||
|
||||
services := options.Services
|
||||
if len(services) == 0 {
|
||||
services = project.ServiceNames()
|
||||
}
|
||||
|
||||
var containers Containers
|
||||
containers, err := s.getContainers(ctx, project.Name, oneOffInclude, true)
|
||||
containers, err := s.getContainers(ctx, project.Name, oneOffInclude, true, services...)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
|
|
@ -56,18 +56,24 @@ func TestKillAll(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestKillSignal(t *testing.T) {
|
||||
const serviceName = "service1"
|
||||
mockCtrl := gomock.NewController(t)
|
||||
defer mockCtrl.Finish()
|
||||
api := mocks.NewMockAPIClient(mockCtrl)
|
||||
tested.apiClient = api
|
||||
|
||||
project := types.Project{Name: strings.ToLower(testProject), Services: []types.ServiceConfig{testService("service1")}}
|
||||
project := types.Project{Name: strings.ToLower(testProject), Services: []types.ServiceConfig{testService(serviceName)}}
|
||||
listOptions := moby.ContainerListOptions{
|
||||
Filters: filters.NewArgs(projectFilter(strings.ToLower(testProject)),
|
||||
serviceFilter(serviceName)),
|
||||
All: true,
|
||||
}
|
||||
|
||||
ctx := context.Background()
|
||||
api.EXPECT().ContainerList(ctx, projectFilterListOpt()).Return([]moby.Container{testContainer("service1", "123", false)}, nil)
|
||||
api.EXPECT().ContainerList(ctx, listOptions).Return([]moby.Container{testContainer(serviceName, "123", false)}, nil)
|
||||
api.EXPECT().ContainerKill(anyCancellableContext(), "123", "SIGTERM").Return(nil)
|
||||
|
||||
err := tested.kill(ctx, &project, compose.KillOptions{Signal: "SIGTERM"})
|
||||
err := tested.kill(ctx, &project, compose.KillOptions{Services: []string{serviceName}, Signal: "SIGTERM"})
|
||||
assert.NilError(t, err)
|
||||
}
|
||||
|
||||
|
|
|
@ -60,10 +60,14 @@ func (s *composeService) Up(ctx context.Context, project *types.Project, options
|
|||
return progress.Run(ctx, func(ctx context.Context) error {
|
||||
go func() {
|
||||
<-signalChan
|
||||
s.Kill(ctx, project, api.KillOptions{}) // nolint:errcheck
|
||||
s.Kill(ctx, project, api.KillOptions{ // nolint:errcheck
|
||||
Services: options.Create.Services,
|
||||
})
|
||||
}()
|
||||
|
||||
return s.Stop(ctx, project, api.StopOptions{})
|
||||
return s.Stop(ctx, project, api.StopOptions{
|
||||
Services: options.Create.Services,
|
||||
})
|
||||
})
|
||||
}
|
||||
go func() {
|
||||
|
|
Loading…
Reference in New Issue