config

package
v0.0.0-...-d444b9f Latest Latest
Warning

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

Go to latest
Published: Apr 24, 2023 License: GPL-3.0 Imports: 10 Imported by: 0

README

README

This README needs to be updated.

Nut must remain backward compatible with respect to nut configuration files. It must also be easy to add new features in nut files, without issues of performance to parse the file, and without applying modifications to all older versions to insure backward compatibility.

The chosen solution is that new features should be defined in the interface, and default behavior/feature should be defined in base class (to be accessible) to all syntaxes version. Then override this default behavior in the new syntax version.

Interfaces Names| Base Class Names | Version 2 | Version 3 | ... ----------------+---------------------+-------------------+-------------------+---- Macro | MacroBase | MacroV2 | MacroV3 | ... MountingPoint | MountingPointBase | MountingPointV2 | MountingPointV3 | ... BaseEnvironment | BaseEnvironmentBase | BaseEnvironmentV2 | BaseEnvironmentV3 | ... Project | ProjectBase | ProjectV2 | ProjectV3 | ...

For each new syntax, copy/paste a project_vXXX.go file (ie the latest one) and change implementation to suit new requirements. For any new feature, create a virtual method in the interface Project (or its components Macro, MountingPoint, BaseEnvironment, etc) and implement a method in ProjectBase class (or its components MacroBase, etc) to define a default behavior for older versions.

Old syntax versions should never be modified. Only the interface, the base class, and the new syntax should be updated.

Note: When working with structs and embedding, everything is STATICALLY LINKED. All references are resolved at compile time. See https://github.com/luciotato/golang-notes/blob/master/OOP.md for more details.

Documentation

Index

Constants

View Source
const NutFileName = "nut.yml"
View Source
const NutOverrideFileName = "nut.override.yml"
View Source
const NutProjectFolderKey = "NUT_PROJECT_FOLDER"

Variables

This section is empty.

Functions

func DownloadFromGithub

func DownloadFromGithub(name string, store Persist.Store) (string, error)

/ Load project from given Github name / If not found on the file system, download it. / Returns the name of the file where / it has been saved from Github, and an error.

func GetActions

func GetActions(macro Macro) []string

func GetAliases

func GetAliases(macro Macro) []string

func GetContainerPath

func GetContainerPath(volume Device) string

func GetDescription

func GetDescription(macro Macro) string

func GetDevices

func GetDevices(config Config) map[string]Device

func GetDockerImage

func GetDockerImage(config Config) string

func GetEnvironmentVariables

func GetEnvironmentVariables(config Config) map[string]string

func GetFullContainerPath

func GetFullContainerPath(volume Volume, context Utils.Context) (string, error)

func GetFullHostPath

func GetFullHostPath(volume Volume, context Utils.Context) (string, error)

func GetHostPath

func GetHostPath(volume Device) string

Define methods over interfaces

func GetMacros

func GetMacros(config Project) map[string]Macro

func GetNetworkMode

func GetNetworkMode(config Config) string

func GetOptions

func GetOptions(bind Bind) string

func GetPorts

func GetPorts(config Config) []string

func GetProjectName

func GetProjectName(config Config) string

func GetSecurityOpts

func GetSecurityOpts(config Config) []string

func GetSyntaxVersion

func GetSyntaxVersion(config Config) string

func GetUTSMode

func GetUTSMode(config Config) string

func GetUsage

func GetUsage(macro Macro) string

func GetUsageText

func GetUsageText(macro Macro) string

func GetVolumeName

func GetVolumeName(volume Volume) string

func GetVolumes

func GetVolumes(config Config, context Utils.Context) map[string]Volume

func GetWorkInProjectFolderAs

func GetWorkInProjectFolderAs(config Config) string

func GetWorkingDir

func GetWorkingDir(config Config) string

func IsCurrentUserEnabled

func IsCurrentUserEnabled(config Config) bool

func IsDetached

func IsDetached(config Config) bool

func IsGUIEnabled

func IsGUIEnabled(config Config) bool

func IsNvidiaDevicesEnabled

func IsNvidiaDevicesEnabled(config Config) bool

func IsPrivileged

func IsPrivileged(config Config) bool

func ResolveDependencies

func ResolveDependencies(project Project, store Persist.Store, nutFilePath string) (err error)

/ Resolve dependencies of the given project / (e.g. by loading other projects from files or downloading them / from Github)

func SetParentProject

func SetParentProject(child Project, parent Project)

func ToYAML

func ToYAML(in interface{}) (out []byte, err error)

func TruthyString

func TruthyString(s string) (bool, bool)

/ Returns the boolean value, and whether there is or not a value

Types

type BaseEnvironment

type BaseEnvironment interface {
	// contains filtered or unexported methods
}

func GetBaseEnv

func GetBaseEnv(config Config) BaseEnvironment

type BaseEnvironmentBase

type BaseEnvironmentBase struct {
}

type BaseEnvironmentV5

type BaseEnvironmentV5 struct {
	BaseEnvironmentBase `yaml:"inheritedValues,inline"`

	FilePath    string `yaml:"nut_file_path,omitempty"`
	GitHub      string `yaml:"github,omitempty"`
	DockerImage string `yaml:"docker_image,omitempty"`
}

type BaseEnvironmentV6

type BaseEnvironmentV6 struct {
	BaseEnvironmentBase `yaml:"inheritedValues,inline"`

	FilePath string `yaml:"nut_file_path,omitempty"`
	GitHub   string `yaml:"github,omitempty"`
}

type BaseEnvironmentV7

type BaseEnvironmentV7 struct {
	BaseEnvironmentBase `yaml:"inheritedValues,inline"`

	FilePath string `yaml:"nut_file_path,omitempty"`
	GitHub   string `yaml:"github,omitempty"`
}

type Bind

type Bind interface {
	// contains filtered or unexported methods
}

type Config

type Config interface {
	// contains filtered or unexported methods
}

func GetParent

func GetParent(config Config) Config

type ConfigBase

type ConfigBase struct {
}

type ConfigV5

type ConfigV5 struct {
	ConfigBase `yaml:"inheritedValues,inline"`

	Mount                map[string][]string `yaml:"mount,omitempty"`
	WorkingDir           string              `yaml:"container_working_directory,omitempty"`
	EnvironmentVariables map[string]string   `yaml:"environment,omitempty"`
	Ports                []string            `yaml:"ports,omitempty"`
	EnableGUI            string              `yaml:"enable_gui,omitempty"`
	EnableNvidiaDevices  string              `yaml:"enable_nvidia_devices,omitempty"`
	Privileged           string              `yaml:"privileged,omitempty"`
	SecurityOpts         []string            `yaml:"security_opts,omitempty"`
	// contains filtered or unexported fields
}

func NewConfigV5

func NewConfigV5(parent Config) *ConfigV5

type ConfigV6

type ConfigV6 struct {
	ConfigBase `yaml:"inheritedValues,inline"`

	DockerImage          string              `yaml:"docker_image,omitempty"`
	Mount                map[string][]string `yaml:"mount,omitempty"`
	WorkingDir           string              `yaml:"container_working_directory,omitempty"`
	EnvironmentVariables map[string]string   `yaml:"environment,omitempty"`
	Ports                []string            `yaml:"ports,omitempty"`
	EnableGUI            string              `yaml:"enable_gui,omitempty"`
	EnableNvidiaDevices  string              `yaml:"enable_nvidia_devices,omitempty"`
	Privileged           string              `yaml:"privileged,omitempty"`
	SecurityOpts         []string            `yaml:"security_opts,omitempty"`
	// contains filtered or unexported fields
}

func NewConfigV6

func NewConfigV6(parent Config) *ConfigV6

type ConfigV7

type ConfigV7 struct {
	ConfigBase `yaml:"inheritedValues,inline"`

	DockerImage           string               `yaml:"docker_image,omitempty"`
	Volumes               map[string]*VolumeV7 `yaml:"volumes,omitempty"`
	WorkingDir            string               `yaml:"container_working_directory,omitempty"`
	EnvironmentVariables  map[string]string    `yaml:"environment,omitempty"`
	Ports                 []string             `yaml:"ports,omitempty"`
	EnableGUI             string               `yaml:"enable_gui,omitempty"`
	EnableNvidiaDevices   string               `yaml:"enable_nvidia_devices,omitempty"`
	Privileged            string               `yaml:"privileged,omitempty"`
	SecurityOpts          []string             `yaml:"security_opts,omitempty"`
	Detached              string               `yaml:"detached,omitempty"`
	UTSMode               string               `yaml:"uts,omitempty"`
	NetworkMode           string               `yaml:"net,omitempty"`
	Devices               map[string]*DeviceV7 `yaml:"devices,omitempty"`
	EnableCurrentUser     string               `yaml:"enable_current_user,omitempty"`
	WorkInProjectFolderAs string               `yaml:"work_in_project_folder_as,omitempty"`
	// contains filtered or unexported fields
}

func NewConfigV7

func NewConfigV7(parent Config) *ConfigV7

type Device

type Device interface {
	// contains filtered or unexported methods
}

type DeviceBase

type DeviceBase struct {
}

type DeviceV7

type DeviceV7 struct {
	DeviceBase `yaml:"inheritedValues,inline"`

	Host      string `yaml:"host_path"`
	Container string `yaml:"container_path"`
	Options   string `yaml:"options,omitempty"`
}

type Macro

type Macro interface {
	// contains filtered or unexported methods
}

type MacroBase

type MacroBase struct {
}

type MacroV5

type MacroV5 struct {
	// A short description of the usage of this macro
	Usage string `yaml:"usage,omitempty"`
	// The commands to execute when this macro is invoked
	Actions []string `yaml:"actions,omitempty"`
	// A list of aliases for the macro
	Aliases []string `yaml:"aliases,omitempty"`
	// Custom text to show on USAGE section of help
	UsageText string `yaml:"usage_for_help_section,omitempty"`
	// A longer explanation of how the macro works
	Description string `yaml:"description,omitempty"`

	MacroBase `yaml:"inheritedValues,inline"`
	ConfigV5  `yaml:"inheritedValues,inline"`
}

type MacroV6

type MacroV6 struct {
	// A short description of the usage of this macro
	Usage string `yaml:"usage,omitempty"`
	// The commands to execute when this macro is invoked
	Actions []string `yaml:"actions,omitempty"`
	// A list of aliases for the macro
	Aliases []string `yaml:"aliases,omitempty"`
	// Custom text to show on USAGE section of help
	UsageText string `yaml:"usage_for_help_section,omitempty"`
	// A longer explanation of how the macro works
	Description string `yaml:"description,omitempty"`

	MacroBase `yaml:"inheritedValues,inline"`
	ConfigV6  `yaml:"inheritedValues,inline"`
}

type MacroV7

type MacroV7 struct {
	// A short description of the usage of this macro
	Usage string `yaml:"usage,omitempty"`
	// The commands to execute when this macro is invoked
	Actions []string `yaml:"actions,omitempty"`
	// A list of aliases for the macro
	Aliases []string `yaml:"aliases,omitempty"`
	// Custom text to show on USAGE section of help
	UsageText string `yaml:"usage_for_help_section,omitempty"`
	// A longer explanation of how the macro works
	Description string `yaml:"description,omitempty"`

	MacroBase `yaml:"inheritedValues,inline"`
	ConfigV7  `yaml:"inheritedValues,inline"`
}

type Project

type Project interface {
	// contains filtered or unexported methods
}

func FindProject

func FindProject(context Utils.Context) (Project, Utils.Context, error)

/ Look for a file from which to parse configuration (nut.yml in current / directory). Parse the file, and returns an updated context (root directory) / TODO: look for nut.yml file in parent folders

func GetSyntaxes

func GetSyntaxes() []Project

func LoadProjectFromFile

func LoadProjectFromFile(fullPath string) (Project, error)

/ Parse Project from file. Given filename must be absolute.

func ProjectFromYAML

func ProjectFromYAML(bytes []byte) (Project, error)

type ProjectBase

type ProjectBase struct {
}

type ProjectV5

type ProjectV5 struct {
	SyntaxVersion string              `yaml:"syntax_version"`
	ProjectName   string              `yaml:"project_name"`
	Base          BaseEnvironmentV5   `yaml:"based_on"`
	Macros        map[string]*MacroV5 `yaml:"macros,omitempty"`

	ProjectBase `yaml:"inheritedValues,inline"`
	ConfigV5    `yaml:"inheritedValues,inline"`
	// contains filtered or unexported fields
}

func NewProjectV5

func NewProjectV5(parent Project) *ProjectV5

type ProjectV6

type ProjectV6 struct {
	SyntaxVersion string              `yaml:"syntax_version"`
	ProjectName   string              `yaml:"project_name"`
	Base          BaseEnvironmentV6   `yaml:"based_on,omitempty"`
	Macros        map[string]*MacroV6 `yaml:"macros,omitempty"`

	ProjectBase `yaml:"inheritedValues,inline"`
	ConfigV6    `yaml:"inheritedValues,inline"`
	// contains filtered or unexported fields
}

func NewProjectV6

func NewProjectV6(parent Project) *ProjectV6

type ProjectV7

type ProjectV7 struct {
	SyntaxVersion string              `yaml:"syntax_version"`
	ProjectName   string              `yaml:"project_name"`
	Base          BaseEnvironmentV7   `yaml:"based_on,omitempty"`
	Macros        map[string]*MacroV7 `yaml:"macros,omitempty"`

	ProjectBase `yaml:"inheritedValues,inline"`
	ConfigV7    `yaml:"inheritedValues,inline"`
	// contains filtered or unexported fields
}

func NewProjectV7

func NewProjectV7(parent Project) *ProjectV7

type Volume

type Volume interface {
	// contains filtered or unexported methods
}

func CheckConflict

func CheckConflict(context Utils.Context, key string, newPoint Volume, mountingPoints map[string]Volume) Volume

Compares a map of Volume, and a given new Volume. Returns the first conflict element from the map, or nil if there wasn't any conflict.

type VolumeBase

type VolumeBase struct {
}

type VolumeV5

type VolumeV5 struct {
	VolumeBase `yaml:"inheritedValues,inline"`

	Host      string `yaml:host_path`
	Container string `yaml:container_path`
}

type VolumeV6

type VolumeV6 struct {
	VolumeBase `yaml:"inheritedValues,inline"`

	Host      string `yaml:host_path`
	Container string `yaml:container_path`
}

type VolumeV7

type VolumeV7 struct {
	VolumeBase `yaml:"inheritedValues,inline"`

	VolumeName string `yaml:"volume_name,omitempty"`
	Host       string `yaml:"host_path,omitempty"`
	Container  string `yaml:"container_path"`
	Options    string `yaml:"options,omitempty"`
}

Jump to

Keyboard shortcuts

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