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

lifecycle

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Oct 25, 2026 License: MIT Imports: 3 Imported by: 0

Documentation

Overview

Package lifecycle plans the post-build / post-start commands a devcontainer expects to run, in the order required by the spec, with the marker-file scheme that the upstream devcontainer CLI uses.

The package is pure: it does not exec anything itself. Instead, Plan returns a slice of Phase records, and a host-specific package (e.g. pkg/host/docker) decides how to execute each phase against the container at runtime — running it imperatively for docker, projecting it into Pod fields for kubernetes.

Compatibility is intentional. Marker file names, marker contents, command-form semantics (string→shell, array→exec, object→parallel), and run-once vs run-on-start vs run-on-attach mirror upstream's src/spec-common/injectHeadless.ts.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func SystemVarFolder

func SystemVarFolder(override string) string

SystemVarFolder is the system-wide devcontainer state folder used for marker files that need root (e.g. patching /etc/environment). Defaults to "/var/devcontainer" per upstream.

func UserDataFolder

func UserDataFolder(homeDir, containerDataFolder string) string

UserDataFolder returns the per-user devcontainer state folder inside the container. The default is "${homeDir}/.devcontainer", overridable by passing a non-empty containerDataFolder, mirroring upstream's containerDataFolder option.

Types

type Hook

type Hook string

Hook names mirror the spec's command field names so log output and marker filenames stay legible / compatible.

const (
	HookOnCreate      Hook = "onCreateCommand"
	HookUpdateContent Hook = "updateContentCommand"
	HookPostCreate    Hook = "postCreateCommand"
	HookPostStart     Hook = "postStartCommand"
	HookPostAttach    Hook = "postAttachCommand"
)

type Origin

type Origin struct {
	// Source is "devcontainer.json" for top-level commands, or the
	// feature's source ref (e.g. "ghcr.io/devcontainers/features/node:1")
	// for feature-supplied commands.
	Source string
}

Origin records where a command came from, so executors can label log output the way upstream does ("Running postCreateCommand from devcontainer.json..." vs "...from Feature 'ghcr.io/.../node:1'...").

type Phase

type Phase struct {
	Hook    Hook
	When    When
	Origin  Origin
	Command spec.Command
}

Phase is one logical run of a single command (or set of parallel named commands) for a particular hook.

func Plan

func Plan(dc *spec.DevContainer, resolved []features.Resolved) []Phase

Plan returns the ordered phases that should run for the given spec and resolved features, with the standard execution order:

onCreate (features…) → onCreate (spec)
updateContent (features…) → updateContent (spec)
postCreate (features…) → postCreate (spec)
postStart (features…) → postStart (spec)
postAttach (features…) → postAttach (spec)

Within each hook, each feature's command runs in install order, then the spec's own command, matching upstream's metadata order (features before devcontainer.json). Phases whose command is empty are omitted, so callers can simply iterate the returned slice.

func (Phase) MarkerPath

func (p Phase) MarkerPath(userDataFolder string) string

MarkerPath returns the path inside the container that the executor should use to record successful completion. WhenAttach phases have no marker; the empty string is returned in that case.

userDataFolder is the user's devcontainer data folder; pass UserDataFolder(homeDir, "") to use the default.

type When

type When int

When describes how often a Phase runs across container lifetimes.

const (
	// WhenOnce runs at most once per container creation. Marker file's
	// content is the container's createdAt; if the marker is missing or
	// stale, the phase runs and the marker is updated.
	WhenOnce When = iota
	// WhenStart runs once per container start, including initial
	// creation. Marker content is startedAt.
	WhenStart
	// WhenAttach runs every time a client attaches. No marker —
	// upstream re-runs unconditionally on every attach.
	WhenAttach
)

func (When) String

func (w When) String() string

Jump to

Keyboard shortcuts

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