libdocker

package
v0.0.0-...-57387e0 Latest Latest
Warning

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

Go to latest
Published: Aug 19, 2025 License: GPL-3.0 Imports: 21 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Connect

func Connect(dockerEndpoint string, cfg *Config) (*Builder, *ContainerBackend, error)

Types

type Builder

type Builder struct {
	// contains filtered or unexported fields
}

Builder takes care of building docker images.

func NewBuilder

func NewBuilder(client *docker.Client, cfg *Config, auth *docker.AuthConfigurations) *Builder

func (*Builder) BuildClientImage

func (b *Builder) BuildClientImage(ctx context.Context, client libhive.ClientDesignator) (string, error)

BuildClientImage builds a docker image of the given client.

func (*Builder) BuildImage

func (b *Builder) BuildImage(ctx context.Context, name string, fsys fs.FS) error

BuildImage creates a container by archiving the given file system, which must contain a file called "Dockerfile".

func (*Builder) BuildSimulatorImage

func (b *Builder) BuildSimulatorImage(ctx context.Context, name string, buildArgs map[string]string) (string, error)

BuildSimulatorImage builds a docker image of a simulator.

func (*Builder) ReadFile

func (b *Builder) ReadFile(ctx context.Context, image, path string) ([]byte, error)

ReadFile returns the content of a file in the given image. To do so, it creates a temporary container, downloads the file from it and destroys the container.

type Config

type Config struct {
	Inventory libhive.Inventory

	Logger *slog.Logger

	// When building containers, any client or simulator image build matching the pattern
	// will avoid the docker cache.
	NoCachePattern *regexp.Regexp

	// This forces pulling of base images when building clients and simulators.
	PullEnabled bool

	// These two are log destinations for output from docker.
	ContainerOutput io.Writer
	BuildOutput     io.Writer

	// This tells the docker client whether to authenticate requests
	UseAuthentication bool
}

Config is the configuration of the docker backend.

type ContainerBackend

type ContainerBackend struct {
	// contains filtered or unexported fields
}

func NewContainerBackend

func NewContainerBackend(c *docker.Client, cfg *Config) *ContainerBackend

func (*ContainerBackend) Build

Build builds the hiveproxy image.

func (*ContainerBackend) ConnectContainer

func (b *ContainerBackend) ConnectContainer(containerID, networkID string) error

ConnectContainer connects the given container to a network.

func (*ContainerBackend) ContainerIP

func (b *ContainerBackend) ContainerIP(containerID, networkID string) (net.IP, error)

ContainerIP finds the IP of a container in the given network.

func (*ContainerBackend) CreateContainer

func (b *ContainerBackend) CreateContainer(ctx context.Context, imageName string, opt libhive.ContainerOptions) (string, error)

CreateContainer creates a docker container.

func (*ContainerBackend) CreateNetwork

func (b *ContainerBackend) CreateNetwork(name string) (string, error)

CreateNetwork creates a docker network.

func (*ContainerBackend) DeleteContainer

func (b *ContainerBackend) DeleteContainer(containerID string) error

DeleteContainer removes the given container. If the container is running, it is stopped.

func (*ContainerBackend) DisconnectContainer

func (b *ContainerBackend) DisconnectContainer(containerID, networkID string) error

DisconnectContainer disconnects the given container from a network.

func (*ContainerBackend) GetDockerClient

func (b *ContainerBackend) GetDockerClient() interface{}

GetDockerClient returns the underlying Docker client for cleanup operations.

func (*ContainerBackend) NetworkNameToID

func (b *ContainerBackend) NetworkNameToID(name string) (string, error)

NetworkNameToID finds the network ID of network by the given name.

func (*ContainerBackend) PauseContainer

func (b *ContainerBackend) PauseContainer(containerID string) error

PauseContainer pauses the given container.

func (*ContainerBackend) RemoveNetwork

func (b *ContainerBackend) RemoveNetwork(id string) error

RemoveNetwork deletes a docker network.

func (*ContainerBackend) RunProgram

func (b *ContainerBackend) RunProgram(ctx context.Context, containerID string, cmd []string) (*libhive.ExecInfo, error)

RunProgram runs a /hive-bin script in a container.

func (*ContainerBackend) ServeAPI

ServeAPI starts the API server.

func (*ContainerBackend) SetHiveInstanceInfo

func (b *ContainerBackend) SetHiveInstanceInfo(instanceID, version string)

SetHiveInstanceInfo sets the hive instance information for container labeling.

func (*ContainerBackend) StartContainer

func (b *ContainerBackend) StartContainer(ctx context.Context, containerID string, opt libhive.ContainerOptions) (*libhive.ContainerInfo, error)

StartContainer starts a docker container.

func (*ContainerBackend) UnpauseContainer

func (b *ContainerBackend) UnpauseContainer(containerID string) error

UnpauseContainer unpauses the given container.

Jump to

Keyboard shortcuts

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