dockerx

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Aug 4, 2026 License: MIT Imports: 19 Imported by: 0

Documentation

Index

Constants

View Source
const DefaultDockerSocket = "/var/run/docker.sock"

DefaultDockerSocket is the default Docker socket path.

View Source
const GacilsVolumeName = "gacils-tmp"

GacilsVolumeName returns the standard gacils volume name.

Variables

View Source
var DefaultExcludePatterns = []string{
	".git",
	".gacils",
	".gacils-local",
	"node_modules",
	"__pycache__",
	".venv",
	"venv",
	"dist",
	"build",
	"target",
	"coverage.out",
	"*.log",
}

DefaultExcludePatterns are the default patterns to exclude when creating a tar archive.

KnownPlatforms is the list of supported platforms.

View Source
var RunnerLabelToImage = map[string]string{
	"ubuntu-latest": "ubuntu:24.04",
	"ubuntu-24.04":  "ubuntu:24.04",
	"ubuntu-22.04":  "ubuntu:22.04",
}

RunnerLabelToImage maps GitHub runner labels to Docker images.

Functions

func CleanupWorkspace

func CleanupWorkspace(ctx context.Context, cli *client.Client, containerID, workspacePath string) error

CleanupWorkspace removes temporary workspace files from container.

func ConnectNetwork

func ConnectNetwork(ctx context.Context, cli *client.Client, networkID, containerID string) error

ConnectNetwork connects a container to a Docker network.

func CopyContainerToHost

func CopyContainerToHost(ctx context.Context, cli *client.Client, containerID, srcContainerPath, dstHostPath string) error

CopyContainerToHost copies files or directories from container path to host destination path.

func CopyFromContainer

func CopyFromContainer(ctx context.Context, cli *client.Client, containerID, srcPath, dstHostPath string) error

CopyFromContainer copies files from container to host using tar stream.

func CopyHostToContainer

func CopyHostToContainer(ctx context.Context, cli *client.Client, containerID, srcHostPath, dstContainerPath string) error

CopyHostToContainer copies files from host directory or file to container path.

func CopyToContainer

func CopyToContainer(ctx context.Context, cli *client.Client, containerID, dstPath string, tarReader io.Reader) error

CopyToContainer copies files from host to container using tar stream.

func CopyWorkspace

func CopyWorkspace(ctx context.Context, cli *client.Client, config CopyConfig) error

CopyWorkspace copies the workspace to a running container.

func CreateContainer

func CreateContainer(ctx context.Context, cli *client.Client, imageName, workingDir string, githubEnvPath, githubPathPath string, githubContext, runnerContext map[string]string) (string, error)

CreateContainer creates a new Docker container for running a job.

func CreateNetwork

func CreateNetwork(ctx context.Context, cli *client.Client, networkName string) (string, error)

CreateNetwork creates a Docker bridge network with the specified name.

func CreateServiceContainer

func CreateServiceContainer(ctx context.Context, cli *client.Client, networkName, serviceName string, serviceConfig ServiceConfig) (string, string, error)

CreateServiceContainer creates a service container connected to the specified network.

func DetectDockerSocket

func DetectDockerSocket() string

DetectDockerSocket attempts to find the Docker socket path. Checks: DOCKER_HOST env, default socket, Docker Desktop paths.

func EnsureImage

func EnsureImage(ctx context.Context, cli *client.Client, imageName string) error

EnsureImage checks if an image exists locally, and pulls it if not.

func EnsureWorkspaceDir

func EnsureWorkspaceDir(ctx context.Context, cli *client.Client, containerID, workspacePath string) error

EnsureWorkspaceDir ensures the workspace directory exists in the container.

func IsLocalDockerHost

func IsLocalDockerHost(host string) bool

IsLocalDockerHost checks if the Docker host is local (unix socket).

func IsValidPlatform

func IsValidPlatform(s string) bool

IsValidPlatform checks if a platform string is valid and known.

func NewClient

func NewClient(ctx context.Context) (*client.Client, error)

NewClient creates a new Docker client with environment-based configuration and API version negotiation.

func ParseDockerHost

func ParseDockerHost(host string) (protocol, address string)

ParseDockerHost parses a Docker host string into protocol and address.

func ParseHealthConfig

func ParseHealthConfig(optionsStr string) *container.HealthConfig

ParseHealthConfig parses health check options from the options string.

func ParsePlatform

func ParsePlatform(s string) (os, arch string, err error)

ParsePlatform parses a platform string in "os/arch" format.

func ParsePorts

func ParsePorts(ports []any) (nat.PortSet, nat.PortMap, string, error)

ParsePorts parses port mapping options into nat.PortSet and nat.PortMap.

func RemoveContainer

func RemoveContainer(ctx context.Context, cli *client.Client, containerID string) error

RemoveContainer removes a Docker container.

func RemoveNetwork

func RemoveNetwork(ctx context.Context, cli *client.Client, networkID string) error

RemoveNetwork removes a Docker network by ID.

func ResolveImage

func ResolveImage(runsOn string) (string, error)

ResolveImage resolves a runs-on label to a Docker image.

func StartContainer

func StartContainer(ctx context.Context, cli *client.Client, containerID string) error

StartContainer starts a Docker container.

func TarDirectory

func TarDirectory(srcPath string, excludePatterns []string) (io.Reader, error)

TarDirectory creates a tar stream of a directory for docker copy operations.

func WaitForServiceReady

func WaitForServiceReady(ctx context.Context, cli *client.Client, containerID string, hostPort string, maxWait time.Duration) error

WaitForServiceReady waits for a service container to become ready.

Types

type CopyConfig

type CopyConfig struct {
	SourcePath      string
	TargetPath      string
	ContainerID     string
	ExcludePatterns []string
	FollowSymlinks  bool
}

CopyConfig holds configuration for copying workspace to container.

type ExecResult

type ExecResult struct {
	ExitCode int
	Stdout   string
	Stderr   string
}

ExecResult represents the result of executing a command in a container.

func ExecCommand

func ExecCommand(ctx context.Context, cli *client.Client, containerID, workingDir string, cmd []string, env map[string]string) (*ExecResult, error)

ExecCommand executes a command inside a running container.

type Platform

type Platform string

Platform represents a normalized Docker platform.

const (
	// PlatformLinuxAMD64 represents linux/amd64.
	PlatformLinuxAMD64 Platform = "linux/amd64"
	// PlatformLinuxARM64 represents linux/arm64.
	PlatformLinuxARM64 Platform = "linux/arm64"
	// PlatformLinuxARMv7 represents linux/arm/v7.
	PlatformLinuxARMv7 Platform = "linux/arm/v7"
	// PlatformLinux386 represents linux/386.
	PlatformLinux386 Platform = "linux/386"
	// PlatformLinuxPPC64le represents linux/ppc64le.
	PlatformLinuxPPC64le Platform = "linux/ppc64le"
	// PlatformLinuxS390x represents linux/s390x.
	PlatformLinuxS390x Platform = "linux/s390x"
)

func HostPlatform

func HostPlatform() Platform

HostPlatform returns the current host platform.

func NormalizePlatform

func NormalizePlatform(input string) Platform

NormalizePlatform normalizes a platform string to a standard format. Accepts formats like: "linux/amd64", "amd64", "x86_64", "arm64", "aarch64"

type ServiceConfig

type ServiceConfig struct {
	Name    string
	Image   string
	Env     map[string]any
	Ports   []any
	Options string
}

ServiceConfig represents container configuration for a service.

type VolumeManager

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

VolumeManager manages Docker volumes for gacils.

func NewVolumeManager

func NewVolumeManager(cli *client.Client) *VolumeManager

NewVolumeManager creates a new volume manager.

func (*VolumeManager) CleanupVolumes

func (vm *VolumeManager) CleanupVolumes(ctx context.Context, labelKey, labelValue string) error

CleanupVolumes removes volumes with a specific label.

func (*VolumeManager) EnsureGacilsVolume

func (vm *VolumeManager) EnsureGacilsVolume(ctx context.Context) error

EnsureGacilsVolume ensures the gacils temporary volume exists.

func (*VolumeManager) EnsureVolume

func (vm *VolumeManager) EnsureVolume(ctx context.Context, name string, labels map[string]string) error

EnsureVolume creates a volume if it doesn't exist.

func (*VolumeManager) RemoveVolume

func (vm *VolumeManager) RemoveVolume(ctx context.Context, name string, force bool) error

RemoveVolume removes a volume by name.

func (*VolumeManager) VolumeExists

func (vm *VolumeManager) VolumeExists(ctx context.Context, name string) (bool, error)

VolumeExists checks if a volume exists.

Jump to

Keyboard shortcuts

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