安装(https://deployer.org/docs/installation)了 Deployer 后,我们可以在终端运行 dep 命令。
为了获取所有可用的任务列表,可以运行 dep 命令。我们可以在项目的任意子目录来运行它;Deployer 将会自动查找项目根目录。
/*
Deployer
Usage:
command [options] [arguments]
Options:
-h, --help Display this help message
-q, --quiet Do not output any message
-V, --version Display this application version
--ansi Force ANSI output
--no-ansi Disable ANSI output
-n, --no-interaction Do not ask any interactive question
-f, --file[=FILE] Specify Deployer file
-v|vv|vvv, --verbose Increase the verbosity of messages: 1 for normal output, 2 for more verbose output and 3 for debug
Available commands:
help Displays help for a command
init Initialize deployer system in your project
list Lists commands
run Run any arbitrary command on hosts
self-update Updates deployer.phar to the latest version
ssh Connect to host through ssh
*/
配置 deploy.php 的最佳方法是,通过如下命令,自动部署到预演环境:
dep deploy
这样,有些人就不会意外部署到生产环境中(对于生产环境部署,dep deploy production 命令需要显式列出所需的 production 应用环境)
需要有关可用选项和用法的相关信息,可以使用 help 命令:
dep help deploy
/*
$ dep help deploy
Usage:
deploy [options] [--] [<stage>]
Arguments:
stage Stage or hostname
Options:
-p, --parallel Run tasks in parallel
-l, --limit=LIMIT How many host to run in parallel?
--no-hooks Run task without after/before hooks
--log=LOG Log to file
--roles=ROLES Roles to deploy
--hosts=HOSTS Host to deploy, comma separated, supports ranges [:]
-o, --option=OPTION Sets configuration option (multiple values allowed)
-h, --help Display this help message
-q, --quiet Do not output any message
-V, --version Display this application version
--ansi Force ANSI output
--no-ansi Disable ANSI output
-n, --no-interaction Do not ask any interactive question
-f, --file[=FILE] Specify Deployer file
--tag[=TAG] Tag to deploy
--revision[=REVISION] Revision to deploy
--branch[=BRANCH] Branch to deploy
-v|vv|vvv, --verbose Increase the verbosity of messages: 1 for normal output, 2 for more verbose output and 3 for debug
Help:
Deploy your project
*/
覆盖配置选项
例如,如果我们的 deploy.php 文件包含如下配置:
set('ssh_multiplexing', false);
并且,我们想要在不修改该文件的情况下,开启 ssh multiplexing(https://en.wikibooks.org/wiki/OpenSSH/Cookbook/Multiplexing),我们可以给 dep 命令,传递 -o 选项:
dep deploy -o ssh_multiplexing=true
要覆盖多个配置选项,我们可以传递多个 -o 参数:
dep deploy -o ssh_multiplexing=true -o branch=master
运行任意命令
Deployer 附带了一个命令,来运行我们服务器上的任意命令,而不修改 deploy.php 文件。
dep run 'ls -la'
要指定主机,该命令具有相应的选项:
--stage=STAGE Stage to deploy
--roles=ROLES Roles to deploy
--hosts=HOSTS Host to deploy, comma separated, supports ranges [:]
获取帮助
通过使用 help 命令,我们来获取任意命令的更多信息:
dep help [command]
自动完成
Deployer 附带了一个 bash/zsh/fish shell 支持的 autocomplete 脚本,因此我们不需要记住所有的任务和选项。运行以下命令来安装:
dep autocomplete
并按照说明操作