app

package
v0.1.14-0...-40cbb9c Latest Latest
Warning

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

Go to latest
Published: Sep 21, 2026 License: MPL-2.0 Imports: 31 Imported by: 0

Documentation

Overview

Package app runs a native executable built on the Wippy runtime.

An executable declares the packs it ships, the application command it starts and the state it owns. Its arguments are:

<exe> [--state DIR] run     <app args...>    ordinary start
<exe> [--state DIR] update  <hub args...>    move the deployment forward
<exe> [--state DIR] recover <app args...>    boot the shipped packs afresh
<exe> [--state DIR] wippy   <cli args...>    the Wippy CLI on the deployment

run, update, recover and wippy are reserved as the first argument by design. A bare invocation, or one whose first word is none of the four, selects run and passes every argument to the application. --state DIR or --state=DIR is the only argument the runner reads and it precedes the verb; everything after the verb belongs to the verb, including an argument shaped like a flag. Owned reports whether a state directory has an owner right now.

Package app hosts native applications built on the Wippy runtime.

Index

Constants

This section is empty.

Variables

View Source
var ErrOwned apierror.Error = apierror.New(apierror.Conflict, "application state is owned")

ErrOwned means another invocation owns the selected application state. It says nothing about the owner's identity, readiness or ability to accept clients. Every owned-state failure matches it with errors.Is.

Functions

func Main

func Main(e Executable)

Main runs the executable with the process arguments under a context that ends on os.Interrupt or SIGTERM, reports a failure on stderr and exits 1.

func NewApplicationStateError

func NewApplicationStateError(operation, target string, cause error) apierror.Error

NewApplicationStateError reports an operation on the application state directory that could not be completed.

func NewArtifactCacheError

func NewArtifactCacheError(detail, subject string, cause error) apierror.Error

NewArtifactCacheError reports content that could not be placed in the application artifact cache.

func NewBundledPackError

func NewBundledPackError(module, detail string, cause error) apierror.Error

NewBundledPackError reports a shipped pack that does not carry the identity or the content the bundle declares for it. Detail names the part of the pack the executable and the bundle disagree about.

func NewCurrentDeploymentError

func NewCurrentDeploymentError(detail, path string, cause error) apierror.Error

NewCurrentDeploymentError reports a current record that does not name a deployment this state holds.

func NewDataEnvironmentBindingError

func NewDataEnvironmentBindingError(name, path string) apierror.Error

NewDataEnvironmentBindingError reports a data environment entry whose name or relative path cannot bind to a path inside the state directory.

func NewDeploymentApplicationError

func NewDeploymentApplicationError(root string) apierror.Error

NewDeploymentApplicationError reports a deployment that selects an application other than the one the executable ships.

func NewDuplicateBundledModuleError

func NewDuplicateBundledModuleError(module string) apierror.Error

NewDuplicateBundledModuleError reports a module a bundle ships twice, which leaves the version the deployment selects undecided.

func NewExistingDeploymentLockError

func NewExistingDeploymentLockError(cause error) apierror.Error

NewExistingDeploymentLockError reports a deployment directory whose lock file the executable cannot read.

func NewInvalidApplicationNameError

func NewInvalidApplicationNameError(name string) apierror.Error

NewInvalidApplicationNameError reports an executable whose application name cannot address a state directory.

func NewMissingApplicationCommandError

func NewMissingApplicationCommandError() apierror.Error

NewMissingApplicationCommandError reports an executable that names no default application command.

func NewMissingBundledApplicationError

func NewMissingBundledApplicationError(root string) apierror.Error

NewMissingBundledApplicationError reports a bundle whose packs do not include the application it selects as its root.

func NewMissingStateDirectoryError

func NewMissingStateDirectoryError() apierror.Error

NewMissingStateDirectoryError reports a --state flag that names no directory.

func NewModuleArtifactError

func NewModuleArtifactError(detail, module, version string, cause error) apierror.Error

NewModuleArtifactError reports a module record whose name, version or digest does not identify the artifact it pins.

func NewOwnedStateError

func NewOwnedStateError(cause error) apierror.Error

NewOwnedStateError reports that another invocation holds the application state directory, carrying the lock attempt that observed it.

func NewRetainedDeploymentError

func NewRetainedDeploymentError(detail, path string, cause error) apierror.Error

NewRetainedDeploymentError reports a retained deployment that does not hold the immutable shape the artifact cache reads it as.

func NewUpdateError

func NewUpdateError(stage string, cause error) apierror.Error

NewUpdateError reports an update stage that failed. The active deployment stays the one the state already selects.

func NewUpdatedModuleError

func NewUpdatedModuleError(detail, module string, cause error) apierror.Error

NewUpdatedModuleError reports a module the update candidate selects whose artifact is missing or does not carry the content the lock pins.

func Owned

func Owned(state string) (bool, error)

Owned reports whether an invocation holds the state lock at the moment of the call. It is a snapshot: it opens the lock file only when that file already exists, releases the lock immediately and creates nothing, so it leaves an absent state absent. A host uses it to describe the state it is about to select; ErrOwned from Run is the authoritative answer.

func Run

func Run(ctx context.Context, e Executable, args []string) error

Run executes one invocation of the executable. It validates the declaration, parses the argument grammar, gives the host its plan and then carries out the selected operation.

Types

type Bundle

type Bundle struct {
	Root  string
	Packs []Pack
}

Bundle is the complete offline deployment shipped by an executable. Root selects the application; other packs are its locked dependencies.

func (Bundle) ID

func (bundle Bundle) ID() string

ID is the identity of the exact content an executable ships. It names the deployment directory the bundle seeds, so two executables carrying different packs seed and keep separate deployments in one state directory.

func (Bundle) Seed

func (bundle Bundle) Seed(directory string) (string, error)

Seed installs an initial Wippy deployment in directory and returns its lock path. An existing deployment must select the same application and is never replaced, including when its version differs from the embedded pack. Directory contains deployment files. Store application databases separately.

type Executable

type Executable struct {
	Data       map[string]string
	Host       Host
	Name       string
	Command    string
	Bundle     Bundle
	Components []boot.Component
}

Executable is the complete declaration of a native Wippy application.

Name       addresses the default state directory, ^[a-z][a-z0-9_-]*$
Command    the application command an ordinary start runs
Bundle     the packs the executable ships, immutable
Data       application-owned environment variables bound to paths inside
           the state directory; a variable the environment already carries
           is a user override and keeps its value
Components the native components the host adds to the runtime
Host       decides what an invocation does, optional

The declaration order below follows the memory layout the runtime pins.

type Host

type Host interface {
	Plan(ctx context.Context, l Launch) (Plan, error)
}

Host decides what an invocation does before the runner opens the state.

type Launch

type Launch struct {
	Command  string
	State    string
	Dir      string
	Args     []string
	Op       Op
	Explicit bool
}

Launch describes one invocation to the host. State is already resolved and absolute, and Explicit reports that --state selected it. Owned answers whether a state has an owner, including a state the host selects itself.

type Op

type Op int

Op is the operation an invocation selects.

const (
	OpRun Op = iota
	OpUpdate
	OpRecover
	OpWippy
)

func (Op) String

func (op Op) String() string

String returns the verb that selects the operation.

type Pack

type Pack struct {
	Module  string
	Version string
	Digest  string
	Data    []byte
}

Pack is an exact published artifact, including its Hub identity. Digest is the SHA-256 of Data, with a sha256: prefix.

type Plan

type Plan struct {
	Run          func(context.Context) error
	Prepare      func(context.Context) (boot.Config, func() error, error)
	DefaultState string
	Command      string
	Args         []string
}

Plan is the host's decision for one launch. A non-empty DefaultState replaces the executable's default state when the invocation did not explicitly name one with --state. Command or Args replace the values the grammar selected. Run hands the whole launch to the host. Prepare opens host resources under the state lock and returns the configuration they need together with the close that releases them.

Jump to

Keyboard shortcuts

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