| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112 | 
							- /*
 
-    Copyright 2020 Docker Compose CLI authors
 
-    Licensed under the Apache License, Version 2.0 (the "License");
 
-    you may not use this file except in compliance with the License.
 
-    You may obtain a copy of the License at
 
-        http://www.apache.org/licenses/LICENSE-2.0
 
-    Unless required by applicable law or agreed to in writing, software
 
-    distributed under the License is distributed on an "AS IS" BASIS,
 
-    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 
-    See the License for the specific language governing permissions and
 
-    limitations under the License.
 
- */
 
- package compose
 
- import (
 
- 	"context"
 
- 	"fmt"
 
- 	"os"
 
- 	"os/signal"
 
- 	"syscall"
 
- 	"github.com/compose-spec/compose-go/types"
 
- 	"github.com/docker/cli/cli"
 
- 	"github.com/docker/compose/v2/pkg/api"
 
- 	"github.com/docker/compose/v2/pkg/progress"
 
- 	"golang.org/x/sync/errgroup"
 
- )
 
- func (s *composeService) Up(ctx context.Context, project *types.Project, options api.UpOptions) error {
 
- 	err := progress.Run(ctx, func(ctx context.Context) error {
 
- 		err := s.create(ctx, project, options.Create)
 
- 		if err != nil {
 
- 			return err
 
- 		}
 
- 		if options.Start.Attach == nil {
 
- 			return s.start(ctx, project.Name, options.Start, nil)
 
- 		}
 
- 		return nil
 
- 	}, s.stderr())
 
- 	if err != nil {
 
- 		return err
 
- 	}
 
- 	if options.Start.Attach == nil {
 
- 		return err
 
- 	}
 
- 	if s.dryRun {
 
- 		fmt.Fprintln(s.stdout(), "end of 'compose up' output, interactive run is not supported in dry-run mode")
 
- 		return err
 
- 	}
 
- 	printer := newLogPrinter(options.Start.Attach)
 
- 	signalChan := make(chan os.Signal, 1)
 
- 	signal.Notify(signalChan, syscall.SIGINT, syscall.SIGTERM)
 
- 	stopFunc := func() error {
 
- 		fmt.Fprintln(s.stderr(), "Aborting on container exit...")
 
- 		ctx := context.Background()
 
- 		return progress.Run(ctx, func(ctx context.Context) error {
 
- 			go func() {
 
- 				<-signalChan
 
- 				s.Kill(ctx, project.Name, api.KillOptions{ //nolint:errcheck
 
- 					Services: options.Create.Services,
 
- 					Project:  project,
 
- 				})
 
- 			}()
 
- 			return s.Stop(ctx, project.Name, api.StopOptions{
 
- 				Services: options.Create.Services,
 
- 				Project:  project,
 
- 			})
 
- 		}, s.stderr())
 
- 	}
 
- 	var isTerminated bool
 
- 	eg, ctx := errgroup.WithContext(ctx)
 
- 	go func() {
 
- 		<-signalChan
 
- 		isTerminated = true
 
- 		printer.Cancel()
 
- 		fmt.Fprintln(s.stderr(), "Gracefully stopping... (press Ctrl+C again to force)")
 
- 		eg.Go(stopFunc)
 
- 	}()
 
- 	var exitCode int
 
- 	eg.Go(func() error {
 
- 		code, err := printer.Run(options.Start.CascadeStop, options.Start.ExitCodeFrom, stopFunc)
 
- 		exitCode = code
 
- 		return err
 
- 	})
 
- 	err = s.start(ctx, project.Name, options.Start, printer.HandleEvent)
 
- 	if err != nil && !isTerminated { // Ignore error if the process is terminated
 
- 		return err
 
- 	}
 
- 	printer.Stop()
 
- 	err = eg.Wait()
 
- 	if exitCode != 0 {
 
- 		errMsg := ""
 
- 		if err != nil {
 
- 			errMsg = err.Error()
 
- 		}
 
- 		return cli.StatusError{StatusCode: exitCode, Status: errMsg}
 
- 	}
 
- 	return err
 
- }
 
 
  |