container

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Sep 4, 2026 License: Apache-2.0 Imports: 13 Imported by: 0

Documentation

Overview

Package container implements the Flow "container" block (Design B / #43 PoC).

Operator model: a pipeline stage whose implementation is a Docker image. Transport is HTTP request/response (not upstream AMQP). Lifecycle is tied to the flow: the container is started at Instantiate (flow start) and removed on Stopper.Stop (flow stop).

Index

Constants

View Source
const Type = "container"

Type is the pipeline block_type string.

Variables

This section is empty.

Functions

func Constructor

func Constructor(name string, config map[string]any, deps flow.Deps) (flow.Block, error)

Constructor is the catalog entry point (uses defaultRunner).

func New

func New(name string, config map[string]any, deps flow.Deps, runner Runner) (flow.Block, error)

New builds and starts a container block with an explicit Runner (tests + PoC).

func SetDefaultRunner

func SetDefaultRunner(r Runner) (restore func())

SetDefaultRunner replaces the Docker runner used by the catalog constructor. Prefer New in unit tests. Returns a restore function.

Types

type Block

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

Block is a transform that round-trips each Message through a container.

func (*Block) Name

func (b *Block) Name() string

Name implements flow.Block.

func (*Block) Process

func (b *Block) Process(msg *flow.Message) ([]*flow.Message, error)

Process implements flow.Block. PoC error policy: return error so the router logs + increments blockErrors and drops the message (no outs).

func (*Block) Stop

func (b *Block) Stop()

Stop implements flow.Stopper: stop and remove the container.

type Bridge

type Bridge struct {
	Client       *http.Client
	BaseURL      string
	Timeout      time.Duration
	MaxBodyBytes int64
}

Bridge POSTs FlowMessages to a container HTTP endpoint.

func (*Bridge) RoundTrip

func (b *Bridge) RoundTrip(ctx context.Context, msg *flow.Message) ([]*flow.Message, error)

RoundTrip sends one Message and parses zero or more outputs.

Contract (PoC):

  • Request: POST /v1/message, body = Message JSON
  • 204 or empty body → drop (zero outs)
  • 200 + object → one message
  • 200 + array → N messages
  • other status → error

func (*Bridge) WaitReady

func (b *Bridge) WaitReady(ctx context.Context) error

WaitReady polls GET /healthz until success or ctx is done.

type CLIRunner

type CLIRunner struct {
	// Docker is the docker binary name or path (default "docker").
	Docker string
	// Run is optional; when set, tests can intercept command execution.
	// argv[0] is the docker binary. Returns stdout, stderr, error.
	Run func(ctx context.Context, name string, args ...string) (stdout, stderr string, err error)
}

CLIRunner shells out to the docker CLI. Suitable for PoC; MVP may switch to the Engine API client for cancel/cleanup.

func (*CLIRunner) Start

func (r *CLIRunner) Start(ctx context.Context, spec Spec) (Instance, error)

Start runs `docker run -d` with a published localhost port and Astrate labels.

type Config

type Config struct {
	Image         string
	Nested        map[string]any // opaque JSON for ASTRATE_FLOW_CONFIG
	ContainerPort int
	Timeout       time.Duration
	ReadyTimeout  time.Duration
}

Config is the parsed block configuration.

type Instance

type Instance interface {
	// BaseURL is the host URL to POST messages to (e.g. http://127.0.0.1:49152).
	BaseURL() string
	// ID is the docker container id (or a test fake id).
	ID() string
	// Stop stops and removes the container (best-effort).
	Stop(ctx context.Context) error
}

Instance is a running container that serves the HTTP bridge.

type Runner

type Runner interface {
	Start(ctx context.Context, spec Spec) (Instance, error)
}

Runner starts containers. PoC default is CLIRunner (docker CLI).

type Spec

type Spec struct {
	Image string
	// ContainerPort is the HTTP port inside the container (default 8080).
	ContainerPort int
	// FlowConfigJSON is passed as ASTRATE_FLOW_CONFIG.
	FlowConfigJSON string
	// Labels are applied to the container (astrate.*).
	Labels map[string]string
	// Name is an optional docker container name (must be unique).
	Name string
}

Spec describes a container to start for a flow block.

type Waiter

type Waiter interface {
	// Wait blocks until the container exits (or ctx is cancelled) and returns
	// its exit code.
	Wait(ctx context.Context) (exitCode int, err error)
}

Waiter is implemented by Instances that can block until their container exits. The block's exit watcher uses it to detect unexpected death (#45).

Jump to

Keyboard shortcuts

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