This project provides a series of processes which can help you systematize some processes in your project.
Install Bundle provides a series of commands that can be configured to:
- Run symfony commands, whether native or custom
- Execute directory creation, symlink and mirror
- Run server operating system commands (CLI)
- Validate path directories and files in a custom way
PHP version >= 8.0 & Symfony >=5.0
All these processes use the symfony components: Console, Filesystem and Process
composer require zyos/install-bundle
If you don't use flex (you should), you need to enable the package manually:
// config/bundles.php
return [
/** ... **/
Zyos\InstallBundle\InstallBundle::class => ['all' => true],
];
It is necessary to create the configuration file in the path:
config/packages/zyos_install.yaml
These are the basic configurations that you need to enter for proper functioning.
The environments in which the different Install Bundle commands can be executed.
If this parameter is not assigned, "prod" is generated by default.
These environments are not limited by the Symfony .env files, in this case you can create your custom environments and run them in the sequence of your preference.
zyos_install:
environments: ['dev', 'prod', 'test']
It is possible to generate execution locks in certain environments, in this case a lock.lock file is generated which will generate the corresponding lock, this lock is only generated when the zyos:install command is executed.
If this parameter is not assigned, "prod" is generated by default.
zyos_install:
locks: ['prod', 'staging']
The lock file is created directly in the symfony project src/Resources/zyos-install-bundle/lock.lock
You must ensure that this directory is created
This command executes only and exclusively Symfony commands which can be customized or any type of command within Symfony.
zyos_install:
install:
- command: 'app:command'
arguments: {'argument': 'hello world', '--option': true}
enable: true
environments: [ 'prod', 'dev' ]
priority: 1
if_error: 'stop'
- command: (string) command to execute.
- arguments: (array) array of data with key value which are necessary for the command.
- enable: (boolean) enable or disable command on execution.
- environments: (array) environments in which the command will be executed.
- priority: (integer): It is the priority at which the command will be executed, (in positive values) the higher the number, less priority it has, (in negative numbers) the higher the number, more priority it has.
- if_error: (enum:[none, stop]) This field limits the action of the command in case of an error, the commands (CLI) return 3 exit codes: success: 0, Failure: 1, Invalid: 2. In this case there are two values in case of error: 1 and 2 which the command can be stopped and the following configured commands are not executed, in this case the value is used: "stop", in case an error occurs but the execution process of the following commands is not stopped, it is used the value: "none".
php bin/console zyos:install
php bin/console zyos:install <environment>
php bin/console zyos:install dev
php bin/console zyos:install --show-output prod
Usage:
zyos:install [options] [--] [<environment>]
Arguments:
environment: Runtime environment [default: "dev"]
Options:
--show-output: Show command output
This command uses the Filesystem component with which you can create directories, Symlink and Mirror directories and files, this process is for creating structures for the project.
zyos_install:
filesystem:
- source: '%kernel.project_dir%/public/test'
destination: '%kernel.project_dir%/public/test'
environments: [ 'prod', 'dev' ]
type: directory
priority: 3
if_error: 'stop'
- source: (string) directory and/or file source path.
- destination: (string) directory and/or file destination path.
- environments: (array) environments in which the command will be executed.
- type: (enum:[directory, symlink, mirror]) type of creation.
- priority: (integer): It is the priority at which the command will be executed, (in positive values) the higher the number, less priority it has, (in negative numbers) the higher the number, more priority it has.
- if_error: (enum:[none, stop]) This field limits the action of the command in case of an error, the commands (CLI) return 3 exit codes: success: 0, Failure: 1, Invalid: 2. In this case there are two values in case of error: 1 and 2 which the command can be stopped and the following configured commands are not executed, in this case the value is used: "stop", in case an error occurs but the execution process of the following commands is not stopped, it is used the value: "none".
Keep in mind: when the type is "directory" it is necessary that both "source" and "destination" be the same, so that a creation problem is not generated.
php bin/console zyos:filesystem
php bin/console zyos:filesystem <environment>
php bin/console zyos:filesystem dev # create directory, symlink and mirror
php bin/console zyos:filesystem --show-output prod
php bin/console zyos:filesystem --mirror prod # only mirror creation
php bin/console zyos:filesystem --symlink prod # only symlink creation
php bin/console zyos:filesystem --directory prod # only directory creation
php bin/console zyos:filesystem --mirror --symlink prod # only mirror and symlink creation
Usage:
zyos:filesystem [options] [--] [<environment>]
Arguments:
environment Runtime environment [default: "dev"]
Options:
--mirror Run only directory mirroring
--symlink Run only create symlink
--directory Run directory creation only
--show-output Show command output
This command uses the Symfony component "Process" which executes commands directly on the operating system where the application is located.
zyos_install:
cli:
- command: ['mkdir', '-p', '/app/public/test3']
environments: ['prod', 'dev']
enable: true
if_error: 'stop'
- command: (array) command to execute. This command follows the rules of the Process component.
- environments: (array) environments in which the command will be executed.
- priority: (integer): It is the priority at which the command will be executed, (in positive values) the higher the number, less priority it has, (in negative numbers) the higher the number, more priority it has.
- if_error: (enum:[none, stop]) This field limits the action of the command in case of an error, the commands (CLI) return 3 exit codes: success: 0, Failure: 1, Invalid: 2. In this case there are two values in case of error: 1 and 2 which the command can be stopped and the following configured commands are not executed, in this case the value is used: "stop", in case an error occurs but the execution process of the following commands is not stopped, it is used the value: "none".
php bin/console zyos:cli
php bin/console zyos:cli <environment>
php bin/console zyos:cli dev
php bin/console zyos:cli --show-output prod
Usage:
zyos:cli [options] [--] [<environment>]
Arguments:
environment: Runtime environment [default: "dev"]
Options:
--show-output Show command output
This command generates the basic validation of directories, files that are configured for each of the environments, these validations will be shown as Success or Failed, in this case at the command level (CLI) the exit code is Success: 0, Failed : 1.
In this process there are no execution limits, the block that the other commands may have is not generated, but the configurations in which each validation fails can also be observed.
zyos_install:
validate:
- filepath: '%kernel.project_dir%/public/img'
type: directory
environments: ['prod', 'dev', 'test']
enable: true
validations:
- exists
- is_dir
- filepath: (string) directory and/or file source path.
- type: (enum:[directory, file]) type of filepath.
- environments: (array) environments in which the command will be executed.
- enable: (boolean) enable or disable the command.
- validations: (array) validations to be executed.
- exists: If the file or directory exists.
- is_dir: If the file or directory is a directory.
- is_file: If the file or directory is a file.
- is_executable: If the file or directory is a executable.
- is_symlink: If the file or directory is a symlink.
- is_writable: If the file or directory is writable.
- is_readable: If the file or directory is readable.
php bin/console zyos:validate
php bin/console zyos:validate <environment>
php bin/console zyos:validate dev
php bin/console zyos:cli --only-errors prod
Usage:
zyos:validate [options] [--] [<environment>]
Arguments:
environment: Runtime environment [default: "dev"]
Options:
--only-errors only show errors