project

package
v2.2.10 Latest Latest
Warning

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

Go to latest
Published: Aug 23, 2021 License: GPL-3.0 Imports: 23 Imported by: 0

Documentation

Overview

Package project provides tools to run a Platform.sh local development environment.

Index

Constants

View Source
const (
	// FlagUnset signifies that flag has not been set by user.
	FlagUnset = 0
	// FlagOff signifies that flag is set to off.
	FlagOff = 1
	// FlagOn signifies that flag is set to on.
	FlagOn = 2
)
View Source
const (
	// EnableCron enables cron jobs.
	EnableCron = "enable_cron"
	// EnableWorkers enables workers.
	EnableWorkers = "enable_workers"
	// EnableServiceRoutes enables routes to services like Varnish.
	EnableServiceRoutes = "enable_service_routes"
	// EnablePHPOpcache enables PHP opcache.
	EnablePHPOpcache = "enable_php_opcache"
	// EnableOSXNFSMounts uses NFS for mounts on OSX.
	EnableOSXNFSMounts = "enable_osx_nfs_mounts"
	// DisableYamlOverrides disables Platform.CC specific YAML override files.
	DisableYamlOverrides = "disable_yaml_overrides"
	// DisableAutoCommit disables automatic commit of application container.
	DisableAutoCommit = "disable_auto_commit"
	// DisableSharedGlobalVolume disables the shared global volume.
	DisableSharedGlobalVolume = "disable_shared_global_volume"
)
View Source
const (
	// FlagSourceLocal defines a flag specific to the project.
	FlagSourceLocal = "project"
	// FlagSourceGlobal defines a flag set for all projects.
	FlagSourceGlobal = "global"
	// FlagSourceNone defines a flag that has not been set.
	FlagSourceNone = "unset"
)
View Source
const (
	// MountStrategyNone defines mount strategy where no action is taken.
	MountStrategyNone = "none"
	// MountStrategySymlink defines mount strategy where symlinks are used.
	MountStrategySymlink = "symlink"
	// MountStrategyVolume defines mount strategy where a container volume is used.
	MountStrategyVolume = "volume"
)
View Source
const (
	// OptionSourceLocal defines option source as local to current project.
	OptionSourceLocal = "local"
	// OptionSourceGlobal defines option source as global to the user.
	OptionSourceGlobal = "global"
	// OptionSourceNone defines option source as not set.
	OptionSourceNone = "unset"
)

Variables

View Source
var (
	// ErrContainerNoIP is an error returned when a container has no IP address.
	ErrContainerNoIP = errors.New("container has no ip address")
	// ErrInvalidRelationship is an error returned when Platform.sh relationships are invalid.
	ErrInvalidRelationship = errors.New("one or more relationships are invalid")
	// ErrNoApplicationFound is an error returned when a project has no applications.
	ErrNoApplicationFound = errors.New("project should have at least one application")
	// ErrInvalidDefinition is an error returned when a service definition is invalid.
	ErrInvalidDefinition = errors.New("invalid definition")
	// ErrContainerRunning is returned when attempting to start an already running container.
	ErrContainerRunning = errors.New("container already running")
	// ErrRegistryNotDefined is returned when a registry is not defined.
	ErrRegistryNotDefined = errors.New("registry not defined")
)

Functions

func GetDatabaseTypeNames

func GetDatabaseTypeNames() []string

GetDatabaseTypeNames returns list of all service types that are considered to be a database.

func GetDefinitionEmptyRelationship

func GetDefinitionEmptyRelationship(d interface{}) map[string]interface{}

GetDefinitionEmptyRelationship returns a relationship template/empty for given definition.

func ListOptionDescription

func ListOptionDescription() map[Option]string

ListOptionDescription returns a mapping of option name to its description.

func MatchDatabaseTypeName

func MatchDatabaseTypeName(name string) int

MatchDatabaseTypeName matches given service type with database service type.

Types

type Container

type Container struct {
	Config        container.Config
	Name          string
	Definition    interface{}
	Relationships map[string][]map[string]interface{}
	// contains filtered or unexported fields
}

Container contains information needed to run a container.

func (Container) Build

func (c Container) Build() error

Build runs the build hooks.

func (Container) Commit

func (c Container) Commit() error

Commit commits the container.

func (Container) DeleteCommit

func (c Container) DeleteCommit() error

DeleteCommit deletes the commit image.

func (Container) Deploy

func (c Container) Deploy() error

Deploy runs the deploy hooks.

func (Container) Download

func (c Container) Download(path string, writer io.Writer) error

Download downloads given container path to given writer.

func (Container) DownloadMulti

func (c Container) DownloadMulti(path string, writer io.Writer) error

DownloadMulti downloads container path and writes to given writer as tarball.

func (Container) HasBuild

func (c Container) HasBuild() bool

HasBuild returns true if container has been built.

func (Container) Log

func (c Container) Log() error

Log outputs container logs to log file.

func (Container) LogStdout

func (c Container) LogStdout(follow bool) error

LogStdout dumps container log to stdout.

func (Container) Open

func (c Container) Open() ([]map[string]interface{}, error)

Open opens the container and returns the relationships.

func (Container) PostDeploy

func (c Container) PostDeploy() error

PostDeploy runs the post deploy hooks.

func (Container) SetupMounts

func (c Container) SetupMounts() error

SetupMounts sets up mounts in container.

func (Container) Shell

func (c Container) Shell(user string, cmd []string) (int, error)

Shell accesses the container shell.

func (Container) Start

func (c Container) Start() error

Start starts the container.

func (Container) Upload

func (c Container) Upload(path string, reader io.ReadSeeker) error

Upload uploads given reader to container as a single file at given path.

func (Container) UploadMulti

func (c Container) UploadMulti(path string, reader io.Reader) error

UploadMulti uploads given tarball reader to container.

type FlagInt

type FlagInt uint8

FlagInt defines flag for enabled features. This is the old version that uses bitmasks.

const (
	// IntEnableCron enables cron jobs.
	IntEnableCron FlagInt = 1 << iota
	// IntEnableWorkers enables workers.
	IntEnableWorkers
	// IntEnableServiceRoutes enables routes to services like Varnish.
	IntEnableServiceRoutes
	// IntEnablePHPOpcache enables PHP opcache.
	IntEnablePHPOpcache
	// IntEnableMountVolume mounts Docker volume for Platform.sh mounts (NO LONGER USED).
	IntEnableMountVolume
	// IntEnableOSXNFSMounts uses NFS for mounts on OSX.
	IntEnableOSXNFSMounts
	// IntDisableYamlOverrides disables Platform.CC specific YAML override files.
	IntDisableYamlOverrides
	// IntDisableAutoCommit disables automatic commit of application container.
	IntDisableAutoCommit
)

func (*FlagInt) Add

func (f *FlagInt) Add(flag FlagInt)

Add adds a flag.

func (FlagInt) Has

func (f FlagInt) Has(flag FlagInt) bool

Has checks if flag is set.

func (FlagInt) List

func (f FlagInt) List() map[string]FlagInt

List returns a mapping of flag name to flag value.

func (*FlagInt) Remove

func (f *FlagInt) Remove(flag FlagInt)

Remove removes a flag.

type Flags

type Flags map[string]int

Flags defines flags that enable features.

func (Flags) Descriptions

func (f Flags) Descriptions() map[string]string

Descriptions returns a mapping of flag name to its description.

func (Flags) Get

func (f Flags) Get(name string) int

Get returns the value of the given flag.

func (Flags) GetValueName

func (f Flags) GetValueName(name string) string

GetValueName returns value of flag as a human readable string.

func (Flags) IsOff

func (f Flags) IsOff(name string) bool

IsOff returns true if given flag is off or unset.

func (Flags) IsOn

func (f Flags) IsOn(name string) bool

IsOn returns true if given flag is on.

func (Flags) IsSet

func (f Flags) IsSet(name string) bool

IsSet returns true if given flag has been set by the user.

func (Flags) IsUnset

func (f Flags) IsUnset(name string) bool

IsUnset returns true if given flag has not been set by the user.

func (Flags) IsValidFlag

func (f Flags) IsValidFlag(name string) bool

IsValidFlag returns true if given flag is valid.

func (*Flags) Set

func (f *Flags) Set(name string, value int)

Set sets the value of the given flag.

func (*Flags) UnmarshalJSON

func (f *Flags) UnmarshalJSON(data []byte) error

UnmarshalJSON implements Unmarshaler interface.

type Option

type Option string

Option defines a project option.

const (
	// OptionDomainSuffix sets the internal route domain suffix.
	OptionDomainSuffix Option = "domain_suffix"
	// OptionMountStrategy defines the strategy of dealing with mounts.
	OptionMountStrategy Option = "mount_strategy"
)

func ListOptions

func ListOptions() []Option

ListOptions list all available project options.

func (Option) DefaultValue

func (o Option) DefaultValue() string

DefaultValue returns the default value of the option.

func (Option) Validate

func (o Option) Validate(v string) error

Validate returns error if given value is not a valid.

func (Option) Value

func (o Option) Value(opts map[Option]string) string

Value returns the current value of the option with the default value if empty.

type Project

type Project struct {
	ID        string            `json:"id"`
	Path      string            `json:"-"`
	Apps      []def.App         `json:"-"`
	Routes    []def.Route       `json:"-"`
	Services  []def.Service     `json:"-"`
	Variables def.Variables     `json:"vars"`
	Flags     Flags             `json:"flags"`   // local project flags
	Options   map[Option]string `json:"options"` // local project options

	PlatformSH *platformsh.Project `json:"-"`
	// contains filtered or unexported fields
}

Project defines a platform.sh/cc project.

func LoadFromPath

func LoadFromPath(path string, parseYaml bool) (*Project, error)

LoadFromPath loads a project from its path.

func (*Project) Build

func (p *Project) Build(force bool) error

Build builds all applications in the project.

func (*Project) BuildConfigJSON

func (p *Project) BuildConfigJSON(d interface{}) ([]byte, error)

BuildConfigJSON makes config.json for container runtime.

func (*Project) CopySlot

func (p *Project) CopySlot(destSlot int) error

CopySlot copies the current slot to a given destination slot.

func (*Project) Deploy

func (p *Project) Deploy() error

Deploy runs deploy hooks for all applications in the project.

func (*Project) FlagSource

func (p *Project) FlagSource(name string) string

FlagSource returns the source of the given flag.

func (*Project) GetDatabaseDumpCommand

func (p *Project) GetDatabaseDumpCommand(d interface{}, database string) string

GetDatabaseDumpCommand returns the command to dump a database for given definition.

func (*Project) GetDatabaseShellCommand

func (p *Project) GetDatabaseShellCommand(d interface{}, database string) string

GetDatabaseShellCommand returns the command to access the database shell for given definition.

func (*Project) GetDefinitionBinds

func (p *Project) GetDefinitionBinds(d interface{}) map[string]string

GetDefinitionBinds returns list of Docker binds for given definition.

func (*Project) GetDefinitionBuildCommand

func (p *Project) GetDefinitionBuildCommand(d interface{}) string

GetDefinitionBuildCommand returns build command for given definition.

func (*Project) GetDefinitionContainerType

func (p *Project) GetDefinitionContainerType(d interface{}) container.ObjectContainerType

GetDefinitionContainerType returns the container type for given definition.

func (*Project) GetDefinitionEnvironmentVariables

func (p *Project) GetDefinitionEnvironmentVariables(d interface{}) map[string]string

GetDefinitionEnvironmentVariables returns list of environment variables for given definition.

func (*Project) GetDefinitionHostName

func (p *Project) GetDefinitionHostName(d interface{}) string

GetDefinitionHostName returns the host name for the container of the given definition.

func (*Project) GetDefinitionImages added in v2.2.10

func (p *Project) GetDefinitionImages(d interface{}) []string

GetDefinitionImages returns the container image for the given definition.

func (*Project) GetDefinitionInitCommand

func (p *Project) GetDefinitionInitCommand(d interface{}) string

GetDefinitionInitCommand returns the initalization command fdor the given definition.

func (*Project) GetDefinitionMountCommand

func (p *Project) GetDefinitionMountCommand(d interface{}) string

GetDefinitionMountCommand returns command to setup mounts for given definition.

func (*Project) GetDefinitionName

func (p *Project) GetDefinitionName(d interface{}) string

GetDefinitionName returns the name of given definition.

func (*Project) GetDefinitionPatch

func (p *Project) GetDefinitionPatch(d interface{}) string

GetDefinitionPatch returns patch command to for given definition.

func (*Project) GetDefinitionPostBuildPatch added in v2.2.7

func (p *Project) GetDefinitionPostBuildPatch(d interface{}) string

GetDefinitionPostBuildPatch returns post-build patch command to for given definition.

func (*Project) GetDefinitionPostDeployCommand

func (p *Project) GetDefinitionPostDeployCommand(d interface{}) string

GetDefinitionPostDeployCommand returns post deploy command for given definition.

func (*Project) GetDefinitionRelationships

func (p *Project) GetDefinitionRelationships(d interface{}) map[string][]map[string]interface{}

GetDefinitionRelationships returns relationships for given definition.

func (*Project) GetDefinitionStartCommand

func (p *Project) GetDefinitionStartCommand(d interface{}) []string

GetDefinitionStartCommand returns the start command for the given definition.

func (*Project) GetDefinitionStartOrder

func (p *Project) GetDefinitionStartOrder(defs []interface{}) ([]interface{}, error)

GetDefinitionStartOrder given list of definitions reorder them for optimal start order for relationships.

func (*Project) GetDefinitionType

func (p *Project) GetDefinitionType(d interface{}) string

GetDefinitionType returns the service type for the given definition.

func (*Project) GetDefinitionVariables

func (p *Project) GetDefinitionVariables(d interface{}) map[string]interface{}

GetDefinitionVariables returns flattened variables for given definition.

func (*Project) GetDefinitionVolumes

func (p *Project) GetDefinitionVolumes(d interface{}) map[string]string

GetDefinitionVolumes returns list of Docker volumes for given definition.

func (*Project) GetOption

func (p *Project) GetOption(o Option) string

GetOption returns the given option value globally or local to the project.

func (*Project) GetPlatformApplication

func (p *Project) GetPlatformApplication(d interface{}) string

GetPlatformApplication returns the PLATFORM_APPLICATION environment variable.

func (*Project) GetPlatformEntropy

func (p *Project) GetPlatformEntropy() string

GetPlatformEntropy returns the PLATFORM_ENTROPY environment variable.

func (*Project) GetPlatformEnvironmentVariables

func (p *Project) GetPlatformEnvironmentVariables(d interface{}) map[string]string

GetPlatformEnvironmentVariables returns a map of all PLATFORM_ environment variables.

func (*Project) GetPlatformRelationships

func (p *Project) GetPlatformRelationships(d interface{}) string

GetPlatformRelationships returns the PLATFORM_RELATIONSHIPS environment variable.

func (*Project) GetPlatformRoutes

func (p *Project) GetPlatformRoutes() string

GetPlatformRoutes returns the PLATFORM_ROUTES environment variable.

func (*Project) GetPlatformSHDatabaseDumpCommand

func (p *Project) GetPlatformSHDatabaseDumpCommand(d interface{}, database string, rels map[string]interface{}) string

GetPlatformSHDatabaseDumpCommand returns the command to dump a database from Platform.sh for given definition.

func (*Project) GetPlatformVariables

func (p *Project) GetPlatformVariables(d interface{}) string

GetPlatformVariables returns the PLATFORM_VARIABLES environment variable.

func (*Project) HasFlag

func (p *Project) HasFlag(name string) bool

HasFlag returns true if given flag is on globally or locally to the project.

func (*Project) Load

func (p *Project) Load() error

Load loads the project info from file.

func (*Project) NewContainer

func (p *Project) NewContainer(d interface{}) Container

NewContainer creates a new container.

func (*Project) OptionSource

func (p *Project) OptionSource(o Option) string

OptionSource returns the source of given option.

func (*Project) PlatformSHSyncDatabases

func (p *Project) PlatformSHSyncDatabases(envName string) error

PlatformSHSyncDatabases syncs the given platform.sh environment's databases to the local project.

func (*Project) PlatformSHSyncMounts

func (p *Project) PlatformSHSyncMounts(envName string) error

PlatformSHSyncMounts syncs the given platform.sh environment's mounts to the local project.

func (*Project) PlatformSHSyncVariables

func (p *Project) PlatformSHSyncVariables(envName string) error

PlatformSHSyncVariables syncs the given platform.sh environment's variables to the local project.

func (*Project) PostDeploy

func (p *Project) PostDeploy() error

PostDeploy runs post-deploy hooks for all applications in the project.

func (*Project) Pull

func (p *Project) Pull() error

Pull fetches all the Docker container images needed by the project.

func (*Project) Purge

func (p *Project) Purge() error

Purge purges data related to the project.

func (*Project) PurgeSlot

func (p *Project) PurgeSlot() error

PurgeSlot purges volumes for current slot.

func (*Project) ReplaceDefault

func (p *Project) ReplaceDefault(path string) string

ReplaceDefault replaces {default} in given path with project id + domain suffix.

func (*Project) RouteReplaceDefault

func (p *Project) RouteReplaceDefault(r def.Route) def.Route

RouteReplaceDefault replaces {default} values in all paths.

func (*Project) RoutesReplaceDefault

func (p *Project) RoutesReplaceDefault(routes []def.Route) []def.Route

RoutesReplaceDefault replaces {default} values in all paths for multiple routes.

func (*Project) Save

func (p *Project) Save() error

Save saves the project info to file.

func (*Project) SetContainerHandler

func (p *Project) SetContainerHandler(c container.Interface)

SetContainerHandler sets the container handler.

func (*Project) SetDefaultRegistry added in v2.2.10

func (p *Project) SetDefaultRegistry(registry string) error

SetDefaultRegistry sets the default registry.

func (*Project) SetGlobalConfig

func (p *Project) SetGlobalConfig(gc def.GlobalConfig)

SetGlobalConfig sets the global config, used for testing.

func (*Project) SetNoBuild

func (p *Project) SetNoBuild()

SetNoBuild sets the no build flag.

func (*Project) SetNoCommit

func (p *Project) SetNoCommit()

SetNoCommit sets the no commit flag.

func (*Project) SetSlot

func (p *Project) SetSlot(slot int)

SetSlot sets the current slot.

func (*Project) Start

func (p *Project) Start() error

Start starts the project.

func (*Project) Status

func (p *Project) Status() []container.Status

Status returns list of container status

func (*Project) Stop

func (p *Project) Stop() error

Stop stops the project.

func (*Project) Validate

func (p *Project) Validate() []error

Validate returns list of validation errors for project.

func (*Project) VarDelete

func (p *Project) VarDelete(key string) error

VarDelete deletes a project variable.

func (*Project) VarGet

func (p *Project) VarGet(key string) (string, error)

VarGet retrieves a project variable.

func (*Project) VarSet

func (p *Project) VarSet(key string, value string) error

VarSet sets a project variable.

Jump to

Keyboard shortcuts

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