provider

package
v0.3.6 Latest Latest
Warning

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

Go to latest
Published: Aug 28, 2023 License: MPL-2.0 Imports: 18 Imported by: 6

Documentation

Index

Constants

View Source
const (
	WorkspaceConfigFile   = "workspace.json"
	MachineConfigFile     = "machine.json"
	ProInstanceConfigFile = "pro.json"
	ProviderConfigFile    = "provider.json"
)
View Source
const (
	DEVPOD             = "DEVPOD"
	DEVPOD_OS          = "DEVPOD_OS"
	DEVPOD_ARCH        = "DEVPOD_ARCH"
	WORKSPACE_ID       = "WORKSPACE_ID"
	WORKSPACE_UID      = "WORKSPACE_UID"
	WORKSPACE_PICTURE  = "WORKSPACE_PICTURE"
	WORKSPACE_FOLDER   = "WORKSPACE_FOLDER"
	WORKSPACE_CONTEXT  = "WORKSPACE_CONTEXT"
	WORKSPACE_ORIGIN   = "WORKSPACE_ORIGIN"
	WORKSPACE_SOURCE   = "WORKSPACE_SOURCE"
	WORKSPACE_PROVIDER = "WORKSPACE_PROVIDER"
	MACHINE_ID         = "MACHINE_ID"
	MACHINE_CONTEXT    = "MACHINE_CONTEXT"
	MACHINE_FOLDER     = "MACHINE_FOLDER"
	MACHINE_PROVIDER   = "MACHINE_PROVIDER"
	PROVIDER_ID        = "PROVIDER_ID"
	PROVIDER_CONTEXT   = "PROVIDER_CONTEXT"
	PROVIDER_FOLDER    = "PROVIDER_FOLDER"
)
View Source
const (
	DockerDriver     = "docker"
	KubernetesDriver = "kubernetes"
)
View Source
const (
	CommandEnv = "COMMAND"
)

Variables

View Source
var (
	WorkspaceSourceGit   = "git:"
	WorkspaceSourceLocal = "local:"
	WorkspaceSourceImage = "image:"
)
View Source
var ProviderNameRegEx = regexp.MustCompile(`[^a-z0-9\-]+`)

Functions

func CombineOptions

func CombineOptions(workspace *Workspace, machine *Machine, options map[string]config.OptionValue) map[string]config.OptionValue

func GetBaseEnvironment

func GetBaseEnvironment(context, provider string) map[string]string

func GetLocksDir added in v0.1.10

func GetLocksDir(context string) (string, error)

func GetMachineDir

func GetMachineDir(context, machineID string) (string, error)

func GetMachinesDir

func GetMachinesDir(context string) (string, error)

func GetProInstanceDir added in v0.3.5

func GetProInstanceDir(context, proInstanceHost string) (string, error)

func GetProInstancesDir added in v0.3.5

func GetProInstancesDir(context string) (string, error)

func GetProviderBinariesDir

func GetProviderBinariesDir(context, providerName string) (string, error)

func GetProviderDir

func GetProviderDir(context, providerName string) (string, error)

func GetProviderOptions

func GetProviderOptions(workspace *Workspace, server *Machine, devConfig *config.Config) map[string]config.OptionValue

func GetProvidersDir

func GetProvidersDir(context string) (string, error)

func GetWorkspaceDir

func GetWorkspaceDir(context, workspaceID string) (string, error)

func GetWorkspacesDir

func GetWorkspacesDir(context string) (string, error)

func MachineExists

func MachineExists(context, machineID string) bool

func Merge

func Merge(m1 map[string]string, m2 map[string]string) map[string]string

func ParseOptions

func ParseOptions(options []string) (map[string]string, error)

func ProInstanceExists added in v0.3.5

func ProInstanceExists(context, proInstanceID string) bool

func SaveMachineConfig

func SaveMachineConfig(machine *Machine) error

func SaveProInstanceConfig added in v0.3.5

func SaveProInstanceConfig(context string, proInstance *ProInstance) error

func SaveProviderConfig

func SaveProviderConfig(context string, provider *ProviderConfig) error

func SaveWorkspaceConfig

func SaveWorkspaceConfig(workspace *Workspace) error

func ToEnvironment

func ToEnvironment(workspace *Workspace, machine *Machine, options map[string]config.OptionValue, extraEnv map[string]string) []string

func ToOptions

func ToOptions(workspace *Workspace, machine *Machine, options map[string]config.OptionValue) map[string]string

func ToOptionsMachine

func ToOptionsMachine(machine *Machine) map[string]string

func ToOptionsWorkspace

func ToOptionsWorkspace(workspace *Workspace) map[string]string

func ToProInstanceID added in v0.3.5

func ToProInstanceID(url string) string

func WorkspaceExists

func WorkspaceExists(context, workspaceID string) bool

Types

type AgentWorkspaceInfo

type AgentWorkspaceInfo struct {
	// Workspace holds the workspace info
	Workspace *Workspace `json:"workspace,omitempty"`

	// Machine holds the machine info
	Machine *Machine `json:"machine,omitempty"`

	// Agent holds the agent info
	Agent ProviderAgentConfig `json:"agent,omitempty"`

	// CLIOptions holds the cli options
	CLIOptions CLIOptions `json:"cliOptions,omitempty"`

	// Options holds the filled provider options for this workspace
	Options map[string]config.OptionValue `json:"options,omitempty"`

	// ContentFolder holds the folder where the content is stored
	ContentFolder string `json:"contentFolder,omitempty"`

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

func CloneAgentWorkspaceInfo added in v0.3.0

func CloneAgentWorkspaceInfo(agentWorkspaceInfo *AgentWorkspaceInfo) *AgentWorkspaceInfo

type CLIOptions added in v0.3.0

type CLIOptions struct {
	// up options
	ID                   string   `json:"id,omitempty"`
	Source               string   `json:"source,omitempty"`
	IDE                  string   `json:"ide,omitempty"`
	IDEOptions           []string `json:"ideOptions,omitempty"`
	PrebuildRepositories []string `json:"prebuildRepositories,omitempty"`
	DevContainerImage    string   `json:"devContainerImage,omitempty"`
	DevContainerPath     string   `json:"devContainerPath,omitempty"`
	WorkspaceEnv         []string `json:"workspaceEnv,omitempty"`
	Recreate             bool     `json:"recreate,omitempty"`
	Proxy                bool     `json:"proxy,omitempty"`
	DisableDaemon        bool     `json:"disableDaemon,omitempty"`
	DaemonInterval       string   `json:"daemonInterval,omitempty"`

	// build options
	Repository string   `json:"repository,omitempty"`
	SkipPush   bool     `json:"skipPush,omitempty"`
	Platform   []string `json:"platform,omitempty"`

	// TESTING
	ForceBuild            bool `json:"forceBuild,omitempty"`
	ForceInternalBuildKit bool `json:"forceInternalBuildKit,omitempty"`
}

type Machine

type Machine struct {
	// ID is the machine id to use
	ID string `json:"id,omitempty"`

	// Folder is the local folder where machine related contents will be stored
	Folder string `json:"folder,omitempty"`

	// Provider is the provider used to create this workspace
	Provider MachineProviderConfig `json:"provider,omitempty"`

	// CreationTimestamp is the timestamp when this workspace was created
	CreationTimestamp types.Time `json:"creationTimestamp,omitempty"`

	// Context is the context where this config file was loaded from
	Context string `json:"context,omitempty"`

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

func CloneMachine

func CloneMachine(server *Machine) *Machine

func FromEnvironment

func FromEnvironment() *Machine

FromEnvironment retrives options from environment and fills a machine with it. This is primarily used by provider implementations.

func LoadMachineConfig

func LoadMachineConfig(context, machineID string) (*Machine, error)

type MachineProviderConfig

type MachineProviderConfig struct {
	// Name is the provider name used to deploy this machine
	Name string `json:"name,omitempty"`

	// Options are the local options that override the global ones
	Options map[string]config.OptionValue `json:"options,omitempty"`
}

type ProInstance added in v0.3.5

type ProInstance struct {
	// Provider is the provider name this pro instance belongs to
	Provider string `json:"provider,omitempty"`

	// Host is the Loft DevPod Pro host to use
	Host string `json:"host,omitempty"`

	// CreationTimestamp is the timestamp when this pro instance was created
	CreationTimestamp types.Time `json:"creationTimestamp,omitempty"`
}

func LoadProInstanceConfig added in v0.3.5

func LoadProInstanceConfig(context, proInstanceHost string) (*ProInstance, error)

type ProviderAgentConfig

type ProviderAgentConfig struct {
	// Local defines if DevPod is running locally
	Local types.StrBool `json:"local,omitempty"`

	// Path is the binary path inside the server devpod will expect the agent binary
	Path string `json:"path,omitempty"`

	// DataPath is the agent path where data is stored
	DataPath string `json:"dataPath,omitempty"`

	// DownloadURL is the base url where to download the agent from
	DownloadURL string `json:"downloadURL,omitempty"`

	// Timeout is the timeout in minutes to wait until the agent tries
	// to turn of the server.
	Timeout string `json:"inactivityTimeout,omitempty"`

	// ContainerTimeout is the timeout in minutes to wait until the agent tries
	// to delete the container.
	ContainerTimeout string `json:"containerInactivityTimeout,omitempty"`

	// InjectGitCredentials signals DevPod if git credentials should get synced into
	// the remote machine for cloning the repository.
	InjectGitCredentials types.StrBool `json:"injectGitCredentials,omitempty"`

	// InjectDockerCredentials signals DevPod if docker credentials should get synced
	// into the remote machine for pulling and pushing images.
	InjectDockerCredentials types.StrBool `json:"injectDockerCredentials,omitempty"`

	// Exec commands that can be used on the remote
	Exec ProviderAgentConfigExec `json:"exec,omitempty"`

	// Binaries is an optional field to specify a binary to execute the commands
	Binaries map[string][]*ProviderBinary `json:"binaries,omitempty"`

	// Driver is the driver to use for deploying the devcontainer. Currently supports
	// docker (default) or kubernetes (experimental)
	Driver string `json:"driver,omitempty"`

	// Kubernetes holds kubernetes specific configuration
	Kubernetes ProviderKubernetesDriverConfig `json:"kubernetes,omitempty"`

	// Docker holds docker specific configuration
	Docker ProviderDockerDriverConfig `json:"docker,omitempty"`
}

type ProviderAgentConfigExec

type ProviderAgentConfigExec struct {
	// Shutdown is the remote command to run when the remote machine
	// should shutdown.
	Shutdown types.StrArray `json:"shutdown,omitempty"`
}

type ProviderBinary

type ProviderBinary struct {
	// The current OS
	OS string `json:"os,omitempty"`

	// The current Arch
	Arch string `json:"arch,omitempty"`

	// Checksum is the sha256 hash of the binary
	Checksum string `json:"checksum,omitempty"`

	// Path is the binary url to download from or relative path to use
	Path string `json:"path,omitempty"`

	// ArchivePath is the path within the archive to extract
	ArchivePath string `json:"archivePath,omitempty"`

	// Name is the name of the binary to store locally
	Name string `json:"name,omitempty"`
}

type ProviderCommands

type ProviderCommands struct {
	// Init is run directly after `devpod provider use`
	Init types.StrArray `json:"init,omitempty"`

	// Command executes a command on the server
	Command types.StrArray `json:"command,omitempty"`

	// Create creates a new server
	Create types.StrArray `json:"create,omitempty"`

	// Delete destroys a server
	Delete types.StrArray `json:"delete,omitempty"`

	// Start starts a stopped server
	Start types.StrArray `json:"start,omitempty"`

	// Stop stops a running server
	Stop types.StrArray `json:"stop,omitempty"`

	// Status retrieves the server status
	Status types.StrArray `json:"status,omitempty"`

	// Proxy proxies commands
	Proxy *ProxyCommands `json:"proxy,omitempty"`
}

type ProviderConfig

type ProviderConfig struct {
	// Name is the name of the provider
	Name string `json:"name,omitempty"`

	// Version is the provider version
	Version string `json:"version,omitempty"`

	// Icon holds an image URL that will be displayed
	Icon string `json:"icon,omitempty"`

	// IconDark holds an image URL that will be displayed in dark mode
	IconDark string `json:"iconDark,omitempty"`

	// Home holds the provider home URL
	Home string `json:"home,omitempty"`

	// Source is the source the provider was loaded from
	Source ProviderSource `json:"source,omitempty"`

	// Description is the provider description
	Description string `json:"description,omitempty"`

	// OptionGroups holds information how to display options
	OptionGroups []ProviderOptionGroup `json:"optionGroups,omitempty"`

	// Options are the provider options.
	Options map[string]*types.Option `json:"options,omitempty"`

	// Agent allows you to override agent configuration
	Agent ProviderAgentConfig `json:"agent,omitempty"`

	// Exec holds the provider commands
	Exec ProviderCommands `json:"exec,omitempty"`

	// Binaries is an optional field to specify a binary to execute the commands
	Binaries map[string][]*ProviderBinary `json:"binaries,omitempty"`
}

func LoadProviderConfig

func LoadProviderConfig(context, provider string) (*ProviderConfig, error)

func ParseProvider

func ParseProvider(reader io.Reader) (*ProviderConfig, error)

func (*ProviderConfig) IsMachineProvider

func (c *ProviderConfig) IsMachineProvider() bool

func (*ProviderConfig) IsProxyProvider added in v0.2.0

func (c *ProviderConfig) IsProxyProvider() bool

type ProviderDockerDriverConfig

type ProviderDockerDriverConfig struct {
	// Path where to find the docker binary, defaults to 'docker'
	Path string `json:"path,omitempty"`

	// If false, DevPod will not try to install docker into the machine.
	Install types.StrBool `json:"install,omitempty"`

	// Environment variables to set when running docker commands
	Env map[string]string `json:"env,omitempty"`
}

type ProviderKubernetesDriverConfig

type ProviderKubernetesDriverConfig struct {
	// Path where to find the kubectl binary, defaults to 'kubectl'
	Path string `json:"path,omitempty"`

	// Namespace is the Kubernetes namespace to use
	Namespace string `json:"namespace,omitempty"`

	// CreateNamespace specifies if DevPod should try to create the namespace
	CreateNamespace types.StrBool `json:"createNamespace,omitempty"`

	// Context is the context to use
	Context string `json:"context,omitempty"`

	// Config is the path to the kube config to use
	Config string `json:"config,omitempty"`

	// ClusterRole defines a role binding with the given cluster role
	// DevPod should create.
	ClusterRole string `json:"clusterRole,omitempty"`

	// ServiceAccount is the service account to use
	ServiceAccount string `json:"serviceAccount,omitempty"`

	// Resources holds the Kubernetes resources for the workspace container
	Resources string `json:"resources,omitempty"`

	// Labels holds the Kubernetes labels for the workspace container
	Labels string `json:"labels,omitempty"`

	// NodeSelector holds the node selector for the workspace pod
	NodeSelector string `json:"nodeSelector,omitempty"`

	// BuildRepository defines the repository to push builds. If empty,
	// DevPod will not try to build any images at all.
	BuildRepository string `json:"buildRepository,omitempty"`

	// BuildkitImage is the build kit image to use
	BuildkitImage string `json:"buildkitImage,omitempty"`

	// BuildkitPrivileged signals if pod should be ran in privileged mode
	BuildkitPrivileged types.StrBool `json:"buildkitPrivileged,omitempty"`

	// BuildkitResources holds the resources the buildkit container should have
	BuildkitResources string `json:"buildkitResources,omitempty"`

	// BuildkitNodeSelector holds the node selector for the build pod
	BuildkitNodeSelector string `json:"buildkitNodeSelector,omitempty"`

	// HelperImage is used to find out cluster architecture and copy files
	HelperImage string `json:"helperImage,omitempty"`

	// HelperResources holds the Kubernetes resources for the workspace init container
	HelperResources string `json:"helperResources,omitempty"`

	// PersistentVolumeSize is the size of the persistent volume in GB
	PersistentVolumeSize string `json:"persistentVolumeSize,omitempty"`

	// StorageClassName is the name of the custom storage class
	StorageClassName string `json:"storageClassName,omitempty"`

	// PVCAccessMode is the access mode of the PVC. ie RWO,ROX,RWX,RWOP
	PVCAccessMode string `json:"pvcAccessMode,omitempty"`

	// PodManifestTemplate is the path of the pod manifest template file
	PodManifestTemplate string `json:"podManifestTemplate,omitempty"`
}

type ProviderOptionGroup

type ProviderOptionGroup struct {
	// Name is the display name of the option group
	Name string `json:"name,omitempty"`

	// Options are the options that belong to this group
	Options []string `json:"options,omitempty"`

	// DefaultVisible defines if the option group should be visible by default
	DefaultVisible bool `json:"defaultVisible,omitempty"`
}

type ProviderSource

type ProviderSource struct {
	// Internal means provider was received internally
	Internal bool `json:"internal,omitempty"`

	// Github source for the provider
	Github string `json:"github,omitempty"`

	// File source for the provider
	File string `json:"file,omitempty"`

	// URL where the provider was downloaded from
	URL string `json:"url,omitempty"`

	// Raw is the exact string we used to load the provider
	Raw string `json:"raw,omitempty"`
}

type ProxyCommands added in v0.2.0

type ProxyCommands struct {
	// Up proxies the up command
	Up types.StrArray `json:"up,omitempty"`

	// Stop proxies the stop command
	Stop types.StrArray `json:"stop,omitempty"`

	// Delete proxies the delete command
	Delete types.StrArray `json:"delete,omitempty"`

	// Ssh proxies the ssh command
	Ssh types.StrArray `json:"ssh,omitempty"`

	// Status proxies the status command
	Status types.StrArray `json:"status,omitempty"`

	// ImportWorkspace proxies the import command
	ImportWorkspace types.StrArray `json:"import,omitempty"`
}

type SubOptions added in v0.3.0

type SubOptions struct {
	Options map[string]*types.Option `json:"options,omitempty"`
}

type Workspace

type Workspace struct {
	// ID is the workspace id to use
	ID string `json:"id,omitempty"`

	// UID is used to identify this specific workspace
	UID string `json:"uid,omitempty"`

	// Folder is the local folder where workspace related contents will be stored
	Folder string `json:"folder,omitempty"`

	// Picture is the project social media image
	Picture string `json:"picture,omitempty"`

	// Provider is the provider used to create this workspace
	Provider WorkspaceProviderConfig `json:"provider,omitempty"`

	// Machine is the machine to use for this workspace
	Machine WorkspaceMachineConfig `json:"machine,omitempty"`

	// IDE holds IDE specific settings
	IDE WorkspaceIDEConfig `json:"ide,omitempty"`

	// Source is the source where this workspace will be created from
	Source WorkspaceSource `json:"source,omitempty"`

	// DevContainerImage is the container image to use, overriding whatever is in the devcontainer.json
	DevContainerImage string `json:"devContainerImage,omitempty"`

	// DevContainerPath is the relative path where the devcontainer.json is located.
	DevContainerPath string `json:"devContainerPath,omitempty"`

	// CreationTimestamp is the timestamp when this workspace was created
	CreationTimestamp types.Time `json:"creationTimestamp,omitempty"`

	// LastUsedTimestamp holds the timestamp when this workspace was last accessed
	LastUsedTimestamp types.Time `json:"lastUsed,omitempty"`

	// Context is the context where this config file was loaded from
	Context string `json:"context,omitempty"`

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

func CloneWorkspace

func CloneWorkspace(workspace *Workspace) *Workspace

func LoadWorkspaceConfig

func LoadWorkspaceConfig(context, workspaceID string) (*Workspace, error)

type WorkspaceIDEConfig

type WorkspaceIDEConfig struct {
	// Name is the name of the IDE
	Name string `json:"name,omitempty"`

	// Options are the local options that override the global ones
	Options map[string]config.OptionValue `json:"options,omitempty"`
}

type WorkspaceMachineConfig

type WorkspaceMachineConfig struct {
	// ID is the machine ID to use for this workspace
	ID string `json:"machineId,omitempty"`

	// UID is the machine UID to use for this workspace
	UID string `json:"machineUid,omitempty"`

	// AutoDelete specifies if the machine should get destroyed when
	// the workspace is destroyed
	AutoDelete bool `json:"autoDelete,omitempty"`
}

type WorkspaceProviderConfig

type WorkspaceProviderConfig struct {
	// Name is the provider name
	Name string `json:"name,omitempty"`

	// Options are the local options that override the global ones
	Options map[string]config.OptionValue `json:"options,omitempty"`
}

type WorkspaceSource

type WorkspaceSource struct {
	// GitRepository is the repository to clone
	GitRepository string `json:"gitRepository,omitempty"`

	// GitBranch is the branch to use
	GitBranch string `json:"gitBranch,omitempty"`

	// GitCommit is the commit SHA to checkout
	GitCommit string `json:"gitCommit,omitempty"`

	// LocalFolder is the local folder to use
	LocalFolder string `json:"localFolder,omitempty"`

	// Image is the docker image to use
	Image string `json:"image,omitempty"`
}

func ParseWorkspaceSource added in v0.2.0

func ParseWorkspaceSource(source string) *WorkspaceSource

func (WorkspaceSource) String

func (w WorkspaceSource) String() string

Jump to

Keyboard shortcuts

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