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

metadata

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: 10 Imported by: 0

Documentation

Overview

relationships:

references: [metadata, lifecycle]

Package metadata reads and writes the devcontainer.metadata image label and merges its ordered entries using the upstream devcontainers CLI rules.

relationships:

references: [merge]

relationships:

references: [metadata]

Index

Constants

View Source
const Label = "devcontainer.metadata"

Label is the interoperable image and container label name.

Variables

This section is empty.

Functions

func DockerfileLabel

func DockerfileLabel(entries []Entry) (string, error)

DockerfileLabel escapes a label value for a double-quoted Dockerfile LABEL. Empty metadata adds no instruction, preserving the base image labels.

func Encode

func Encode(entries []Entry) (string, error)

Encode always emits a JSON array, including for a single entry.

func Plan

func Plan(entries []Entry) []lifecycle.Phase

Plan retains entry origins and command forms, grouped in lifecycle phase order.

Types

type CollectOptions

type CollectOptions struct {
	// SkipFeatureCustomizations omits only newly referenced feature customizations.
	SkipFeatureCustomizations bool
	// OmitConfigRemoteEnv omits only the current config's remoteEnv contribution.
	OmitConfigRemoteEnv bool
}

CollectOptions controls newly persisted contributions, preserving inherited entries.

type Entry

type Entry struct {
	ID                   string         `json:"id,omitempty"`
	Init                 *bool          `json:"init,omitempty"`
	Privileged           *bool          `json:"privileged,omitempty"`
	CapAdd               []string       `json:"capAdd,omitempty"`
	SecurityOpt          []string       `json:"securityOpt,omitempty"`
	Entrypoint           string         `json:"entrypoint,omitempty"`
	Mounts               []any          `json:"mounts,omitempty"`
	Customizations       map[string]any `json:"customizations,omitempty"`
	OnCreate             spec.Command   `json:"onCreateCommand,omitzero"`
	UpdateContent        spec.Command   `json:"updateContentCommand,omitzero"`
	PostCreate           spec.Command   `json:"postCreateCommand,omitzero"`
	PostStart            spec.Command   `json:"postStartCommand,omitzero"`
	PostAttach           spec.Command   `json:"postAttachCommand,omitzero"`
	WaitFor              string         `json:"waitFor,omitempty"`
	RemoteUser           string         `json:"remoteUser,omitempty"`
	ContainerUser        string         `json:"containerUser,omitempty"`
	UserEnvProbe         string         `json:"userEnvProbe,omitempty"`
	RemoteEnv            map[string]any `json:"remoteEnv,omitempty"`
	ContainerEnv         map[string]any `json:"containerEnv,omitempty"`
	OverrideCommand      *bool          `json:"overrideCommand,omitempty"`
	PortsAttributes      map[string]any `json:"portsAttributes,omitempty"`
	OtherPortsAttributes map[string]any `json:"otherPortsAttributes,omitempty"`
	ForwardPorts         []any          `json:"forwardPorts,omitempty"`
	ShutdownAction       string         `json:"shutdownAction,omitempty"`
	UpdateRemoteUserUID  *bool          `json:"updateRemoteUserUID,omitempty"`
	HostRequirements     map[string]any `json:"hostRequirements,omitempty"`
}

Entry is one base-image, feature, or devcontainer.json contribution. Feature IDs identify the original user feature reference, not its short ID.

func Collect

func Collect(base []Entry, resolved []features.Resolved, dc *spec.DevContainer) []Entry

Collect appends feature entries in install order, then the config entry. Feature containerEnv is image ENV, rather than label metadata, in upstream.

func CollectWithOptions

func CollectWithOptions(base []Entry, resolved []features.Resolved, dc *spec.DevContainer, opts CollectOptions) []Entry

CollectWithOptions filters only the new feature and config contributions.

func FromConfig

func FromConfig(dc *spec.DevContainer) Entry

FromConfig picks only the properties upstream persists in image metadata.

func Parse

func Parse(value string) ([]Entry, error)

Parse accepts the array and legacy single-object forms. Invalid labels return an error; callers can log it and continue without metadata, as upstream does.

func Read

func Read(labels map[string]string, logf func(string, ...any)) []Entry

Read reads labels and falls back to no metadata on invalid input. The optional logger receives the parse error, matching upstream's nonfatal label handling.

func Substitute

func Substitute(entries []Entry, replace func(string) string) ([]Entry, error)

Substitute applies a string substitution to every metadata value, including object mount fields and all lifecycle command forms. Keys stay unchanged.

func Update

func Update(entries []Entry, dc *spec.DevContainer) []Entry

Update appends only the properties upstream permits to change on an existing labelled container. Its persisted lifecycle and container settings stay intact.

type Merged

type Merged struct {
	*spec.DevContainer
	Customizations        map[string][]any
	Entrypoints           []string
	OnCreateCommands      []spec.Command
	UpdateContentCommands []spec.Command
	PostCreateCommands    []spec.Command
	PostStartCommands     []spec.Command
	PostAttachCommands    []spec.Command
}

Merged keeps the ordinary config shape for Go callers and exposes upstream's collected lifecycle/customization fields in JSON.

func Merge

func Merge(config *spec.DevContainer, entries []Entry) Merged

Merge combines an already-collected list; it does not append config again. The config supplies fields that are not part of image metadata (e.g. image, build, workspace and runArgs). Neither config nor entries is modified.

func (Merged) MarshalJSON

func (m Merged) MarshalJSON() ([]byte, error)

MarshalJSON uses the merged configuration names from the upstream CLI.

Jump to

Keyboard shortcuts

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