environment

package
v0.3.13-rc.0 Latest Latest
Warning

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

Go to latest
Published: Mar 21, 2024 License: Apache-2.0 Imports: 23 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// DefaultWorkspaceDir is the default workspace directory
	DefaultWorkspaceDir = "workspace"
)

Variables

View Source
var (
	// GRPCEnvName represents the environment variable name used to pass the GRPC server information to the transformers
	GRPCEnvName = strings.ToUpper(types.AppNameShort) + "_QA_GRPC_SERVER"
	// ProjectNameEnvName stores the project name
	ProjectNameEnvName = strings.ToUpper(types.AppNameShort) + "_PROJECT_NAME"
	// SourceEnvName stores the source path
	SourceEnvName = strings.ToUpper(types.AppNameShort) + "_SOURCE"
	// OutputEnvName stores the output path
	OutputEnvName = strings.ToUpper(types.AppNameShort) + "_OUTPUT"
	// ContextEnvName stores the context
	ContextEnvName = strings.ToUpper(types.AppNameShort) + "_CONTEXT"
	// CurrOutputEnvName stores the location of output from the previous iteration
	CurrOutputEnvName = strings.ToUpper(types.AppNameShort) + "_CURRENT_OUTPUT"
	// RelTemplatesDirEnvName stores the rel templates directory
	RelTemplatesDirEnvName = strings.ToUpper(types.AppNameShort) + "_RELATIVE_TEMPLATES_DIR"
	// TempPathEnvName stores the temp path
	TempPathEnvName = strings.ToUpper(types.AppNameShort) + "_TEMP"
	// EnvNameEnvName stores the environment name
	EnvNameEnvName = strings.ToUpper(types.AppNameShort) + "_ENV_NAME"
)
View Source
var (
	// ErrEnvironmentNotActive represents the error when an environment is not active and a function is called on it.
	ErrEnvironmentNotActive = errors.New("environment Not active. Process is terminating")
)

Functions

This section is empty.

Types

type EnvInfo

type EnvInfo struct {
	Name        string
	ProjectName string

	Isolated bool

	Source                string
	Output                string
	Context               string
	CurrEnvOutputBasePath string
	RelTemplatesDir       string
	TempPath              string
	EnvPlatformConfig     environmenttypes.EnvPlatformConfig
	SpawnContainers       bool
}

EnvInfo stores the envionment generic info

type EnvPathType

type EnvPathType string

EnvPathType stores possible path types

const (
	// SourcePathType represents source path type
	SourcePathType EnvPathType = "Source"
	// OutputPathType represents output path type
	OutputPathType EnvPathType = "Output"
)

type Environment

type Environment struct {
	EnvInfo
	Env          EnvironmentInstance
	Children     []*Environment
	TempPathsMap map[string]string
	// contains filtered or unexported fields
}

Environment is used to manage EnvironmentInstances

func NewEnvironment

func NewEnvironment(envInfo EnvInfo, grpcQAReceiver net.Addr) (env *Environment, err error)

NewEnvironment creates a new environment

func (*Environment) AddChild

func (e *Environment) AddChild(env *Environment)

AddChild adds a child to the environment

func (*Environment) CreateTempRoot

func (e *Environment) CreateTempRoot() string

CreateTempRoot returns the "/" to indicate the temp-root creation. Exposed to be used within path-mapping destination-path template.

func (*Environment) Decode

func (e *Environment) Decode(obj interface{}) interface{}

Decode decodes all paths in the passed obj

func (*Environment) Destroy

func (e *Environment) Destroy() error

Destroy destroys all artifacts specific to the environment

func (*Environment) DownloadAndDecode

func (e *Environment) DownloadAndDecode(obj interface{}, downloadSource bool) interface{}

DownloadAndDecode downloads and decodes the data from the paths in the object

func (*Environment) Encode

func (e *Environment) Encode(obj interface{}) interface{}

Encode encodes all paths in the obj to be relevant to the environment

func (*Environment) Exec

func (e *Environment) Exec(cmd environmenttypes.Command, envList []string) (stdout string, stderr string, exitcode int, err error)

Exec executes an executable within the environment

func (*Environment) GetEnvironmentContext

func (e *Environment) GetEnvironmentContext() string

GetEnvironmentContext returns the context path within the environment

func (*Environment) GetEnvironmentOutput

func (e *Environment) GetEnvironmentOutput() string

GetEnvironmentOutput returns the output path within the environment

func (*Environment) GetEnvironmentSource

func (e *Environment) GetEnvironmentSource() string

GetEnvironmentSource returns the source path within the environment

func (*Environment) GetProjectName

func (e *Environment) GetProjectName() string

GetProjectName returns the project name

func (*Environment) IsPathValid

func (e *Environment) IsPathValid(path string) bool

IsPathValid returns if the project path is valid or not

func (*Environment) OutputRel

func (e *Environment) OutputRel(destPath string) (string, error)

OutputRel makes the path relative. Exposed to be used within path-mapping destination-path template.

func (*Environment) PathType

func (e *Environment) PathType(destPath string) (EnvPathType, error)

PathType makes the path relative. Exposed to be used within path-mapping destination-path template.

func (*Environment) ProcessPathMappings

func (e *Environment) ProcessPathMappings(pathMappings []transformertypes.PathMapping) []transformertypes.PathMapping

ProcessPathMappings post processes the paths in the path mappings

func (*Environment) Rel

func (e *Environment) Rel(destPath string) (string, error)

Rel makes the path relative. Exposed to be used within path-mapping destination-path template.

func (*Environment) Reset

func (e *Environment) Reset() error

Reset resets an environment

func (*Environment) SourceRel

func (e *Environment) SourceRel(destPath string) (string, error)

SourceRel makes the path relative. Exposed to be used within path-mapping destination-path template.

type EnvironmentInstance

type EnvironmentInstance interface {
	Reset() error
	Stat(name string) (fs.FileInfo, error)
	Download(envpath string) (outpath string, err error)
	Upload(outpath string) (envpath string, err error)
	Exec(cmd environmenttypes.Command, envList []string) (stdout string, stderr string, exitcode int, err error)
	Destroy() error

	GetSource() string
	GetContext() string
}

EnvironmentInstance represents a actual instance of an environment which the Environment manages

func NewLocal

func NewLocal(envInfo EnvInfo, grpcQAReceiver net.Addr) (EnvironmentInstance, error)

NewLocal creates a new Local environment

func NewPeerContainer

func NewPeerContainer(envInfo EnvInfo, grpcQAReceiver net.Addr, containerInfo environmenttypes.Container, spawnContainers bool) (EnvironmentInstance, error)

NewPeerContainer creates an instance of peer container based environment

type Local

type Local struct {
	EnvInfo
	WorkspaceSource  string
	WorkspaceContext string
	GRPCQAReceiver   net.Addr
}

Local manages a local machine environment

func (*Local) Destroy

func (e *Local) Destroy() error

Destroy destroys all artifacts specific to the environment

func (*Local) Download

func (e *Local) Download(sourcePath string) (string, error)

Download downloads the path to outside the environment

func (*Local) Exec

func (e *Local) Exec(cmd environmenttypes.Command, envList []string) (stdout string, stderr string, exitcode int, err error)

Exec executes an executable within the environment

func (*Local) GetContext

func (e *Local) GetContext() string

GetContext returns the context of Local

func (*Local) GetSource

func (e *Local) GetSource() string

GetSource returns the source of Local

func (*Local) Reset

func (e *Local) Reset() error

Reset resets the environment to fresh state

func (*Local) Stat added in v0.3.2

func (e *Local) Stat(name string) (fs.FileInfo, error)

Stat returns stat info of the file/dir in the env

func (*Local) Upload

func (e *Local) Upload(sourcePath string) (string, error)

Upload uploads the path from outside the environment into it

type PeerContainer

type PeerContainer struct {
	EnvInfo
	// WorkspaceSource is the directory where the input data resides in the new image.
	WorkspaceSource string
	// OriginalImage is the original image name (for the image without the input data).
	OriginalImage string
	// ContainerInfo contains info about the running container.
	ContainerInfo environmenttypes.Container
	// GRPCQAReceiver is used to ask questions and get answers using the GRPC protocol.
	GRPCQAReceiver net.Addr
}

PeerContainer is supports spawning peer containers to run the environment

func (*PeerContainer) Destroy

func (e *PeerContainer) Destroy() error

Destroy destroys the container instance

func (*PeerContainer) Download

func (e *PeerContainer) Download(path string) (string, error)

Download downloads the path to outside the environment

func (*PeerContainer) Exec

func (e *PeerContainer) Exec(cmd environmenttypes.Command, envList []string) (stdout string, stderr string, exitcode int, err error)

Exec executes a command in the container

func (*PeerContainer) GetContext

func (e *PeerContainer) GetContext() string

GetContext returns the working directory inside the container.

func (*PeerContainer) GetSource

func (e *PeerContainer) GetSource() string

GetSource returns the directory where the input data resides in the new image.

func (*PeerContainer) Reset

func (e *PeerContainer) Reset() error

Reset resets the PeerContainer environment

func (*PeerContainer) Stat added in v0.3.2

func (e *PeerContainer) Stat(name string) (fs.FileInfo, error)

Stat returns stat info of the file/dir in the env

func (*PeerContainer) Upload

func (e *PeerContainer) Upload(outpath string) (string, error)

Upload uploads the path from outside the environment into it

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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