func BootUp()

in internal/stack/boot.go [35:117]


func BootUp(ctx context.Context, options Options) error {
	// Print information before starting the stack, for cases where
	// this is executed in the foreground, without daemon mode.
	config := Config{
		Provider:              ProviderCompose,
		ElasticsearchHost:     "https://127.0.0.1:9200",
		ElasticsearchUsername: elasticsearchUsername,
		ElasticsearchPassword: elasticsearchPassword,
		KibanaHost:            "https://127.0.0.1:5601",
		CACertFile:            options.Profile.Path(CACertificateFile),
	}
	printUserConfig(options.Printer, config)

	buildPackagesPath, found, err := builder.FindBuildPackagesDirectory()
	if err != nil {
		return fmt.Errorf("finding build packages directory failed: %w", err)
	}

	stackPackagesDir, err := locations.NewLocationManager()
	if err != nil {
		return fmt.Errorf("locating stack packages directory failed: %w", err)
	}

	err = files.ClearDir(stackPackagesDir.PackagesDir())
	if err != nil {
		return fmt.Errorf("clearing package contents failed: %w", err)
	}

	if found {
		fmt.Printf("Custom build packages directory found: %s\n", buildPackagesPath)
		err = copyUniquePackages(buildPackagesPath, stackPackagesDir.PackagesDir())
		if err != nil {
			return fmt.Errorf("copying package contents failed: %w", err)
		}
	}

	options.Printer.Println("Local package-registry will serve packages from these sources:")
	options.Printer.Println("- Proxy to https://epr.elastic.co")

	if found {
		options.Printer.Printf("- Local directory %s\n", buildPackagesPath)
	}

	err = applyResources(options.Profile, options.StackVersion)
	if err != nil {
		return fmt.Errorf("creating stack files failed: %w", err)
	}

	err = dockerComposeBuild(ctx, options)
	if err != nil {
		return fmt.Errorf("building docker images failed: %w", err)
	}

	err = dockerComposeUp(ctx, options)
	if err != nil {
		// At least starting on 8.6.0, fleet-server may be reconfigured or
		// restarted after being healthy. If elastic-agent tries to enroll at
		// this moment, it fails inmediately, stopping and making `docker-compose up`
		// to fail too.
		// As a workaround, try to give another chance to docker-compose if only
		// elastic-agent failed.
		if onlyElasticAgentFailed(ctx, options) && !errors.Is(err, context.Canceled) {
			sleepTime := 2 * time.Second
			fmt.Printf("Elastic Agent failed to start, trying again in %s.\n", sleepTime)
			select {
			case <-time.After(sleepTime):
				err = dockerComposeUp(ctx, options)
			case <-ctx.Done():
				err = ctx.Err()
			}
		}
		if err != nil {
			return fmt.Errorf("running docker-compose failed: %w", err)
		}
	}

	err = storeConfig(options.Profile, config)
	if err != nil {
		return fmt.Errorf("failed to store config: %w", err)
	}

	return nil
}