config

package
v0.11.1-0...-8ab92b3 Latest Latest
Warning

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

Go to latest
Published: Jul 11, 2022 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// DirectoryName is the name of the directory to store nitro configs
	DirectoryName = ".nitro"

	// ErrNoConfigFile is returned when a configuration file cannot be found
	ErrNoConfigFile = fmt.Errorf("there is no config file for the environment")

	// ErrEmptyfile is returned when a config file is empty
	ErrEmptyfile = fmt.Errorf("the config file appears to be empty")

	// FileName is the default name for the yaml file
	FileName = "nitro.yaml"

	// DefaultEnvs is used to map a config to a known environment variable that is used
	// on the container instances to their default values
	DefaultEnvs = map[string]string{
		"PHP_DISPLAY_ERRORS":              "on",
		"PHP_MEMORY_LIMIT":                "512M",
		"PHP_MAX_EXECUTION_TIME":          "5000",
		"PHP_UPLOAD_MAX_FILESIZE":         "512M",
		"PHP_MAX_INPUT_VARS":              "5000",
		"PHP_POST_MAX_SIZE":               "512M",
		"PHP_OPCACHE_ENABLE":              "0",
		"PHP_OPCACHE_REVALIDATE_FREQ":     "0",
		"PHP_OPCACHE_VALIDATE_TIMESTAMPS": "0",
		"XDEBUG_MODE":                     "off",
		"XDEBUG_SESSION":                  "PHPSTORM",
		"XDEBUG_CONFIG":                   "",
		"BLACKFIRE_SERVER_ID":             "",
		"BLACKFIRE_SERVER_TOKEN":          "",
	}
)

Functions

func IsEmpty

func IsEmpty(home string) (string, error)

IsEmpty is used to check if the config file is empty

Types

type Blackfire

type Blackfire struct {
	ServerID    string `json:"server_id,omitempty" yaml:"server_id,omitempty"`
	ServerToken string `json:"server_token,omitempty" yaml:"server_token,omitempty"`
}

Blackfire allows users to setup their containers to use blackfire locally.

type Config

type Config struct {
	Containers []Container `json:"containers,omitempty" yaml:"containers,omitempty"`
	Blackfire  Blackfire   `json:"blackfire,omitempty" yaml:"blackfire,omitempty"`
	Databases  []Database  `json:"databases,omitempty" yaml:"databases,omitempty"`
	Services   Services    `json:"services" yaml:"services"`
	Sites      []Site      `json:"sites,omitempty" yaml:"sites,omitempty"`
	File       string      `json:"-" yaml:"-"`
}

Config represents the nitro-dev.yaml users add for local development.

func Load

func Load(home string) (*Config, error)

Load is used to return the unmarshalled config, and returns an error when trying to get the users home directory or while marshalling the config.

func (*Config) AddContainer

func (c *Config) AddContainer(container Container) error

AddContainer adds a new container config to an config. It will validate there are no other container names to avoid colision or duplicate ports.

func (*Config) AddSite

func (c *Config) AddSite(s Site) error

AddSite takes a site and adds it to the config

func (*Config) AllSitesWithHostnames

func (c *Config) AllSitesWithHostnames(site Site, addr string) map[string][]string

AllSitesWithHostnames takes the address, which is the nitro-proxy ip address, and the current site and returns a list of all the

func (*Config) DisableBlackfire

func (c *Config) DisableBlackfire(site string) error

DisableBlackfire takes a sites hostname and sets the blackfire option to false. If the site cannot be found, it returns an error.

func (*Config) DisableXdebug

func (c *Config) DisableXdebug(site string) error

DisableXdebug takes a sites hostname and sets the xdebug option to false. If the site cannot be found, it returns an error.

func (*Config) EnableBlackfire

func (c *Config) EnableBlackfire(site string) error

EnableBlackfire takes a sites hostname and sets the xdebug option to true. If the site cannot be found, it returns an error.

func (*Config) EnableXdebug

func (c *Config) EnableXdebug(site string) error

EnableXdebug takes a sites hostname and sets the xdebug option to true. If the site cannot be found, it returns an error.

func (*Config) FindContainerByName

func (c *Config) FindContainerByName(name string) (*Container, error)

FindContainerByName takes a name and returns the container if name matches.

func (*Config) FindSiteByHostName

func (c *Config) FindSiteByHostName(hostname string) (*Site, error)

FindSiteByHostName takes a hostname and returns the site if the hostnames match.

func (*Config) GetFile

func (c *Config) GetFile() string

GetFile returns the file location for the config

func (*Config) ListOfSitesByDirectory

func (c *Config) ListOfSitesByDirectory(home, wd string) []Site

ListOfSitesByDirectory takes the user’s home directory and the current working directory and returns a list of sites within that context.

func (*Config) RemoveContainer

func (c *Config) RemoveContainer(container *Container) error

RemoveContainer takes a name and will remove the container by its name from the config file.

func (*Config) RemoveDatabase

func (c *Config) RemoveDatabase(database Database) error

RemoveDatabase is used to destroy or remove a database engine from the config.

func (*Config) RemoveSite

func (c *Config) RemoveSite(site *Site) error

RemoveSite takes a hostname and will remove the site by its hostname from the config file.

func (*Config) Save

func (c *Config) Save() error

Save takes a file path and marshals the config into a file.

func (*Config) SetPHPBoolSetting

func (c *Config) SetPHPBoolSetting(hostname, setting string, value bool) error

SetPHPBoolSetting is used to set php settings that are bool. It will look for the site by its hostname and change the setting. If it cannot find the site or setting it will return an error.

func (*Config) SetPHPExtension

func (c *Config) SetPHPExtension(hostname, extension string) error

SetPHPExtension is used to set php settings that are bool. It will look for the site by its hostname and change the setting. If it cannot find the site or setting it will return an error.

func (*Config) SetPHPIntSetting

func (c *Config) SetPHPIntSetting(hostname, setting string, value int) error

SetPHPIntSetting is used to set php settings that are ints. It will look for the site by its hostname and change the setting. If it cannot find the site or setting it will return an error.

func (*Config) SetPHPStrSetting

func (c *Config) SetPHPStrSetting(hostname, setting, value string) error

SetPHPStrSetting is used to set php settings that are strings. It will look for the site by its hostname and change the setting. If it cannot find the site or setting it will return an error.

func (*Config) SetSiteAlias

func (c *Config) SetSiteAlias(hostname, alias string) error

SetSiteAlias is used to add an alias domain to a site. If the site cannot be found or the alias is already set it will return an error.

type Container

type Container struct {
	// Name is a uniq name, with no spaces or special characters and is used to generate the hostname
	Name string `json:"name" yaml:"name"`

	// Image the is canonical name of the image to use for the container `docker.elastic.co/elasticsearch/elasticsearch`
	Image string `json:"image" yaml:"image"`

	// Tag tells Nitro which docker image tag to use, it defaults to latest.
	Tag string `json:"tag" yaml:"tag"`

	// Ports is used to expose ports on the host machine to the
	// containers port in the <host>:<container> syntax
	Ports []string `json:"ports,omitempty" yaml:"ports,omitempty"`

	// Volume stores the volumes we should create and maintain for the container (e.g. <name>_container_<vol>_nitro_volume)
	Volumes []string `json:"volumes,omitempty" yaml:"volumes,omitempty"`

	WebGui  int    `json:"web_gui,omitempty" yaml:"web_gui,omitempty"`
	EnvFile string `json:"env_file,omitempty" yaml:"env_file,omitempty"`
}

Container represents a custom container to add to nitro. Containers can be publicly hosted on Docker Hub.

type Database

type Database struct {
	Engine  string `json:"engine" yaml:"engine"`
	Version string `json:"version" yaml:"version"`
	Port    string `json:"port" yaml:"port"`
}

Database is the struct used to represent a database engine that is a combination of a engine (e.g. mariadb, mysql, or postgres), the version number, and the port. The engine and version are directly related to the official docker images on the docker hub.

func (*Database) GetHostname

func (d *Database) GetHostname() (string, error)

GetHostname returns a friendly and predictable name for a database container. It is used for accessing a database by hostname. For example, mysql-8.0-3306 would be the hostname to use in the .env for DB_HOST.

type PHP

type PHP struct {
	DisplayErrors             bool   `json:"display_errors,omitempty" yaml:"display_errors,omitempty"`
	MaxExecutionTime          int    `json:"max_execution_time,omitempty" yaml:"max_execution_time,omitempty"`
	MaxInputVars              int    `json:"max_input_vars,omitempty" yaml:"max_input_vars,omitempty"`
	MaxInputTime              int    `json:"max_input_time,omitempty" yaml:"max_input_time,omitempty"`
	MaxFileUpload             string `json:"max_file_upload,omitempty" yaml:"max_file_upload,omitempty"`
	MemoryLimit               string `json:"memory_limit,omitempty" yaml:"memory_limit,omitempty"`
	OpcacheEnable             bool   `json:"opcache_enable,omitempty" yaml:"opcache_enable,omitempty"`
	OpcacheRevalidateFreq     int    `json:"opcache_revalidate_freq,omitempty" yaml:"opcache_revalidate_freq,omitempty"`
	OpcacheValidateTimestamps bool   `json:"opcache_validate_timestamps,omitempty" yaml:"opcache_validate_timestamps,omitempty"`
	PostMaxSize               string `json:"post_max_size,omitempty" yaml:"post_max_size,omitempty"`
	UploadMaxFileSize         string `json:"upload_max_file_size,omitempty" yaml:"upload_max_file_size,omitempty"`
}

PHP is nested in a configuration and allows setting environment variables for sites to override in the local development environment.

type Services

type Services struct {
	DynamoDB bool `json:"dynamodb"`
	Mailhog  bool `json:"mailhog"`
	Minio    bool `json:"minio"`
	Redis    bool `json:"redis"`
}

Services define common tools for development that should run as containers. We don't expose the volumes, ports, and networking options for these types of services. We plan to support "custom" container options to make local users development even better.

type Site

type Site struct {
	Hostname   string   `json:"hostname" yaml:"hostname"`
	Aliases    []string `json:"aliases,omitempty" yaml:"aliases,omitempty"`
	Path       string   `json:"path" yaml:"path"`
	Version    string   `json:"version" yaml:"version"`
	PHP        PHP      `json:"php,omitempty" yaml:"php,omitempty"`
	Extensions []string `json:"extensions,omitempty" yaml:"extensions,omitempty"`
	Webroot    string   `json:"webroot" yaml:"webroot"`
	Xdebug     bool     `json:"xdebug" yaml:"xdebug"`
	Blackfire  bool     `json:"blackfire" yaml:"blackfire"`
}

Site represents a web application. It has a hostname, aliases (which are alternate domains), the local path to the site, additional mounts to add to the container, and the directory the index.php is located.

func (*Site) AsEnvs

func (s *Site) AsEnvs(addr string) []string

AsEnvs takes a gateway addr and turns specific options such as PHP settings into env vars that can be set on the containers environment

func (*Site) GetAbsContainerPath

func (s *Site) GetAbsContainerPath(home string) (string, error)

GetAbsContainerPath gets the directory for a site’s container path.

func (*Site) GetAbsPath

func (s *Site) GetAbsPath(home string) (string, error)

GetAbsPath gets the directory for a site.Path, It is used to create the mount for a sites container.

func (*Site) GetContainerPath

func (s *Site) GetContainerPath() string

GetContainerPath is responsible for looking at the site’s web root and determing the correct path in the container. This is used for the craft and queue commands to identify the location of the "craft" executable.

Jump to

Keyboard shortcuts

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