|
@@ -19,7 +19,6 @@ package compose
|
|
|
import (
|
|
import (
|
|
|
"context"
|
|
"context"
|
|
|
"fmt"
|
|
"fmt"
|
|
|
- "os"
|
|
|
|
|
|
|
|
|
|
"github.com/compose-spec/compose-go/types"
|
|
"github.com/compose-spec/compose-go/types"
|
|
|
"github.com/docker/compose-cli/api/compose"
|
|
"github.com/docker/compose-cli/api/compose"
|
|
@@ -30,7 +29,7 @@ import (
|
|
|
moby "github.com/docker/docker/pkg/stringid"
|
|
moby "github.com/docker/docker/pkg/stringid"
|
|
|
)
|
|
)
|
|
|
|
|
|
|
|
-func (s *composeService) RunOneOffContainer(ctx context.Context, project *types.Project, opts compose.RunOptions) (string, error) {
|
|
|
|
|
|
|
+func (s *composeService) RunOneOffContainer(ctx context.Context, project *types.Project, opts compose.RunOptions) error {
|
|
|
originalServices := project.Services
|
|
originalServices := project.Services
|
|
|
var requestedService types.ServiceConfig
|
|
var requestedService types.ServiceConfig
|
|
|
for _, service := range originalServices {
|
|
for _, service := range originalServices {
|
|
@@ -53,16 +52,20 @@ func (s *composeService) RunOneOffContainer(ctx context.Context, project *types.
|
|
|
requestedService.Labels = requestedService.Labels.Add(oneoffLabel, "True")
|
|
requestedService.Labels = requestedService.Labels.Add(oneoffLabel, "True")
|
|
|
|
|
|
|
|
if err := s.waitDependencies(ctx, project, requestedService); err != nil {
|
|
if err := s.waitDependencies(ctx, project, requestedService); err != nil {
|
|
|
- return "", err
|
|
|
|
|
|
|
+ return err
|
|
|
}
|
|
}
|
|
|
if err := s.createContainer(ctx, project, requestedService, requestedService.ContainerName, 1, opts.AutoRemove); err != nil {
|
|
if err := s.createContainer(ctx, project, requestedService, requestedService.ContainerName, 1, opts.AutoRemove); err != nil {
|
|
|
- return "", err
|
|
|
|
|
|
|
+ return err
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
containerID := requestedService.ContainerName
|
|
containerID := requestedService.ContainerName
|
|
|
|
|
|
|
|
if opts.Detach {
|
|
if opts.Detach {
|
|
|
- return containerID, s.apiClient.ContainerStart(ctx, containerID, apitypes.ContainerStartOptions{})
|
|
|
|
|
|
|
+ err := s.apiClient.ContainerStart(ctx, containerID, apitypes.ContainerStartOptions{})
|
|
|
|
|
+ if err != nil {
|
|
|
|
|
+ return err
|
|
|
|
|
+ }
|
|
|
|
|
+ fmt.Fprintln(opts.Writer, containerID)
|
|
|
|
|
+ return nil
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
containers, err := s.apiClient.ContainerList(ctx, apitypes.ContainerListOptions{
|
|
containers, err := s.apiClient.ContainerList(ctx, apitypes.ContainerListOptions{
|
|
@@ -72,20 +75,16 @@ func (s *composeService) RunOneOffContainer(ctx context.Context, project *types.
|
|
|
All: true,
|
|
All: true,
|
|
|
})
|
|
})
|
|
|
if err != nil {
|
|
if err != nil {
|
|
|
- return "", err
|
|
|
|
|
|
|
+ return err
|
|
|
}
|
|
}
|
|
|
oneoffContainer := containers[0]
|
|
oneoffContainer := containers[0]
|
|
|
eg := errgroup.Group{}
|
|
eg := errgroup.Group{}
|
|
|
eg.Go(func() error {
|
|
eg.Go(func() error {
|
|
|
- return s.attachContainerStreams(ctx, oneoffContainer, true, os.Stdin, os.Stdout)
|
|
|
|
|
|
|
+ return s.attachContainerStreams(ctx, oneoffContainer, true, opts.Reader, opts.Writer)
|
|
|
})
|
|
})
|
|
|
- if err != nil {
|
|
|
|
|
- return "", err
|
|
|
|
|
- }
|
|
|
|
|
|
|
|
|
|
if err = s.apiClient.ContainerStart(ctx, containerID, apitypes.ContainerStartOptions{}); err != nil {
|
|
if err = s.apiClient.ContainerStart(ctx, containerID, apitypes.ContainerStartOptions{}); err != nil {
|
|
|
- return "", err
|
|
|
|
|
|
|
+ return err
|
|
|
}
|
|
}
|
|
|
- err = eg.Wait()
|
|
|
|
|
- return containerID, err
|
|
|
|
|
|
|
+ return eg.Wait()
|
|
|
}
|
|
}
|