docker

package
v1.30.9 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 18, 2024 License: MIT Imports: 7 Imported by: 1

Documentation

Index

Constants

View Source
const RetryAttempts = 3

Variables

View Source
var LinuxPlatformImageRetrier = func(l zerolog.Logger, startErr error, req tc.GenericContainerRequest) (tc.Container, error) {

	if startErr == nil {
		return nil, startErr
	}
	req.Reuse = false
	oldName := req.Name
	req.Name = req.Name + "-linux-retry"

	if !strings.Contains(startErr.Error(), "No such image") {
		l.Debug().
			Str("Start error", startErr.Error()).
			Str("Retrier", "PlatformImageRetrier").
			Msgf("Won't try to start %s container again, unsupported error", req.Name)
		return nil, startErr
	}

	l.Debug().
		Str("Start error", startErr.Error()).
		Str("Retrier", "PlatformImageRetrier").
		Msgf("Attempting to start %s container", req.Name)

	originalPlatform := req.ImagePlatform
	req.ImagePlatform = "linux/x86_64"

	ct, err := tc.GenericContainer(testcontext.Get(nil), req)
	if err == nil {
		l.Debug().
			Str("Retrier", "PlatformImageRetrier").
			Msgf("Successfully started %s container", req.Name)
		return ct, nil
	}

	req.ImagePlatform = originalPlatform
	req.Name = oldName

	if ct != nil {
		err := ct.Terminate(testcontext.Get(nil))
		if err != nil {
			l.Error().Err(err).Msgf("Cannot terminate %s container to initiate restart", req.Name)
			return nil, err
		}
	}

	l.Debug().
		Str("Original start error", startErr.Error()).
		Str("Current start error", err.Error()).
		Str("Retrier", "PlatformImageRetrier").
		Msgf("Failed to start %s container,", req.Name)

	return nil, startErr
}
View Source
var NaiveRetrier = func(l zerolog.Logger, startErr error, req tc.GenericContainerRequest) (tc.Container, error) {
	l.Debug().
		Str("Start error", startErr.Error()).
		Str("Retrier", "NaiveRetrier").
		Msgf("Attempting to start %s container", req.Name)

	oldName := req.Name
	req.Name = req.Name + "-naive-retry"

	ct, err := tc.GenericContainer(testcontext.Get(nil), req)
	if err == nil {
		l.Debug().
			Str("Retrier", "NaiveRetrier").
			Msgf("Successfully started %s container", req.Name)
		return ct, nil
	}
	if ct != nil {
		err := ct.Terminate(testcontext.Get(nil))
		if err != nil {
			l.Error().
				Err(err).
				Msgf("Cannot terminate %s container to initiate restart", req.Name)
			return nil, err
		}
	}

	req.Name = oldName

	l.Debug().
		Str("Original start error", startErr.Error()).
		Str("Current start error", err.Error()).
		Str("Retrier", "NaiveRetrier").
		Msgf("Failed to start %s container,", req.Name)

	return nil, startErr
}

Functions

func CreateNetwork

func CreateNetwork(l zerolog.Logger) (*tc.DockerNetwork, error)

func StartContainerWithRetry added in v1.16.4

func StartContainerWithRetry(l zerolog.Logger, req tc.GenericContainerRequest, retriers ...StartContainerRetrier) (tc.Container, error)

StartContainerWithRetry attempts to start a container with 3 retry attempts. It will try to start the container with the provided retriers, if none are provided it will use the default retriers. Default being: 1. tries to download image for "linux/x86_64" platform 2. simply starts again without changing anything

Types

type StartContainerRetrier added in v1.22.6

type StartContainerRetrier func(l zerolog.Logger, startErr error, req tc.GenericContainerRequest) (tc.Container, error)

Directories

Path Synopsis
cmd

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL