config

package
v0.3.0-alpha.0 Latest Latest
Warning

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

Go to latest
Published: Jul 11, 2023 License: MPL-2.0 Imports: 18 Imported by: 4

Documentation

Index

Constants

View Source
const (
	DockerIDLabel           = "dev.containers.id"
	DockerfileDefaultTarget = "dev_container_auto_added_stage_label"
)
View Source
const DEVCONTAINER_FEATURE_FILE_NAME = "devcontainer-feature.json"

Variables

View Source
var VariableRegExp = regexp.MustCompile(`\${(.*?)}`)

Functions

func CalculatePrebuildHash

func CalculatePrebuildHash(originalConfig *DevContainerConfig, platform, architecture, dockerfileContent string, log log.Logger) (string, error)

func Convert

func Convert(from interface{}, to interface{}) error

func GetDevContainerID

func GetDevContainerID(labels map[string]string) string

func GetRemoteUser

func GetRemoteUser(result *Result) string

func ListToObject

func ListToObject(list []string) map[string]string

func ResolveString

func ResolveString(val string, replace ReplaceFunction) string

func ReverseSlice

func ReverseSlice[T comparable](s []T) []T

func SaveDevContainerJSON

func SaveDevContainerJSON(config *DevContainerConfig) error

func Substitute

func Substitute(substitutionCtx *SubstitutionContext, config interface{}, out interface{}) error

func SubstituteContainerEnv

func SubstituteContainerEnv(containerEnv map[string]string, config interface{}, out interface{}) error

Types

type BuildInfo

type BuildInfo struct {
	ImageDetails  *ImageDetails
	ImageMetadata *ImageMetadataConfig
	ImageName     string
	PrebuildHash  string
}

type BuildOptions

type BuildOptions struct {
	provider2.CLIOptions

	Platform string
	NoBuild  bool
}

type ComposeContainer

type ComposeContainer struct {
	// The name of the docker-compose file(s) used to start the services.
	DockerComposeFile types.StrArray `json:"dockerComposeFile,omitempty"`

	// The service you want to work on. This is considered the primary container for your dev environment which your editor will connect to.
	Service string `json:"service,omitempty"`

	// An array of services that should be started and stopped.
	RunServices []string `json:"runServices,omitempty"`
}

type ConfigBuildOptions

type ConfigBuildOptions struct {
	// The location of the Dockerfile that defines the contents of the container. The path is relative to the folder containing the `devcontainer.json` file.
	Dockerfile string `json:"dockerfile,omitempty"`

	// The location of the context folder for building the Docker image. The path is relative to the folder containing the `devcontainer.json` file.
	Context string `json:"context,omitempty"`

	// Target stage in a multi-stage build.
	Target string `json:"target,omitempty"`

	// Build arguments.
	Args map[string]string `json:"args,omitempty"`

	// The image to consider as a cache. Use an array to specify multiple images.
	CacheFrom types.StrArray `json:"cacheFrom,omitempty"`
}

type ContainerDetails

type ContainerDetails struct {
	ID      string                 `json:"ID,omitempty"`
	Created string                 `json:"Created,omitempty"`
	State   ContainerDetailsState  `json:"State,omitempty"`
	Config  ContainerDetailsConfig `json:"Config,omitempty"`
}

type ContainerDetailsConfig

type ContainerDetailsConfig struct {
	Image  string            `json:"Image,omitempty"`
	User   string            `json:"User,omitempty"`
	Env    []string          `json:"Env,omitempty"`
	Labels map[string]string `json:"Labels,omitempty"`
}

type ContainerDetailsState

type ContainerDetailsState struct {
	Status    string `json:"Status,omitempty"`
	StartedAt string `json:"StartedAt,omitempty"`
}

type DevContainerActions

type DevContainerActions struct {
	// A command to run when creating the container. This command is run after "initializeCommand" and before "updateContentCommand". If this is a single string, it will be run in a shell. If this is an array of strings, it will be run as a single command without shell.
	OnCreateCommand types.StrArray `json:"onCreateCommand,omitempty"`

	// A command to run when creating the container and rerun when the workspace content was updated while creating the container.
	// This command is run after "onCreateCommand" and before "postCreateCommand". If this is a single string, it will be run in a shell.
	// If this is an array of strings, it will be run as a single command without shell.
	UpdateContentCommand types.StrArray `json:"updateContentCommand,omitempty"`

	// A command to run after creating the container. This command is run after "updateContentCommand" and before "postStartCommand".
	// If this is a single string, it will be run in a shell. If this is an array of strings, it will be run as a single command without shell.
	PostCreateCommand types.StrArray `json:"postCreateCommand,omitempty"`

	// A command to run after starting the container. This command is run after "postCreateCommand" and before "postAttachCommand".
	// If this is a single string, it will be run in a shell. If this is an array of strings, it will be run as a single command without shell.
	PostStartCommand types.StrArray `json:"postStartCommand,omitempty"`

	// A command to run when attaching to the container. This command is run after "postStartCommand".
	// If this is a single string, it will be run in a shell. If this is an array of strings, it will be run as a single command without shell.
	PostAttachCommand types.StrArray `json:"postAttachCommand,omitempty"`

	// Tool-specific configuration. Each tool should use a JSON object subproperty with a unique name to group its customizations.
	Customizations map[string]interface{} `json:"customizations,omitempty"`
}

type DevContainerConfig

type DevContainerConfig struct {
	DevContainerConfigBase `json:",inline"`
	DevContainerActions    `json:",inline"`
	NonComposeBase         `json:",inline"`
	ImageContainer         `json:",inline"`
	ComposeContainer       `json:",inline"`
	DockerfileContainer    `json:",inline"`

	// Origin is the origin from where this config was loaded
	Origin string `json:"-"`
}

func CloneDevContainerConfig

func CloneDevContainerConfig(config *DevContainerConfig) *DevContainerConfig

func ParseDevContainerJSON

func ParseDevContainerJSON(folder, relativePath string) (*DevContainerConfig, error)

type DevContainerConfigBase

type DevContainerConfigBase struct {
	// A name for the dev container which can be displayed to the user.
	Name string `json:"name,omitempty"`

	// Features to add to the dev container.
	Features map[string]interface{} `json:"features,omitempty"`

	// Array consisting of the Feature id (without the semantic version) of Features in the order the user wants them to be installed.
	OverrideFeatureInstallOrder []string `json:"overrideFeatureInstallOrder,omitempty"`

	// Ports that are forwarded from the container to the local machine. Can be an integer port number, or a string of the format "host:port_number".
	ForwardPorts types.StrIntArray `json:"forwardPorts,omitempty"`

	// Set default properties that are applied when a specific port number is forwarded.
	PortsAttributes map[string]PortAttribute `json:"portAttributes,omitempty"`

	// Set default properties that are applied to all ports that don't get properties from the setting `remote.portsAttributes`.
	OtherPortsAttributes map[string]PortAttribute `json:"otherPortsAttributes,omitempty"`

	// Controls whether on Linux the container's user should be updated with the local user's UID and GID. On by default when opening from a local folder.
	UpdateRemoteUserUID *bool `json:"updateRemoteUserUID,omitempty"`

	// Remote environment variables to set for processes spawned in the container including lifecycle scripts and any remote editor/IDE server process.
	RemoteEnv map[string]string `json:"remoteEnv,omitempty"`

	// The username to use for spawning processes in the container including lifecycle scripts and any remote editor/IDE server process. The default is the same user as the container.
	RemoteUser string `json:"remoteUser,omitempty"`

	// A command to run locally before anything else. This command is run before "onCreateCommand". If this is a single string, it will be run in a shell. If this is an array of strings, it will be run as a single command without shell.
	InitializeCommand types.StrArray `json:"initializeCommand,omitempty"`

	// Action to take when the user disconnects from the container in their editor. The default is to stop the container.
	ShutdownAction string `json:"shutdownAction,omitempty"`

	// The user command to wait for before continuing execution in the background while the UI is starting up. The default is "updateContentCommand".
	WaitFor string `json:"waitFor,omitempty"`

	// User environment probe to run. The default is "loginInteractiveShell".
	UserEnvProbe string `json:"userEnvProbe,omitempty"`

	// Host hardware requirements.
	HostRequirements *HostRequirements `json:"hostRequirements,omitempty"`

	// Whether to overwrite the command specified in the image. The default is true.
	OverrideCommand *bool `json:"overrideCommand,omitempty"`

	// The path of the workspace folder inside the container.
	WorkspaceFolder string `json:"workspaceFolder,omitempty"`

	// DEPRECATED: Use 'customizations/vscode/settings' instead
	// Machine specific settings that should be copied into the container. These are only copied when connecting to the container for the first time, rebuilding the container then triggers it again.
	Settings map[string]interface{} `json:"settings,omitempty"`

	// DEPRECATED: Use 'customizations/vscode/extensions' instead
	// An array of extensions that should be installed into the container.
	Extensions []string `json:"extensions,omitempty"`

	// DEPRECATED: Use 'customizations/vscode/devPort' instead
	// The port VS Code can use to connect to its backend.
	DevPort int `json:"devPort,omitempty"`
}

type DevPodCustomizations

type DevPodCustomizations struct {
	PrebuildRepository types.StrArray `json:"prebuildRepository,omitempty"`
}

func GetDevPodCustomizations

func GetDevPodCustomizations(parsedConfig *DevContainerConfig) *DevPodCustomizations

type DockerfileContainer

type DockerfileContainer struct {
	// The location of the Dockerfile that defines the contents of the container. The path is relative to the folder containing the `devcontainer.json` file.
	Dockerfile string `json:"dockerFile,omitempty"`

	// The location of the context folder for building the Docker image. The path is relative to the folder containing the `devcontainer.json` file.
	Context string `json:"context,omitempty"`

	// Docker build-related options.
	Build ConfigBuildOptions `json:"build,omitempty"`
}

type FeatureConfig

type FeatureConfig struct {
	// ID of the Feature. The id should be unique in the context of the repository/published package where the feature exists and must match the name of the directory where the devcontainer-feature.json resides.
	ID string `json:"id,omitempty"`

	// Display name of the Feature.
	Name string `json:"name,omitempty"`

	// The version of the Feature. Follows the semanatic versioning (semver) specification.
	Version string `json:"version,omitempty"`

	// Description of the Feature. For the best appearance in an implementing tool, refrain from including markdown or HTML in the description.
	Description string `json:"description,omitempty"`

	// Entrypoint script that should fire at container start up.
	Entrypoint string `json:"entrypoint,omitempty"`

	// Indicates that the Feature is deprecated, and will not receive any further updates/support. This property is intended to be used by the supporting tools for highlighting Feature deprecation.
	Deprecated bool `json:"deprecated,omitempty"`

	// Array of old IDs used to publish this Feature. The property is useful for renaming a currently published Feature within a single namespace.
	LegacyIds []string `json:"legacyIds,omitempty"`

	// Possible user-configurable options for this Feature. The selected options will be passed as environment variables when installing the Feature into the container.
	Options map[string]FeatureConfigOption `json:"options,omitempty"`

	// URL to documentation for the Feature.
	DocumentationURL string `json:"documentationURL,omitempty"`

	// URL to the license for the Feature.
	LicenseURL string `json:"licenseURL,omitempty"`

	// Passes docker capabilities to include when creating the dev container.
	CapAdd []string `json:"capAdd,omitempty"`

	// Adds the tiny init process to the container (--init) when the Feature is used.
	Init *bool `json:"init,omitempty"`

	// Sets privileged mode (--privileged) for the container.
	Privileged *bool `json:"privileged,omitempty"`

	// Sets container security options to include when creating the container.
	SecurityOpt []string `json:"securityOpt,omitempty"`

	// Mounts a volume or bind mount into the container.
	Mounts []*Mount `json:"mounts,omitempty"`

	// Array of ID's of Features that should execute before this one. Allows control for feature authors on soft dependencies between different Features.
	InstallsAfter []string `json:"installsAfter,omitempty"`

	// Container environment variables.
	ContainerEnv map[string]string `json:"containerEnv,omitempty"`

	// Tool-specific configuration. Each tool should use a JSON object subproperty with a unique name to group its customizations.
	Customizations map[string]interface{} `json:"customizations,omitempty"`

	// Origin is the path where the feature was loaded from
	Origin string `json:"-"`
}

func ParseDevContainerFeature

func ParseDevContainerFeature(folder string) (*FeatureConfig, error)

type FeatureConfigOption

type FeatureConfigOption struct {
	// Default value if the user omits this option from their configuration.
	Default types.StrBool `json:"default,omitempty"`

	// A description of the option displayed to the user by a supporting tool.
	Description string `json:"description,omitempty"`

	// The type of the option. Can be 'boolean' or 'string'.  Options of type 'string' should use the 'enum' or 'proposals' property to provide a list of allowed values.
	Type string `json:"type,omitempty"`

	// Allowed values for this option.  Unlike 'proposals', the user cannot provide a custom value not included in the 'enum' array.
	Enum []string `json:"enum,omitempty"`

	// Suggested values for this option.  Unlike 'enum', the 'proposals' attribute indicates the installation script can handle arbitrary values provided by the user.
	Proposals []string `json:"proposals,omitempty"`
}

type FeatureSet

type FeatureSet struct {
	ConfigID string
	Folder   string
	Config   *FeatureConfig
	Options  interface{}
}

type HostRequirements

type HostRequirements struct {
	// Number of required CPUs.
	CPUs int `json:"cpus,omitempty"`

	// Amount of required RAM in bytes. Supports units tb, gb, mb and kb.
	Memory string `json:"memory,omitempty"`

	// Amount of required disk space in bytes. Supports units tb, gb, mb and kb.
	Storage string `json:"storage,omitempty"`

	// If GPU support should be enabled
	GPU bool `json:"gpu,omitempty"`
}

type ImageBuildInfo

type ImageBuildInfo struct {
	User     string
	Metadata *ImageMetadataConfig

	// Either on of these will be filled as will
	Dockerfile   *dockerfile.Dockerfile
	ImageDetails *ImageDetails
}

type ImageContainer

type ImageContainer struct {
	// The docker image that will be used to create the container.
	Image string `json:"image,omitempty"`
}

type ImageDetails

type ImageDetails struct {
	ID     string
	Config ImageDetailsConfig
}

func ContainerToImageDetails

func ContainerToImageDetails(containerDetails *ContainerDetails) *ImageDetails

type ImageDetailsConfig

type ImageDetailsConfig struct {
	User       string
	Env        []string
	Labels     map[string]string
	Entrypoint []string
	Cmd        []string
}

type ImageMetadata

type ImageMetadata struct {
	ID                     string `json:"id,omitempty"`
	Entrypoint             string `json:"entrypoint,omitempty"`
	DevContainerConfigBase `json:",inline"`
	DevContainerActions    `json:",inline"`
	NonComposeBase         `json:",inline"`
}

type ImageMetadataConfig

type ImageMetadataConfig struct {
	Raw    []*ImageMetadata
	Config []*ImageMetadata
}

type MergedDevContainerConfig

type MergedDevContainerConfig struct {
	DevContainerConfigBase  `json:",inline"`
	UpdatedConfigProperties `json:",inline"`
	NonComposeBase          `json:",inline"`
	ImageContainer          `json:",inline"`
	ComposeContainer        `json:",inline"`
	DockerfileContainer     `json:",inline"`

	// Origin is the origin from where this config was loaded
	Origin string `json:"-"`
}

func MergeConfiguration

func MergeConfiguration(config *DevContainerConfig, imageMetadataEntries []*ImageMetadata) (*MergedDevContainerConfig, error)

type Mount

type Mount struct {
	Type     string   `json:"type,omitempty"`
	Source   string   `json:"source,omitempty"`
	Target   string   `json:"target,omitempty"`
	External bool     `json:"external,omitempty"`
	Other    []string `json:"other,omitempty"`
}

func ParseMount

func ParseMount(str string) Mount

func (*Mount) String

func (m *Mount) String() string

func (*Mount) UnmarshalJSON

func (m *Mount) UnmarshalJSON(data []byte) error

type NonComposeBase

type NonComposeBase struct {
	// Application ports that are exposed by the container. This can be a single port or an array of ports. Each port can be a number or a string.
	// A number is mapped to the same port on the host. A string is passed to Docker unchanged and can be used to map ports differently,
	// e.g. "8000:8010".
	AppPort types.StrIntArray `json:"appPort,omitempty"`

	// Container environment variables.
	ContainerEnv map[string]string `json:"containerEnv,omitempty"`

	// The user the container will be started with. The default is the user on the Docker image.
	ContainerUser string `json:"containerUser,omitempty"`

	// Mounts points to set up when creating the container. See Docker's documentation for the --mount option for the supported syntax.
	Mounts []*Mount `json:"mounts,omitempty"`

	// Passes the --init flag when creating the dev container.
	Init *bool `json:"init,omitempty"`

	// Passes the --privileged flag when creating the dev container.
	Privileged *bool `json:"privileged,omitempty"`

	// Passes docker capabilities to include when creating the dev container.
	CapAdd []string `json:"capAdd,omitempty"`

	// Passes docker security options to include when creating the dev container.
	SecurityOpt []string `json:"securityOpt,omitempty"`

	// The arguments required when starting in the container.
	RunArgs []string `json:"runArgs,omitempty"`

	// The --mount parameter for docker run. The default is to mount the project folder at /workspaces/$project.
	WorkspaceMount string `json:"workspaceMount,omitempty"`
}

type PortAttribute

type PortAttribute struct {
	// Defines the action that occurs when the port is discovered for automatic forwarding
	// default=notify
	OnAutoForward string `json:"onAutoForward,omitempty"`

	// Automatically prompt for elevation (if needed) when this port is forwarded. Elevate is required if the local port is a privileged port.
	ElevateIfNeeded bool `json:"elevateIfNeeded,omitempty"`

	// Label that will be shown in the UI for this port.
	// default=Application
	Label string `json:"label,omitempty"`

	// When true, a modal dialog will show if the chosen local port isn't used for forwarding.
	RequireLocalPort bool `json:"requireLocalPort,omitempty"`

	// The protocol to use when forwarding this port.
	Protocol string `json:"protocol,omitempty"`
}

type ReplaceFunction

type ReplaceFunction func(match, variable string, args []string) string

type Result

type Result struct {
	ContainerDetails    *ContainerDetails         `json:"ContainerDetails"`
	MergedConfig        *MergedDevContainerConfig `json:"MergedConfig"`
	SubstitutionContext *SubstitutionContext      `json:"SubstitutionContext"`
}

type SubstitutedConfig

type SubstitutedConfig struct {
	Config *DevContainerConfig
	Raw    *DevContainerConfig
}

type SubstitutionContext

type SubstitutionContext struct {
	DevContainerID           string            `json:"DevContainerID,omitempty"`
	LocalWorkspaceFolder     string            `json:"LocalWorkspaceFolder,omitempty"`
	ContainerWorkspaceFolder string            `json:"ContainerWorkspaceFolder,omitempty"`
	Env                      map[string]string `json:"Env,omitempty"`
}

type UpdatedConfigProperties

type UpdatedConfigProperties struct {
	// Entrypoint script that should fire at container start up.
	Entrypoints []string `json:"entrypoints,omitempty"`

	// A command to run when creating the container. This command is run after "initializeCommand" and before "updateContentCommand". If this is a single string, it will be run in a shell. If this is an array of strings, it will be run as a single command without shell.
	OnCreateCommands []types.StrArray `json:"onCreateCommand,omitempty"`

	// A command to run when creating the container and rerun when the workspace content was updated while creating the container.
	// This command is run after "onCreateCommand" and before "postCreateCommand". If this is a single string, it will be run in a shell.
	// If this is an array of strings, it will be run as a single command without shell.
	UpdateContentCommands []types.StrArray `json:"updateContentCommand,omitempty"`

	// A command to run after creating the container. This command is run after "updateContentCommand" and before "postStartCommand".
	// If this is a single string, it will be run in a shell. If this is an array of strings, it will be run as a single command without shell.
	PostCreateCommands []types.StrArray `json:"postCreateCommand,omitempty"`

	// A command to run after starting the container. This command is run after "postCreateCommand" and before "postAttachCommand".
	// If this is a single string, it will be run in a shell. If this is an array of strings, it will be run as a single command without shell.
	PostStartCommands []types.StrArray `json:"postStartCommand,omitempty"`

	// A command to run when attaching to the container. This command is run after "postStartCommand".
	// If this is a single string, it will be run in a shell. If this is an array of strings, it will be run as a single command without shell.
	PostAttachCommands []types.StrArray `json:"postAttachCommand,omitempty"`

	// Tool-specific configuration. Each tool should use a JSON object subproperty with a unique name to group its customizations.
	Customizations map[string][]interface{} `json:"customizations,omitempty"`
}

type VSCodeCustomizations

type VSCodeCustomizations struct {
	Settings   map[string]interface{} `json:"settings,omitempty"`
	Extensions []string               `json:"extensions,omitempty"`
	DevPort    int                    `json:"devPort,omitempty"`
}

func GetVSCodeConfiguration

func GetVSCodeConfiguration(mergedConfig *MergedDevContainerConfig) *VSCodeCustomizations

Jump to

Keyboard shortcuts

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