in internal/components/setup/compose.go [59:125]
func ComposeSetup(e2eConfig *config.E2EConfig) error {
composeConfigPath := e2eConfig.Setup.GetFile()
if composeConfigPath == "" {
return fmt.Errorf("no compose config file was provided")
}
// build docker client
cli, err := client.NewClientWithOpts(client.FromEnv)
if err != nil {
return err
}
// setup docker compose
composeFilePaths := []string{
composeConfigPath,
}
identifier := GetIdentity()
compose := testcontainers.NewLocalDockerCompose(composeFilePaths, identifier)
// bind wait port
services, err := buildComposeServices(e2eConfig, compose)
if err != nil {
return fmt.Errorf("bind wait ports error: %v", err)
}
// build command
cmd := make([]string, 0)
if e2eConfig.Setup.InitSystemEnvironment != "" {
profilePath := util.ResolveAbs(e2eConfig.Setup.InitSystemEnvironment)
cmd = append(cmd, "--env-file", profilePath)
util.ExportEnvVars(profilePath)
}
cmd = append(cmd, "up", "-d")
// Listen container create
listener := NewComposeContainerListener(context.Background(), cli, services)
defer listener.Stop()
err = listener.Listen(func(container *ComposeContainer) {
if err = exposeComposeLog(cli, container.Service, container.ID, logFollower); err == nil {
container.Service.beenFollowLog = true
}
})
if err != nil {
return err
}
// setup
execError := compose.WithCommand(cmd).Invoke()
if execError.Error != nil {
return execError.Error
}
// find exported port and build env
err = exposeComposeService(services, cli, identifier, e2eConfig)
if err != nil {
return err
}
// run steps
err = RunStepsAndWait(e2eConfig.Setup.Steps, e2eConfig.Setup.GetTimeout(), nil)
if err != nil {
logger.Log.Errorf("execute steps error: %v", err)
return err
}
return nil
}