m-adamski / symfony-deployer-bundle
用于简化Deployer配置的SymfonyBundle
2.0.0
2020-02-07 09:16 UTC
Requires
- php: ^7.2
- symfony/console: ^4.1|^5.0
- symfony/framework-bundle: ^4.1|^5.0
- symfony/process: ^4.1|^5.0
Requires (Dev)
- kint-php/kint: ^3.0
README
用于简化Deployer配置的SymfonyBundle。
此bundle与Symfony 4.1和Symfony 5.0兼容。已放弃与Symfony 3.4的兼容性。
安装
此bundle可以通过Composer安装。
$ composer require m-adamski/symfony-deployer-bundle $ composer require deployer/deployer --dev
Deployer配置
除了安装此包之外,您还必须创建它将使用的配置文件。您可以使用准备好的脚本或手动创建配置文件。
自动
在项目根目录下运行命令
$ vendor/bin/create-config
手动
在项目根目录下创建.deployer
目录。然后在新建的目录中创建四个文件:
- config.php
- deployer.php
- hosts.php
- tasks.php
使用默认值填写这些文件,然后根据需求进行修改。
config.php
<?php namespace Deployer; /** * Global Configuration */ set("application", "example-application"); set("repository", "git@github.com:m-adamski/example-application.git"); set("ssh_multiplexing", false); set("git_tty", false); set("shared_dirs", ["var/log"]); set("shared_files", [".env.local"]); set("writable_dirs", ["var"]); set("sudo_password", function () { return askHiddenResponse("[sudo] password: "); }); set("allow_anonymous_stats", false);
deployer.php
<?php namespace Deployer; require_once "recipe/symfony4.php"; require_once __DIR__ . "/config.php"; require_once __DIR__ . "/hosts.php"; require_once __DIR__ . "/tasks.php"; /** * Additional workflow events */ before("deploy:writable", "deploy:writable:prepare"); after("deploy:cache:warmup", "deploy:restart:php"); after("deploy:failed", "deploy:unlock");
hosts.php
<?php namespace Deployer; /** * Hosts */ host("example.com") ->stage("production") ->user("deployer") ->identityFile(__DIR__ . "/.ssh/production/deployer_rsa") ->addSshOption("UserKnownHostsFile", "/dev/null") ->addSshOption("StrictHostKeyChecking", "no") ->set("php_version", "php7.2-fpm") ->set("deploy_path", "/var/www/vhosts/example.com") ->set("branch", "master");
tasks.php
<?php namespace Deployer; task("deploy:restart:php", function () { run("echo '{{ sudo_password }}' | sudo -S service {{ php_version }} restart"); })->desc("Restart PHP"); task("deploy:writable:prepare", function () { $dirs = join(" ", get("writable_dirs")); cd("{{ release_path }}"); run("echo '{{ sudo_password }}' | sudo -S setfacl -RL -m mask:rwX $dirs"); })->desc("Prepare writable");
最后一步是根据自己的需求修改配置文件。
许可证
MIT