core

package
v0.3.8-beta Latest Latest
Warning

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

Go to latest
Published: Jul 29, 2022 License: MIT Imports: 47 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	SslBaseDir  = "ssl"
	CaBaseDir   = "rootca"
	CertBaseDir = "certs"
)
View Source
var (
	// FS is a Memory Map Filesystem.
	FS = afero.NewOsFs()
	// AFS is the implementation of Afero Filesystem.
	AFS = &afero.Afero{Fs: FS}
)
View Source
var (
	// ErrEmptyDirName occurs when directory name is empty.
	ErrEmptyDirName = errors.New("empty directory name")
	// ErrFileWithThisDirNameExist occurs when file already exist.
	ErrFileWithThisDirNameExist = errors.New("file with the same name exists")
	// ErrFileNotFound occurs when file is not found.
	ErrFileNotFound = errors.New("file not found")
	// ErrUnknownEnvType occurs when an unknown environment type is specified.
	ErrUnknownEnvType = errors.New("unknown env type")
	// ErrUnknownAction occurs when an unknown actions is called.
	ErrUnknownAction = errors.New("unknown action error")
	// ErrDockerAPIIsUnreachable occurs when Docker is not running, Docker version is too old,
	// or the user who runs the application cannot call Docker API.
	ErrDockerAPIIsUnreachable = errors.New("docker api is unreachable")
	// ErrDockerVersionMismatch occurs when Docker version is too old.
	ErrDockerVersionMismatch = errors.New("docker version is too old")
	// ErrDockerComposeVersionMismatch occurs when docker-compose version is too old.
	ErrDockerComposeVersionMismatch = errors.New("docker-compose version is too old")
	// ErrEnvNameIsInvalid occurs when the environment name is invalid. It should be a valid hostname.
	ErrEnvNameIsInvalid = errors.New("environment name is invalid, it should match RFC1178")
	// ErrEnvIsEmpty occurs when environment name is empty.
	ErrEnvIsEmpty = fmt.Errorf("env name is empty. please run `%v env-init`", AppName)
	// ErrCaCertDoesNotExist occurs when the Signing CA Certificate is not yet created.
	ErrCaCertDoesNotExist = fmt.Errorf(
		"the root CA certificate is missing, please run '%v install' and try again",
		AppName,
	)
	// ErrCannotFindContainer occurs when the application cannot find the requested container.
	ErrCannotFindContainer = errors.New("container cannot be found")
	// ErrTooManyContainersFound occurs when the application found more than 1 container.
	ErrTooManyContainersFound = errors.New("too many containers found")
	// ErrArgumentRequired occurs when the function is called without a required argument.
	ErrArgumentRequired = errors.New("argument required")
	// ErrInvokedAsRootUser occurs when the Application was called by Root user.
	ErrInvokedAsRootUser = errors.New(
		"In most cases, you should not run " +
			AppName + " as root user except for `self-update`. " + "If you are sure you want to do this, use " +
			strings.ToUpper(AppName) + "_ALLOW_SUPERUSER=1.",
	)
)
View Source
var (
	// AppName is the lowercase Application Name, used globally.
	AppName = strings.ToLower(appname)
)
View Source
var (
	TmpFilesList = list.New()
)

Functions

func AppendEnvironmentTemplates

func AppendEnvironmentTemplates(t *template.Template, templateList *list.List, partialName string) error

AppendEnvironmentTemplates tries to look up all the templates dedicated for an environment type.

func AppendMutagenTemplates

func AppendMutagenTemplates(t *template.Template, templateList *list.List, partialName string) error

AppendMutagenTemplates is going to add mutagen configuration templates.

func AppendTemplatesFromPaths

func AppendTemplatesFromPaths(t *template.Template, templateList *list.List, paths []string) error

AppendTemplatesFromPaths appends templates to t from templateList list searching them in paths path list. If it cannot find templates it's not going to fail. If a template with the same name already exists, it's going to skip that template.

func AppendTemplatesFromPathsStatic

func AppendTemplatesFromPathsStatic(t *template.Template, templateList *list.List, paths []string) error

AppendTemplatesFromPathsStatic appends templates to t from templateList list searching them in paths path list. This function looks up templates built to the application's binary (static files). If it cannot find templates it's not going to fail. If a template with the same name already exists, it's going to skip that template.

func ArgumentRequiredError

func ArgumentRequiredError(op string) error

ArgumentRequiredError is a wrapper function for ErrArgumentRequired error.

func AskForConfirmation

func AskForConfirmation(msg string, suppressMessage ...bool) bool

AskForConfirmation ask msg from the user and returns the answer.

func CannotFindContainerError

func CannotFindContainerError(op string) error

CannotFindContainerError is a wrapper function for ErrCannotFindContainer error.

func CheckCaCertificateExistInDir

func CheckCaCertificateExistInDir(caDir string, dontAskRecreate ...bool) bool

CheckCaCertificateExistInDir checks if the CA Certificate PEM file already exists in Dir.

func CheckDocker

func CheckDocker() error

CheckDocker checks if docker-engine is running or not.

func CheckDockerNetworkExist

func CheckDockerNetworkExist(networkName string) (bool, error)

CheckDockerNetworkExist returns true if the docker network exists.

func CheckExitCodeOfCommand

func CheckExitCodeOfCommand(command string) int

CheckExitCodeOfCommand runs a command and returns its exit code.

func CheckFileExists

func CheckFileExists(file string) bool

CheckFileExists checks if the file already exists and ask the user if he'd like to recreate it.

func CheckFileExistsAndRecreate

func CheckFileExistsAndRecreate(file string) bool

CheckFileExistsAndRecreate checks if the file already exists and ask the user if he'd like to recreate it.

If user input is yes - return false (as if the file does not existing).

func CheckRegexInFile

func CheckRegexInFile(regex, filePath string) (bool, error)

CheckRegexInFile checks if the file contains content.

func CheckRegexInString

func CheckRegexInString(regex, str string) bool

CheckRegexInString checks if the string contains content.

func Cleanup

func Cleanup() error

Cleanup removes all the temporary template files.

func ContainsString

func ContainsString(slice []string, val string) bool

ContainsString checks if a slice of string contains a string.

func ConvertTemplateToComposeConfig

func ConvertTemplateToComposeConfig(t *template.Template, templateList *list.List) (compose.ConfigDetails, error)

ConvertTemplateToComposeConfig iterates through all the templates and converts them to docker-compose configurations.

func CreateCaCertificate

func CreateCaCertificate(caDir string) error

CreateCaCertificate creates a Private Key and a Signed CA Certificate in PEM format and writes to file.

func CreateDir

func CreateDir(dir string, perms ...int) error

CreateDir creates the directory if not exist.

func CreateDirAndWriteBytesToFile

func CreateDirAndWriteBytesToFile(bytes []byte, file string, perms ...int) error

CreateDirAndWriteBytesToFile creates the base directory and writes bytes to a file in it.

func CreatePrivKeyAndCertificate

func CreatePrivKeyAndCertificate(
	certDir string, certName string,
	dnsNames []string, caCertFilePath, caPrivKeyFilePath string,
) error

CreatePrivKeyAndCertificate creates a Private Key and a Certificate signed by caCertificate and writes to file in PEM format.

func CreateSignedCertificate

func CreateSignedCertificate(c certificateComponents) ([]byte, error)

func DecompressFileFromArchive

func DecompressFileFromArchive(src io.Reader, archive, filename string) (io.Reader, error)

func DockerComposeCompleter

func DockerComposeCompleter() func(cmd *cobra.Command, args []string, toComplete string) (
	[]string, cobra.ShellCompDirective,
)

DockerComposeCompleter returns a completer function for docker-compose.

func DockerComposeVersionMismatchError

func DockerComposeVersionMismatchError(op string) error

DockerComposeVersionMismatchError is a wrapper function for ErrDockerComposeVersionMismatch error.

func DockerPeeredServices

func DockerPeeredServices(action, networkName string) error

DockerPeeredServices attaches/detaches the common services to the current environment's docker network.

func DockerVersionMismatchError

func DockerVersionMismatchError(op string) error

DockerVersionMismatchError is a wrapper function for ErrDockerVersionMismatch error.

func EncodeRSAPrivateKeyToPEM

func EncodeRSAPrivateKeyToPEM(privateKey *rsa.PrivateKey) ([]byte, error)

EncodeRSAPrivateKeyToPEM encodes Private Key from RSA to PEM format.

func EvalSymlinkPath

func EvalSymlinkPath(file string) (string, error)

EvalSymlinkPath checks if file exists and returns the resolved path if a symlink if file is a symlink,

else it returns the filepath.

func ExecuteTemplate

func ExecuteTemplate(t *template.Template, buffer io.Writer) error

ExecuteTemplate executes the templates, appending some specific template functions to the execution.

func ExtractUnknownArgs

func ExtractUnknownArgs(flags *pflag.FlagSet, args []string) []string

ExtractUnknownArgs returns []string arguments which are not used by pflags.

func FileNotFoundError

func FileNotFoundError(op string) error

FileNotFoundError is a wrapper function for ErrFileNotFound error.

func GenerateAndSaveSSHKeys

func GenerateAndSaveSSHKeys(bitSize int, pathToSave string) error

GenerateAndSaveSSHKeys generates and writes SSH keys with bitSize and saves them to pathToSave.

func GenerateMutagenTemplateFileIfNotExist

func GenerateMutagenTemplateFileIfNotExist() error

GenerateMutagenTemplateFileIfNotExist generates mutagen configuration from template if it doesn't exists.

func GenerateRSAPrivateKey

func GenerateRSAPrivateKey(bitSize int) (*rsa.PrivateKey, error)

GenerateRSAPrivateKey creates a RSA Private Key of specified byte size.

func GenerateSSHPublicKey

func GenerateSSHPublicKey(publicKey *rsa.PublicKey) ([]byte, error)

GenerateSSHPublicKey takes a rsa.PublicKey and return bytes suitable for writing to .pub file returns in the format "ssh-rsa ...".

func GetAppHomeDir

func GetAppHomeDir() string

GetAppHomeDir returns the application's home directory.

func GetAppVersion

func GetAppVersion() *version.Version

GetAppVersion returns a version.Version object contains the application version.

func GetBlackfireCommand

func GetBlackfireCommand() string

GetBlackfireCommand returns the command which is called when the application manipulates blackfire.

func GetBlackfireContainer

func GetBlackfireContainer() string

GetBlackfireContainer returns the container name of the Blackfire debug container.

func GetCaCertificateFilePath

func GetCaCertificateFilePath(caDir string) (string, error)

GetCaCertificateFilePath returns the CA certificate path based on caDir.

func GetCaPrivKeyFilePath

func GetCaPrivKeyFilePath(caDir string) (string, error)

GetCaPrivKeyFilePath returns the CA privkey path based on caDir.

func GetComposerVersion

func GetComposerVersion() (*version.Version, error)

GetComposerVersion returns the Composer Version defined in Viper settings.

func GetContainerIDByName

func GetContainerIDByName(containerName string) (string, error)

GetContainerIDByName returns a container ID of the containerName running in

the current environment.

func GetContainerStateByName

func GetContainerStateByName(containerName string) (string, error)

GetContainerStateByName returns the container state of the containerName running in

the current environment.

func GetCwd

func GetCwd() string

GetCwd returns the current working directory.

func GetDBCommand

func GetDBCommand() string

GetDBCommand returns the command which is called when the application manipulates the database.

func GetDBContainer

func GetDBContainer() string

GetDBContainer returns the name of the database container.

func GetDBDumpCommand

func GetDBDumpCommand() string

GetDBDumpCommand returns the command which is called when the application dumps a database.

func GetDockerNetworksWithLabel

func GetDockerNetworksWithLabel(label string) ([]string, error)

func GetEnvName

func GetEnvName() string

GetEnvName returns the environment name in lowercase format.

func GetEnvNetworkName

func GetEnvNetworkName() string

GetEnvNetworkName returns the environments docker network name in lowercase format.

func GetEnvType

func GetEnvType() string

GetEnvType returns the environment type in lowercase format.

func GetHomeDir

func GetHomeDir() string

GetHomeDir returns the invoking user's home directory.

func GetMagentoBackendFrontname

func GetMagentoBackendFrontname() string

GetMagentoBackendFrontname returns Magento admin path from Viper settings.

func GetMagentoVersion

func GetMagentoVersion() (*version.Version, error)

GetMagentoVersion returns a *version.Version object which contains the Magento version.

func GetMagentoVersionFromViper

func GetMagentoVersionFromViper() (*version.Version, error)

GetMagentoVersionFromViper returns a *version.Version object from Viper settings. Note: If it's unset, it will return a dedicated latest version.

func GetMutagenSyncFile

func GetMutagenSyncFile() string

GetMutagenSyncFile returns the file path of the mutagen sync file.

func GetMutagenSyncIgnore

func GetMutagenSyncIgnore() string

GetMutagenSyncIgnore returns the additional mutagen ignored files from Viper settings.

func GetOSDistro

func GetOSDistro() string

GetOSDistro returns the linux distro name if GOOS is linux, else "darwin" or "windows".

func GetServiceDomain

func GetServiceDomain() string

GetServiceDomain returns the application's service domain.

func GetTraefikDomain

func GetTraefikDomain() string

GetTraefikDomain returns traefik domain from Viper settings.

func GetTraefikFullDomain

func GetTraefikFullDomain() string

GetTraefikFullDomain returns traefik full domain (subdomain + domain merged).

func GetTraefikSubdomain

func GetTraefikSubdomain() string

GetTraefikSubdomain returns traefik subdomain from Viper settings.

func GetWebRoot

func GetWebRoot() string

GetWebRoot returns the content of the WEB_ROOT variable from Viper settings.

func InsertStringAfterOccurrence

func InsertStringAfterOccurrence(args []string, insertStr, searchStr string) []string

InsertStringAfterOccurrence inserts insertStr after the occurrence of searchStr to args and returns args.

If searchStr is not exists it will append to the end of args.

func InsertStringBeforeOccurrence

func InsertStringBeforeOccurrence(args []string, insertStr, searchStr string) []string

InsertStringBeforeOccurrence inserts insertStr before occurrence of searchStr (if exist) to args and returns args.

If searchStr is not exists it will append to the end of args.

func InstallCaCertificate

func InstallCaCertificate(caDir string) error

InstallCaCertificate installs the generated CA certificate.

func InstallDNSResolver

func InstallDNSResolver()

InstallDNSResolver configures local DNS resolution based on the operating system.

func InstallSSHConfig

func InstallSSHConfig() error

InstallSSHConfig updates the ssh config file to use our key if the target host is the tunnel.

func IsAdmin

func IsAdmin() bool

IsAdmin returns true if the user who runs the command is root.

func IsAllowedSuperuser

func IsAllowedSuperuser() bool

IsAllowedSuperuser returns true if the application is allowed to be invoked by root.

func IsBlackfireEnabled

func IsBlackfireEnabled() bool

IsBlackfireEnabled returns true if the blackfire container is enabled.

func IsCommandAvailable

func IsCommandAvailable(name string) bool

IsCommandAvailable returns if the parameter can be find in $PATH.

func IsContainerRunning

func IsContainerRunning(container string) (bool, error)

IsContainerRunning returns true if container is running.

func IsDBEnabled

func IsDBEnabled() bool

IsDBEnabled returns true if the database service is enabled for the current environment.

func IsDebug

func IsDebug() bool

IsDebug returns true if debug mode is set.

func IsMutagenSyncEnabled

func IsMutagenSyncEnabled() bool

IsMutagenSyncEnabled returns true for macOS and Windows (if the WSL2 Direct Mount option is disabled).

func IsServiceEnabled

func IsServiceEnabled(service string) bool

IsServiceEnabled returns true if service is enabled in Viper settings.

func IsSingleWebContainer

func IsSingleWebContainer() bool

IsSingleWebContainer returns true if Single Web Container setting is enabled in Viper settings.

func IsWSL2DirectMount

func IsWSL2DirectMount() bool

IsWSL2DirectMount returns true if WSL2 Direct Mount setting is enabled in Viper settings.

func LookupContainerAddressInNetwork

func LookupContainerAddressInNetwork(containerName, environmentName, networkName string) (string, error)

LookupContainerAddressInNetwork returns the container IP address in the specific network.

func LookupContainerGatewayInNetwork

func LookupContainerGatewayInNetwork(containerName, networkName string) (string, error)

LookupContainerGatewayInNetwork returns the container IP address in the specific network.

func NewDockerClient

func NewDockerClient() (*client.Client, error)

NewDockerClient creates a docker client and return with it.

func Pipeline

func Pipeline(cmds ...*exec.Cmd) (pipeLineOutput, collectedStandardError []byte, pipeLineError error)

Pipeline runs cmds piped after each other.

func Quote

func Quote(s string) string

Quote puts a quote around s string in Unix-like systems and returns it, while it just returns s as-is on Windows.

func ResolveDomainToTraefik

func ResolveDomainToTraefik() bool

ResolveDomainToTraefik returns true if an environment's service containers should resolve their "main" domains to the Traefik container's address. If this is enabled, the nginx/php containers will be able to reach themselves through the traefik proxy.

func RunDockerComposeCommand

func RunDockerComposeCommand(args []string, suppressOsStdOut ...bool) (string, error)

RunDockerComposeCommand runs the passed parameters with docker-compose and returns the output.

func RunDockerComposeWithConfig

func RunDockerComposeWithConfig(
	args []string, details compose.ConfigDetails, suppressOsStdOut ...bool,
) (string, error)

RunDockerComposeWithConfig calls docker-compose with the converted configuration settings (from templates).

func RunMeElevated

func RunMeElevated()

RunMeElevated does nothing on unix systems.

func RunOsCommand

func RunOsCommand(args []string, suppressOsStdOut ...bool) (string, error)

RunOsCommand is going to run a command depending on the caller's operating system.

func SvcEnabledPermissive

func SvcEnabledPermissive(s string) bool

SvcEnabledPermissive returns true if the s service is enabled in Viper settings. This function is also going to return true if the service is not mentioned in Viper settings (defaults to true).

func SvcEnabledStrict

func SvcEnabledStrict(name string) bool

SvcEnabledStrict returns true if the s service is enabled in Viper settings. This function is going to return false if the service is not mentioned in Viper settings (defaults to false).

func TooManyContainersFoundError

func TooManyContainersFoundError(op string) error

TooManyContainersFoundError is a wrapper function for ErrCannotFindContainer error.

func Unzip

func Unzip(src io.Reader, dest string) ([]string, error)

Unzip will decompress a zip archive, moving all files and folders

within the zip file (parameter 1) to an output directory (parameter 2).

Types

This section is empty.

Jump to

Keyboard shortcuts

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