runner

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Mar 27, 2026 License: MIT Imports: 20 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func FindAvailablePort

func FindAvailablePort(preferredPort int) (int, error)

FindAvailablePort finds an available port, preferring the requested port. If the requested port is in use, it finds a random available port. Returns the actual port that will be used.

func HasTemplates

func HasTemplates(s string) bool

HasTemplates checks if a string contains template expressions

func IsPortAvailable

func IsPortAvailable(port int) bool

IsPortAvailable checks if a port is available on the host

Types

type BuildImageOptions

type BuildImageOptions struct {
	ImageName    string            // Primary image tag
	Context      string            // Build context path
	Dockerfile   string            // Dockerfile path (relative to context)
	BuildArgs    map[string]string // Build arguments
	Target       string            // Multi-stage build target
	Tags         []string          // Additional tags
	WorkflowDir  string            // Host path that serves as /workflow reference
	VolumeMounts []VolumeMount     // Additional volume mounts during build
}

BuildImageOptions holds options for building an image

type BuiltImage

type BuiltImage struct {
	StepID    string
	ImageName string
}

BuiltImage tracks images built during workflow execution

type Docker

type Docker struct {
	// Output function for logging
	Output func(format string, args ...any)
	// contains filtered or unexported fields
}

Docker wraps docker CLI commands

func NewDocker

func NewDocker(output func(format string, args ...any), styles *Styles, secrets []string) *Docker

NewDocker creates a new Docker wrapper

func (*Docker) BuildImage

func (d *Docker) BuildImage(ctx context.Context, opts BuildImageOptions) (string, error)

BuildImage builds an image using docker build

func (*Docker) ContainerExists

func (d *Docker) ContainerExists(ctx context.Context, containerName string) bool

ContainerExists checks if a container with the given name exists (running or stopped)

func (*Docker) CreateNetwork

func (d *Docker) CreateNetwork(ctx context.Context, opts NetworkCreateOptions) error

CreateNetwork creates a Docker network

func (*Docker) GetContainerLogs

func (d *Docker) GetContainerLogs(ctx context.Context, containerName string, lines int) (string, error)

GetContainerLogs returns the last n lines of container logs

func (*Docker) GetImageID

func (d *Docker) GetImageID(ctx context.Context, imageName string) (string, error)

GetImageID returns the image ID for a given image name

func (*Docker) ImageExists

func (d *Docker) ImageExists(ctx context.Context, imageName string) bool

ImageExists checks if an image exists locally

func (*Docker) IsContainerRunning

func (d *Docker) IsContainerRunning(ctx context.Context, containerName string) bool

IsContainerRunning checks if a container is running

func (*Docker) NetworkExists

func (d *Docker) NetworkExists(ctx context.Context, name string) bool

NetworkExists checks if a network exists

func (*Docker) PullImage

func (d *Docker) PullImage(ctx context.Context, imageName string) error

PullImage pulls an image if not present locally

func (*Docker) RemoveContainer

func (d *Docker) RemoveContainer(ctx context.Context, containerName string) error

RemoveContainer removes a container

func (*Docker) RemoveExistingContainer

func (d *Docker) RemoveExistingContainer(ctx context.Context, containerName string) error

RemoveExistingContainer removes an existing container with the given name if it exists

func (*Docker) RemoveNetwork

func (d *Docker) RemoveNetwork(ctx context.Context, name string) error

RemoveNetwork removes a Docker network

func (*Docker) RunContainer

func (d *Docker) RunContainer(ctx context.Context, opts RunContainerOptions) error

RunContainer runs a container and waits for it to complete

func (*Docker) SetSecrets

func (d *Docker) SetSecrets(secrets []string)

SetSecrets updates the secrets to mask in output

func (*Docker) StopContainer

func (d *Docker) StopContainer(ctx context.Context, containerName string) error

StopContainer stops a running container

func (*Docker) StreamLogs

func (d *Docker) StreamLogs(ctx context.Context, containerName string) error

StreamLogs streams container logs (for long-running containers)

type DotEnv

type DotEnv struct {
	// Vars contains all KEY=value pairs from .env files
	Vars map[string]string
}

DotEnv holds parsed environment variables from .env files

func LoadDotEnv

func LoadDotEnv(workflowDir string) (*DotEnv, error)

LoadDotEnv loads environment variables from .env file in the workflow directory. If no .env file exists, returns an empty DotEnv (not an error). Lines starting with # are comments, empty lines are ignored. Format: KEY=value (no export prefix, quotes are preserved as-is)

func LoadDotEnvFile

func LoadDotEnvFile(path string) (*DotEnv, error)

LoadDotEnvFile loads environment variables from a specific .env file. If the file doesn't exist, returns an empty DotEnv (not an error). Lines starting with # are comments, empty lines are ignored. Format: KEY=value (no export prefix, quotes are preserved as-is)

func (*DotEnv) Get

func (d *DotEnv) Get(key string) string

Get returns a value from the .env, or empty string if not found

func (*DotEnv) Has

func (d *DotEnv) Has(key string) bool

Has returns true if a key exists in the .env

type ExposedService

type ExposedService struct {
	StepID        string // ID of the step (used as identifier)
	StepName      string // Human-readable name of the step
	ContainerPort int    // Port inside the container
	HostPort      int    // Port on the host (may differ if preferred port was unavailable)
	RequestedPort int    // Originally requested host port
	Protocol      string // Protocol (http, https, tcp, udp)
}

ExposedService tracks a service that has been exposed to the host

type FileWatcher

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

FileWatcher watches for file system changes and triggers callbacks

func NewFileWatcher

func NewFileWatcher(watchConfig *schema.Watch, basePath string, onChange func(changedFile string)) (*FileWatcher, error)

NewFileWatcher creates a new file watcher

func (*FileWatcher) Start

func (fw *FileWatcher) Start()

Start begins watching for file changes

func (*FileWatcher) Stop

func (fw *FileWatcher) Stop() error

Stop stops the file watcher

type HealthCheckConfig

type HealthCheckConfig struct {
	Cmd         string        // Command to run for health check
	Interval    time.Duration // Time between health checks
	Timeout     time.Duration // Timeout for each health check
	Retries     int           // Number of retries before failing
	StartPeriod time.Duration // Grace period before starting health checks
}

HealthCheckConfig holds health check configuration

type JobMeta

type JobMeta struct {
	Name        string
	Description string
	ID          string
}

JobMeta contains job-level metadata

type NetworkCreateOptions

type NetworkCreateOptions struct {
	Name   string // Network name
	Driver string // Network driver (default: bridge)
}

NetworkCreateOptions holds options for creating a network

type PortMapping

type PortMapping struct {
	ContainerPort int    // Port inside the container
	HostPort      int    // Port on the host
	Protocol      string // Protocol (http, https, tcp, udp)
}

PortMapping represents a container port to host port mapping

type Reloader

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

Reloader manages file watchers and container reloading

func NewReloader

func NewReloader(runner *Runner) *Reloader

NewReloader creates a new reloader

func (*Reloader) RegisterContainer

func (r *Reloader) RegisterContainer(wc *WatchedContainer) error

RegisterContainer registers a container for watching

func (*Reloader) Stop

func (r *Reloader) Stop()

Stop stops all watchers and cancels pending reloads

type ResolvedVolume

type ResolvedVolume struct {
	Name      string
	HostPath  string            // Absolute path on host
	Mode      schema.VolumeMode // "ro" or "rw"
	MountPath string            // Default mount path (empty = /volumes/<name>)
}

ResolvedVolume contains the resolved paths for a workflow volume

type RunContainerOptions

type RunContainerOptions struct {
	Name         string             // Container name (optional, auto-generated if empty)
	Hostname     string             // Hostname for the container (for DNS resolution in network)
	Network      string             // Network to connect to (empty = default docker network)
	Image        string             // Image to run
	Cmd          string             // Command string (will be passed to shell)
	Args         []string           // Command arguments (if Cmd is empty)
	Entrypoint   string             // Override entrypoint
	Env          map[string]string  // Environment variables
	WorkDir      string             // Working directory inside container
	WorkflowDir  string             // Host path to mount as /workflow
	VolumeMounts []VolumeMount      // Additional volume mounts (for explicit host access)
	TTY          bool               // Allocate TTY
	Remove       bool               // Remove container after exit (default true for non-background)
	Background   bool               // Run in background (detached)
	HealthCheck  *HealthCheckConfig // Health check for background containers
	PortMappings []PortMapping      // Ports to expose from container to host
	Force        bool               // Force remove existing container with same name
}

RunContainerOptions holds options for running a container

type Runner

type Runner struct {
	// WorkflowDir is the directory containing the workflow file (mounted as /workflow)
	WorkflowDir string
	// WorkflowFile is the path to the workflow YAML file
	WorkflowFile string
	// EnvFile is the path to the .env file to load (empty means use default .env)
	EnvFile string
	// Output function for logging (defaults to fmt.Printf)
	Output func(format string, args ...any)
	// contains filtered or unexported fields
}

Runner executes OCW workflows

func NewRunner

func NewRunner(workflowDir string) *Runner

NewRunner creates a new workflow runner

func (*Runner) Run

func (r *Runner) Run(ctx context.Context, ocw *schema.OCW) error

Run executes an OCW workflow (direct flow control, not a specific job)

func (*Runner) RunJob

func (r *Runner) RunJob(ctx context.Context, ocw *schema.OCW, jobName string) error

RunJob executes a specific job from an OCW workflow

func (*Runner) WithEnvFile

func (r *Runner) WithEnvFile(envFile string) *Runner

WithEnvFile sets a custom .env file path

func (*Runner) WithForce

func (r *Runner) WithForce(force bool) *Runner

WithForce sets whether to force remove existing containers with the same name

func (*Runner) WithShowSecrets

func (r *Runner) WithShowSecrets(show bool) *Runner

WithShowSecrets sets whether to show secret values in output (disable masking)

type StepResult

type StepResult struct {
	Name     string
	Status   StepStatus
	Duration time.Duration
	Error    error
}

StepResult represents the result of a step execution

type StepStatus

type StepStatus string

StepStatus represents the status of a step

const (
	StepStatusPending   StepStatus = "pending"
	StepStatusRunning   StepStatus = "running"
	StepStatusCompleted StepStatus = "completed"
	StepStatusFailed    StepStatus = "failed"
	StepStatusSkipped   StepStatus = "skipped"
)

type Styles

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

Styles provides pre-defined styles for different output types

func NewStyles

func NewStyles() *Styles

NewStyles creates a new Styles instance, auto-detecting color support

func (*Styles) Box

func (s *Styles) Box(title, content string) string

Box creates a simple box around text

func (*Styles) Command

func (s *Styles) Command(text string) string

Command styles command text

func (*Styles) CompletionBanner

func (s *Styles) CompletionBanner(jobName string, duration string, success bool) string

CompletionBanner creates the final completion banner

func (*Styles) Dim

func (s *Styles) Dim(text string) string

Dim styles dimmed/secondary text

func (*Styles) Divider

func (s *Styles) Divider(width int) string

Divider returns a horizontal divider line

func (*Styles) Duration

func (s *Styles) Duration(d string) string

Duration formats a duration nicely

func (*Styles) Error

func (s *Styles) Error(text string) string

Error styles error messages

func (*Styles) Header

func (s *Styles) Header(text string) string

Header styles - for major sections

func (*Styles) Icon

func (s *Styles) Icon(icon string) string

Icon returns a styled icon

func (*Styles) Info

func (s *Styles) Info(text string) string

Info styles informational text

func (*Styles) JobBox

func (s *Styles) JobBox(jobName, workflowName, description string) string

JobBox creates the job header

func (*Styles) JobHeader

func (s *Styles) JobHeader(text string) string

JobHeader styles the job/workflow header

func (*Styles) Label

func (s *Styles) Label(text string) string

Label styles for labels (like "Type:", "Image:")

func (*Styles) LogPrefix

func (s *Styles) LogPrefix() string

LogPrefix returns a styled prefix for log output

func (*Styles) OutputKey

func (s *Styles) OutputKey(text string) string

OutputKey styles output keys

func (*Styles) OutputValue

func (s *Styles) OutputValue(text string) string

OutputValue styles output values

func (*Styles) OutputsBox

func (s *Styles) OutputsBox(title string, outputs map[string]string) string

OutputsBox creates a styled outputs section

func (*Styles) SectionHeader

func (s *Styles) SectionHeader(text string) string

SectionHeader creates a section header (like ">>> Running 4 steps in sequence")

func (*Styles) ServiceURL

func (s *Styles) ServiceURL(name, url, protocol string) string

ServiceURL formats a service URL

func (*Styles) StatusIcon

func (s *Styles) StatusIcon(status StepStatus) string

StatusIcon returns an appropriate icon for a status

func (*Styles) StepBox

func (s *Styles) StepBox(name, stepType string, extra map[string]string) string

StepBox creates a styled step header box

func (*Styles) StepComplete

func (s *Styles) StepComplete(name string, success bool) string

StepComplete formats a step completion message

func (*Styles) StepHeader

func (s *Styles) StepHeader(text string) string

StepHeader styles step headers

func (*Styles) StepName

func (s *Styles) StepName(text string) string

StepName styles step names

func (*Styles) Success

func (s *Styles) Success(text string) string

Success styles success messages

func (*Styles) Value

func (s *Styles) Value(text string) string

Value styles for values

func (*Styles) Warning

func (s *Styles) Warning(text string) string

Warning styles warning messages

type TemplateContext

type TemplateContext struct {
	// Steps contains outputs from completed steps, keyed by step ID
	// Each step can have multiple outputs (e.g., "image" for build steps)
	Steps map[string]map[string]string

	// Env contains environment variables (workflow-level + system)
	Env map[string]string

	// Workflow contains workflow metadata
	Workflow WorkflowMeta

	// Job contains current job metadata
	Job JobMeta
}

TemplateContext holds the data available for template interpolation

func NewTemplateContext

func NewTemplateContext() *TemplateContext

NewTemplateContext creates a new empty template context

func (*TemplateContext) GetStepOutput

func (tc *TemplateContext) GetStepOutput(stepID, key string) (string, bool)

GetStepOutput gets an output value for a step

func (*TemplateContext) Interpolate

func (tc *TemplateContext) Interpolate(s string) (string, error)

Interpolate replaces template expressions in a string with their values

func (*TemplateContext) InterpolateMap

func (tc *TemplateContext) InterpolateMap(m map[string]string) (map[string]string, error)

InterpolateMap interpolates all string values in a map

func (*TemplateContext) InterpolateSlice

func (tc *TemplateContext) InterpolateSlice(s []string) ([]string, error)

InterpolateSlice interpolates all strings in a slice

func (*TemplateContext) SetStepOutput

func (tc *TemplateContext) SetStepOutput(stepID, key, value string)

SetStepOutput sets an output value for a step

type VolumeMount

type VolumeMount struct {
	HostPath      string
	ContainerPath string
	ReadOnly      bool
}

VolumeMount represents a resolved volume mount

type WatchedContainer

type WatchedContainer struct {
	StepID        string
	StepName      string
	Image         string
	ContainerName string
	WatchConfig   *schema.Watch
	RunStep       *schema.RunStep
	BuildStepID   string // ID of the build step if using a built image

	// Volume mounts for translating container paths to host paths
	VolumeMounts []VolumeMount

	PortMappings []PortMapping // Track allocated ports to reuse them on reload
	// contains filtered or unexported fields
}

WatchedContainer tracks a container being watched for file changes

type WorkflowMeta

type WorkflowMeta struct {
	Name        string
	Description string
	ID          string
}

WorkflowMeta contains workflow-level metadata

Jump to

Keyboard shortcuts

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