Help us shape the future of Go! Take the 2026 Go Developer Survey

installer

package
v0.2.1 Latest Latest
Warning

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

Go to latest
Published: Oct 27, 2026 License: Apache-2.0 Imports: 24 Imported by: 0

Documentation

Overview

Package installer is the invocation image side of nemo: it reads the operation a CNAB runtime hands to the container and applies the bundle's compose project to the target with the Orchestrator the target names. It keeps no state and knows nothing about stacks, storage or the nemo runtime.

Index

Constants

View Source
const (
	BundleFile          = "/cnab/bundle.json"
	EnvAction           = "CNAB_ACTION"
	EnvInstallationName = "CNAB_INSTALLATION_NAME"
	EnvBundleName       = "CNAB_BUNDLE_NAME"
	EnvRevision         = "CNAB_REVISION"
)

Locations and variables of the CNAB contract between a runtime and its invocation image (cnab-spec 103-bundle-runtime.md).

View Source
const AppDir = "/cnab/app"

AppDir is the bundle's own directory in the invocation image: the compose project resolves its relative paths there.

View Source
const DefaultTimeout = 5 * time.Minute

DefaultTimeout bounds an action whose bundle sets no nemo-timeout.

View Source
const VolumeExtension = "x-nemo-volume"

VolumeExtension is the compose extension by which a bundle gives a volume a type, that the target makes of a driver and options.

Variables

View Source
var ErrUnsupported = errors.New("unsupported")

ErrUnsupported is returned for an action or an orchestrator the installer does not handle.

Functions

func Run

func Run(ctx context.Context, operation Operation, orchestrators Orchestrators, events progress.Sink) error

Run performs the operation with the orchestrator the nemo-orchestrator parameter names. Only that one is built.

func VolumeOwner

func VolumeOwner(installation Installation) map[string]string

VolumeOwner are the labels that make a volume the stack's own. A network or a container is also its orchestrator's, a volume is not: the data an uninstall keeps is for the next install, whichever orchestrator it uses.

Types

type Container

type Container struct {
	LookupEnv func(key string) (string, bool)
	// FS is the container's filesystem, rooted at "/".
	FS fs.FS
}

Container is what the invocation image sees of the operation: its environment variables and its filesystem.

type InstallOptions

type InstallOptions struct {
	Events progress.Sink
}

InstallOptions are the options of Orchestrator.Install.

type Installation

type Installation struct {
	Stack    string
	Bundle   string
	Version  string
	Revision string
}

Installation identifies what an operation installs. Its fields go on every object the orchestrator creates.

type NewOrchestratorFunc

type NewOrchestratorFunc func(ctx context.Context) (Orchestrator, error)

NewOrchestratorFunc connects an orchestrator to the target.

type Operation

type Operation struct {
	Installation string
	Revision     string
	Action       string
	Bundle       cnab.ExtendedBundle

	// Parameters holds every parameter that applies to the action, typed by
	// its definition: the value the runtime delivered, else the default.
	Parameters map[string]any

	// Credentials holds every credential the runtime delivered for the action.
	Credentials map[string]string

	// Relocation maps the bundle's image references to where the images are
	// on the target. It is empty when the images were not relocated.
	Relocation relocation.ImageRelocationMap
	// contains filtered or unexported fields
}

Operation is what a CNAB runtime hands to the invocation image, seen from inside the container. It is the counterpart of cnab-go's driver.Operation: cnab-go based runtimes, Porter and nemo among them, build one from a claim and turn it into these variables and files.

func ReadOperation

func ReadOperation(container Container) (Operation, error)

ReadOperation reads the operation the runtime handed to the container.

type Options

type Options struct {
	Orchestrator string
	Timeout      time.Duration
	Purge        bool
	// VolumeTypes are what the target makes the volumes of each type of.
	VolumeTypes map[string]target.VolumeType
	// RegistryAuth holds the credentials the images are pulled with.
	RegistryAuth RegistryAuth
}

Options are the installer's reading of the nemo-* parameters, all of them: what the runtime tells it about the target.

type Orchestrator

type Orchestrator interface {
	// Name is the value of the nemo-orchestrator parameter that selects it.
	Name() string

	// Validate reports what it can't honour in the project, without touching the target.
	Validate(project *Project) error

	// Install brings the installation to the project: it creates what is
	// missing, updates what changed, removes what the project no longer
	// declares, and waits until everything converged. It is also the upgrade.
	Install(ctx context.Context, project *Project, opts InstallOptions) error

	// Uninstall removes everything the installation created.
	Uninstall(ctx context.Context, project *Project, opts UninstallOptions) error

	// Close releases the connection to the target.
	Close() error
}

Orchestrator applies a compose project to the target: Compose on a single Docker host, or Swarm. It knows nothing about CNAB.

type Orchestrators

type Orchestrators map[string]NewOrchestratorFunc

Orchestrators are the orchestrators an installer knows, by the value of the nemo-orchestrator parameter. Only the one named is built.

type Problem

type Problem struct {
	Path    string `json:"path"`
	Message string `json:"message"`
}

Problem is something of the compose project an orchestrator can't honour, at its path in the compose file.

func (Problem) Error

func (problem Problem) Error() string

type Problems

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

Problems collects the problems of a project: errors, which stop the action, and warnings, about what an orchestrator ignores. Its methods take values, and every Problems derived with At adds to the same lists.

func NewProblems

func NewProblems() Problems

NewProblems returns an empty collection.

func (Problems) AddIf

func (problem Problems) AddIf(condition bool, message string)

AddIf adds an error at this path when the condition holds.

func (Problems) At

func (problem Problems) At(parts ...string) Problems

At returns the collection at a path below this one.

func (Problems) EmitWarnings

func (problem Problems) EmitWarnings(events progress.Sink)

EmitWarnings sends each warning to events: what the orchestrator ignores does not stop the action, but is said.

func (Problems) Err

func (problem Problems) Err() error

Err joins the errors collected so far, or returns nil.

func (Problems) WarnIf

func (problem Problems) WarnIf(condition bool, message string)

WarnIf adds a warning at this path when the condition holds.

func (Problems) Warnings

func (problem Problems) Warnings() []Problem

Warnings returns the warnings collected so far.

type Project

type Project struct {
	Installation Installation

	// Compose is the compose project, named after the stack. Its configs and
	// secrets hold their content: an orchestrator never reads a file or a
	// variable of the installer to get it.
	Compose *types.Project

	// Levels holds the services in the order of their depends_on: each level
	// only depends on the levels before it.
	Levels [][]string

	// Labels go on every object of the installation.
	Labels map[string]string

	// Provisions holds, by volume name, the directory to create before the
	// volume, as its target's volume type says.
	Provisions map[string]target.VolumeProvision

	// InvocationImage is the installer's own image, which provisions the
	// volumes' directories.
	InvocationImage string

	// RegistryAuth holds the credentials the images are pulled with.
	RegistryAuth RegistryAuth
}

Project is the compose project of an operation, ready for an orchestrator.

func LoadProject

func LoadProject(ctx context.Context, operation Operation) (*Project, error)

LoadProject builds the compose project of the operation's bundle.

The compose documents are interpolated with the parameters, each under the name of its environment destination, so that ${REGION} reads the same as with docker compose. Credentials are not: they reach the containers only as compose secrets, from their environment variable or their file. For an uninstall, configs and secrets are left without their content.

func (*Project) Validate

func (project *Project) Validate() error

Validate reports what of the project no orchestrator can honour: what needs a build, a model provider or lifecycle hooks, and dependencies that can never be met.

type RegistryAuth

type RegistryAuth map[string]registry.AuthConfig

RegistryAuth holds the credentials of registries, by domain, as the runtime hands them in nemo-registry-auth.

func (RegistryAuth) For

func (auth RegistryAuth) For(image string) (string, error)

For returns the encoded credentials of the image's registry, as the Engine API takes them, or nothing when there are none.

type UninstallOptions

type UninstallOptions struct {
	Events progress.Sink
	// RemoveVolumes also removes the volumes, and the data they hold.
	RemoveVolumes bool
}

UninstallOptions are the options of Orchestrator.Uninstall.

type VolumeClaim

type VolumeClaim struct {
	Type    string   `json:"type"`
	Options []string `json:"options,omitempty"`
}

VolumeClaim is what a bundle says of a volume in its x-nemo-volume.

Directories

Path Synopsis
Package compose is the Compose orchestrator: it applies a compose project to one Docker as plain containers, the way docker compose up --wait does, and labels them the way docker compose does, so that docker compose ps and logs still see them.
Package compose is the Compose orchestrator: it applies a compose project to one Docker as plain containers, the way docker compose up --wait does, and labels them the way docker compose does, so that docker compose ps and logs still see them.
convert
Package convert turns a compose project into what the Compose orchestrator creates on the Docker Engine: the create options of each container, its networks and volumes, and the state to wait for, the way docker compose does.
Package convert turns a compose project into what the Compose orchestrator creates on the Docker Engine: the create options of each container, its networks and volumes, and the state to wait for, the way docker compose does.
Package swarm is the Swarm orchestrator: it applies a compose project to a swarm as services, the way docker stack deploy does, and waits until they converged.
Package swarm is the Swarm orchestrator: it applies a compose project to a swarm as services, the way docker stack deploy does, and waits until they converged.
convert
Package convert turns a compose project into the specs of Swarm objects, the way docker stack deploy does (docker/cli, cli/compose/convert).
Package convert turns a compose project into the specs of Swarm objects, the way docker stack deploy does (docker/cli, cli/compose/convert).

Jump to

Keyboard shortcuts

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