docker

package
v0.8.0 Latest Latest
Warning

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

Go to latest
Published: Dec 2, 2025 License: Apache-2.0 Imports: 18 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Build

func Build(ctx context.Context, log *slog.Logger, imageName string, dockerfilePath string, contextDir string, verbose bool, args ...string) error

func Exec

func Exec(ctx context.Context, cli *client.Client, containerID string, cmd []string, options ...ExecOption) ([]byte, error)

func ExecReturnJSONList

func ExecReturnJSONList(ctx context.Context, cli *client.Client, containerID string, cmd []string, options ...ExecOption) ([]map[string]any, error)

func ExecReturnObject

func ExecReturnObject[T any](ctx context.Context, cli *client.Client, containerID string, cmd []string, options ...ExecOption) (T, error)

func ExecReturnReader

func ExecReturnReader(ctx context.Context, cli *client.Client, containerID string, cmd []string, options ...ProcessOption) (int, io.Reader, error)

The following code is adapted from the Exec function in testcontainers-go: https://github.com/testcontainers/testcontainers-go/blob/main/docker.go

The MIT license applies **only to this function and the related types or logic directly derived from the above source**. All other code in this file/project is licensed under the Apache License 2.0.

The MIT License (MIT)

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

func Pull

func Pull(ctx context.Context, log *slog.Logger, imageName string, verbose bool) error

func Run

func Run(ctx context.Context, log *slog.Logger, imageName string, verbose bool, args ...string) ([]byte, error)

Types

type ExecOption

type ExecOption func(*ExecOptions)

func NoPrintOnError

func NoPrintOnError() ExecOption

type ExecOptions

type ExecOptions struct {
	PrintOnError bool
}

type ProcessOption

type ProcessOption interface {
	Apply(opts *ProcessOptions)
}

ProcessOption defines a common interface to modify the reader processor These options can be passed to the Exec function in a variadic way to customize the returned Reader instance

func Multiplexed

func Multiplexed() ProcessOption

Multiplexed returns a ProcessOption that configures the command execution to combine stdout and stderr into a single stream without Docker's multiplexing headers.

func WithEnv

func WithEnv(env []string) ProcessOption

func WithUser

func WithUser(user string) ProcessOption

func WithWorkingDir

func WithWorkingDir(workingDir string) ProcessOption

type ProcessOptionFunc

type ProcessOptionFunc func(opts *ProcessOptions)

func (ProcessOptionFunc) Apply

func (fn ProcessOptionFunc) Apply(opts *ProcessOptions)

type ProcessOptions

type ProcessOptions struct {
	ExecConfig container.ExecOptions
	Reader     io.Reader
}

ProcessOptions defines options applicable to the reader processor

func NewProcessOptions

func NewProcessOptions(cmd []string) *ProcessOptions

NewProcessOptions returns a new ProcessOptions instance with the given command and default options: - detach: false - attach stdout: true - attach stderr: true

type SubnetAllocator

type SubnetAllocator struct {
	Base       net.IP
	BaseMask   int
	SubnetMask int
	MaxSubnets int
	// contains filtered or unexported fields
}

SubnetAllocator is a helper for allocating subnets from a base CIDR.

It can be used to allocate subnets for testing purposes, and is thread-safe using an in-memory lock, so it can be used in parallel. It also checks for overlaps with existing subnets in the docker network using a docker client, and will retry with a different salt if the subnet is already in use.

func NewDefaultSubnetAllocator

func NewDefaultSubnetAllocator(docker *client.Client) *SubnetAllocator

func NewSubnetAllocator

func NewSubnetAllocator(baseCIDR string, subnetMask int, docker *client.Client) *SubnetAllocator

func (*SubnetAllocator) FindAvailableSubnet

func (a *SubnetAllocator) FindAvailableSubnet(ctx context.Context, testID string) (string, error)

func (*SubnetAllocator) GetSubnetCIDR

func (a *SubnetAllocator) GetSubnetCIDR(testID string, salt int) (string, error)

Jump to

Keyboard shortcuts

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