Signed-off-by: Suleiman Dibirov <idsulik@gmail.com>
(cherry picked from commit 6a35be511222e673f4907dfa32a23a3aa4513e5c)
Signed-off-by: Guillaume Lours <705411+glours@users.noreply.github.com>
This commit is contained in:
Suleiman Dibirov 2025-10-28 17:22:49 +02:00 committed by Guillaume Lours
parent c6bec2e712
commit 141921e72b

View File

@ -98,13 +98,7 @@ func (s *composeService) prepareRun(ctx context.Context, project *types.Project,
Add(api.OneoffLabel, "True")
// Only ensure image exists for the target service, dependencies were already handled by startDependencies
var buildOpts *api.BuildOptions
if opts.Build != nil {
// Create a copy of build options and restrict to only the target service
buildOptsCopy := *opts.Build
buildOptsCopy.Services = []string{opts.Service}
buildOpts = &buildOptsCopy
}
buildOpts := prepareBuildOptions(opts)
if err := s.ensureImagesExists(ctx, project, buildOpts, opts.QuietPull); err != nil { // all dependencies already checked, but might miss service img
return "", err
}
@ -155,6 +149,16 @@ func (s *composeService) prepareRun(ctx context.Context, project *types.Project,
return created.ID, err
}
func prepareBuildOptions(opts api.RunOptions) *api.BuildOptions {
if opts.Build == nil {
return nil
}
// Create a copy of build options and restrict to only the target service
buildOptsCopy := *opts.Build
buildOptsCopy.Services = []string{opts.Service}
return &buildOptsCopy
}
func applyRunOptions(project *types.Project, service *types.ServiceConfig, opts api.RunOptions) {
service.Tty = opts.Tty
service.StdinOpen = opts.Interactive