app

package
v0.1.14-0...-5dc58c9 Latest Latest
Warning

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

Go to latest
Published: Oct 17, 2026 License: MPL-2.0 Imports: 38 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.

State selection precedes boot configuration: an explicit --state wins over the host plan's DefaultState, then Executable.State, then the user's configuration directory. Boot continues through the normal boot.Config path, using published pack defaults, the selected state's .wippy.yaml, profiles and runtime overrides.

OwnedCommand is chosen only when the actual state lock is busy. It starts the application's command in private temporary state seeded from the shipped bundle, without inheriting the owner's .wippy.yaml, history, data bindings or selected deployment. Host preparation and normal runtime overrides still apply; the application implements any connection to the owner itself.

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 LuaCacheIdentity

func LuaCacheIdentity() (schema, toolchain string, err error)

LuaCacheIdentity returns the cache schema and toolchain identity linked into this runtime. Generated application code uses these values in its seed.

func Main

func Main(e Executable)

Main runs the executable with the process arguments. Until the runner hands the process to the Wippy CLI, os.Interrupt and SIGTERM cancel the invocation; afterwards the CLI owns them. A failure is reported 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 NewInvalidApplicationStateError

func NewInvalidApplicationStateError() apierror.Error

NewInvalidApplicationStateError reports a declared state path containing NUL.

func NewInvalidOwnedCommandError

func NewInvalidOwnedCommandError() apierror.Error

NewInvalidOwnedCommandError reports an owned-state command containing NUL.

func NewInvalidPlanError

func NewInvalidPlanError(detail string) apierror.Error

NewInvalidPlanError reports a host decision whose fields cannot describe one invocation.

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 BootLogger

type BootLogger interface {
	BootLogger() *zap.Logger
}

BootLogger supplies the host's structured diagnostic logger before the runtime event bus exists. Hosts that omit it keep ordinary silent startup.

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
	LuaCacheSeed *LuaCacheSeed
	Name         string
	Command      string
	Components   []boot.Component
	// State is the default state directory when the invocation names none. A
	// relative path resolves against the working directory, so each folder
	// holds its own state. Empty selects the user configuration directory.
	State string
	// OwnedCommand, when set, runs that application command in a transient
	// state if acquiring the selected state's lock returns ErrOwned. It applies
	// only to run, after host planning; a plan's Run or Transient takes precedence.
	// Empty preserves the ordinary refusal. No owner readiness or IPC is implied.
	OwnedCommand string
	Bundle       Bundle
}

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 LuaCacheSeed

type LuaCacheSeed struct {
	Digest            string
	SchemaVersion     string
	ToolchainIdentity string
	Archive           []byte
}

LuaCacheSeed is a cache snapshot created while assembling an application: a zip archive with one compressed member per cache file. The archive digest covers every embedded cache file.

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
	Transient    bool
}

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. Transient runs an ordinary application command in a private temporary state. It cannot accompany Run, and it is valid only for OpRun.

Jump to

Keyboard shortcuts

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