host - 主机
host(string ...$hostname): Host
定义一个主机或一组主机。查看关于主机的更多信息(https://deployer.org/docs/hosts)
localhost - 本地主机
localhost(string ...$alias = 'localhost'): Host
定义一个本地主机
inventory - 主机清单
inventory(string $file): Host[]
从一个文件中加载一个主机列表
desc - 描述
desc(string $description)
设置任务描述
task - 任务
task(string $name, string $script)
task(string $name, callable $callable)
task(string $name): Task
定义一个任务或获取一个任务。查看关于任务的更多信息(https://deployer.org/docs/tasks)
before - 前置
before(string $when, string $that)
在 $when 任务之前调用 $that 任务
after - 后置
after(string $when, string $that)
在 $when 任务之后调用 $that 任务
fail - 失败
fail(string $what, string $that)
如果任务 $what 失败,运行 $that 任务
argument - 参数
argument($name, $mode = null, $description = '', $default = null)
添加用户的命令行参数
option - 选项
option($name, $shortcut = null, $mode = null, $description = '', $default = null)
添加用户的命令行选项
cd - 切换目录
cd(string $path)
为下面的 run 函数设置工作路径。每个任务在任务开始时,恢复工作路径到基本工作路径。
cd('{{release_path}}');
run('npm run build');
within - 在内部
within(string $path, callable $callback)
在 $path 内部调用 $callback
within('{{release_path}}', function(){
run('npm run build');
});
workingPath - 工作路径
workingPath(): string
返回当前工作路径
cd('{{release_path}}');
workingPath() == '/var/www/app/releases/1';
run - 运行
run(string $command, $options = []): string
在远程主机上运行一个命令。可用的选项有:
timeout - 设置进程超时时间(最大运行时间)
禁用超时时间,设置值为 null.
超时时间以秒为单位(默认: 300 秒).
tty - 启用或禁用 TTY 模式(默认:false).
例如,如果我们的私钥包含一个密码,启用 tty,我们将看到 git 提示要求输入密码。
run('git clone ...', ['timeout' => null, 'tty' => true]);
run 函数返回字符串格式的命令输出:
$path = run('readlink {{deploy_path}}/current');
run("echo $path");
runLocally - 本地运行
runLocally($command, $options = []): string
在本地主机运行一个命令。可用的选项有:
timeout - 超时时间以秒为单位(默认: 300 秒).
tty - TTY 模式(默认: false)
test - 测试
test(string $command): bool
运行一个测试命令
if(test('[ -d {{release_path}} ]')){
...
}
testLocally - 本地测试
testLocally(string $command): bool
本地运行一个测试命令
on - 在主机上
on(Host $host, callable $callback)
on(Host[] $host, callable $callback)
在指定的主机上执行一个 $callback 回调
on(host('domain.com'), function($host){
...
});
on(roles('app'), function($host){
...
});
on(Deployer::get()->hosts, function($host){
...
});
roles - 角色
roles(string ...$role): Host[]
按角色返回一个主机列表
invoke - 调用
invoke(string $task)
在当前主机上运行一个任务。
task('deployl', function(){
invoke('deploy:prepare');
invoke('deploy:release');
...
});
注意:这是实验功能
upload - 上传
upload(string $source, string $destination, $config = [])
将文件从 $source 上传到远程主机上的 $destination。
upload('build/', '{{release_path}}/public');
我们可能已经注意到,在上面命令的第一个参数的末尾,有一个尾部斜杠(/),这是必须的,表示 "build 的内容"。
没有尾部斜杠的替代方案是,将 build(包含该目录) 放置在 public 下。这将创建一个类似于 {{release_path}}/public/build 的层次结构。
可选的选项有:
timeout - 超时时间以秒为单位(默认: null).
options - rsync 选项
download - 下载
download(string $source, string $destination, $config = [])
将文件从远程主机上的 $source 下载到本地机器上的 $destination。
可用的选项有:
timeout - 超时时间以秒为单位(默认: null).
options - rsync 选项
write - 写入
在输出中写入消息。我们可以使用标签来格式化消息:
<info>...</info>
<comment>...</comment>
<error>...</error>
查看 Symfony Console(http://symfony.com/doc/current/console/coloring.html)
writeIn - 写入
同 write 函数一样,但也会写入一个新行(从另一个行写入)。
set - 设置
set(string $name, string|int|bool|array $value)
set(string $name, callable $value)
设置一个全局配置参数。如果给 $value 传递一个 callable,它将在首次获取该配置时触发。
查看关于配置的更多信息(https://deployer.org/docs/configuration)
add - 添加
add(string $name, array $values)
给已存在的配置添加值。
查看关于配置的更多信息(https://deployer.org/docs/configuration)
get - 获取
get(string $name, $default = null): string|int|bool|array
获取配置值
查看关于配置的更多信息(https://deployer.org/docs/configuration)
has - 是否存在
has(string $name): bool
检查配置选项是否存在
查看关于配置的更多信息(https://deployer.org/docs/configuration)
ask - 询问
ask(string $message, $default = null, $suggestedChoices = null)
询问用户输入
askChoice - 询问选择
askChoice(string $message, array $availableChoices, $default = null, $multiselect = false)
要求用户从多个 键/值 选项中进行选择,并返回一个数组。Multiselect 可以选择多个以逗号分隔的选项。默认值用于静默模式(quiet mode),否则将会接受第一个可用选项。
askConfirmation - 询问确认
askConfirmation(string $message, bool $default = false)
询问用户一个 yes|no 问题。
askHiddenResponse - 询问隐藏响应,一般是用于密码输入
askHiddenResponse(string $message)
询问用户密码
input - 输入
input(): Input
获取当前控制台输入
output - 输出
output(): Output
获取当前控制台输出
isQuiet - 是否静默模式
isQuiet(): bool
检查是否以 -q 选项运行了 dep 命令
isVerbose - 是否显示详细信息
isVerbose(): bool
检查是否以 -v 选项运行了 dep 命令
isVeryVerbose - 是否显示非常详细的信息
isVerbose(): bool
检查是否以 -vv 选项运行了 dep 命令
isDebug - 是否调试模式
isDebug(): bool
检查是否以 -vvv 选项运行了 dep 命令
commandExist - 命令是否存在
commandExist(string $command): bool
检查命令是否存在
if(commandExist('composer')){
...
}
parse - 语法
parse(string $line): string
解析出现在 $line 内的 {{ }} 配置
Deployer-8-API参考-API Reference
猜你喜欢
转载自blog.csdn.net/beyond__devil/article/details/86496736
今日推荐
周排行