docker

package
v1.22.6 Latest Latest
Warning

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

Go to latest
Published: Jan 17, 2024 License: MIT Imports: 7 Imported by: 1

Documentation

Index

Constants

View Source
const RetryAttempts = 3

Variables

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

	if startErr == nil {
		return nil, startErr
	}

	if !strings.Contains(startErr.Error(), "No such image") {
		l.Debug().
			Str("Start error", startErr.Error()).
			Str("Retrier", "PlatoformImageRetrier").
			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", "PlatoformImageRetrier").
		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", "PlatoformImageRetrier").
			Msgf("Successfully started %s container", req.Name)
		return ct, nil
	}

	req.ImagePlatform = originalPlatform

	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", "PlatoformImageRetrier").
		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)

	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.Reuse = false

	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