配置
若要設置配置參數, 使用 set 函數;若要在任務中獲取配置參數, 使用 get 函數.
set('param', 'value');
task('deploy', function () {
$param = get('param');
});
各個主機可以分別覆蓋這些參數:
host(...)
->set('param', 'new value');
配置參數也可以指定為回調函數, 該函數將在第一次 get 調用時在遠程主機上執行:
set('current_path', function () {
return run('pwd');
});
可以在調用 run 函數中使用帶有 {{ }} 的參數值, 就像下面這樣:
run('cd {{release_path}} && command');
替代下面這種寫法:
run('cd ' . get('release_path') . ' && command');
common recipe附帶了一些預定義的配置參數, 如下所示.
獲取可用參數的列表, 請運行:
dep config:dump
顯示當前部署的版本:
dep config:current
Show inventory:
dep config:hosts
常見變量列表.
deploy_path
在遠程主機上部署應用程序的位置. 應該為所有主機定義此變量. 例如, 要將應用程序部署到主目錄下:
host(...)
->set('deploy_path', '~/project');
hostname
當前主機名. 由 host 函數自動設置.
user
當前用戶名. 默認為當前git用戶名:
set('user', function () {
return runLocally('git config --get user.name');
});
你可以在 deploy.php 中覆蓋它, 如, 使用環境變量中的值:
set('user', function () {
return getenv('DEP_USER');
});
user 參數可用于配置通知系統:
set('slack_text', '{{user}} 正在部署分支 {{branch}} 到 {{hostname}}主機上');
release_path
當前版本目錄的完整路徑。非部署上下文中的當前目錄路徑。 將其用作構建的工作路徑:
task('build', function () {
cd('{{release_path}}');
// ...
});
默認情況下, 簡單任務的工作路徑是
release_path:php task('build', 'webpack -p');
previous_release
前一個版本的完整路徑. (如果第一次發布, 變量不存在)
task('npm', function () {
if (has('previous_release')) {
run('cp -R {{previous_release}}/node_modules {{release_path}}/node_modules');
}
run('cd {{release_path}} && npm install');
});
ssh_multiplexing
使用 OpenSSH 多路復用 提速原生客戶端.
set('ssh_multiplexing', true);
default_stage
默認場景設置. 如果主機有場景的聲明,則使用dep deploy命令部署時, 自動選擇有默認場景聲明的主機進行部署。
set('default_stage', 'prod');
host(...)
->stage('prod');
如果需要復雜的方式來聲明場景, 你還可以將可調用的程序(callable)做為參數.
Having callable in set() allows you to not set the value when declaring it, but later when it is used. There is no difference when we assign a simple string. But when we assign value of a function, then this function must be called at once, if not used as callable. With callable, it can be called when used, so a function which determines a variable can be overwritten by the user with its own function. This is the great power of having callable in set() instead of direct in function calls.
在set()中使用可調用程序時,允許在聲明值時不設置該值, 而是在稍后使用該值時設置該值。這種情況與指定一個簡單的字符串沒有區別。
但當我們給一個函數賦值時,如果這個函數不能作為可調用函數使用,那么它必須立即被調用。
通過callable,可以在使用時調用它,因此聲明變量的函數可以被用戶用自己的函數覆蓋。這是在set()中使用callable而不是在函數調用中使用direct的強大功能。
Example 1: Direct function assign in set()
Lets assume that we must include some third party recipe that is setting 'default_stage' like this:
set('default_stage', \ThirdPartyVendor\getDefaultStage());
And we want to overwrite this in our deploy.php with our own value:
set('default_stage', \MyVendor\getDefaultStage());
Third party recipe should avoid a direct function call, because it will be called always even if we overwrite it with our own set('default_stage', \MyVendor\getDefaultStage()). Look at the next example how the third party recipe should use callable in that case.
Example 2: Callable assign in set()
Lets assume that we must include some third party recipe that is setting 'default_stage' like this:
set('default_stage', function() {
return \ThirdPartyVendor\getDefaultStage();
});
And we want to overwrite this in our deploy.php:
set('default_stage', function() {
return \MyVendor\getDefaultStage();
});
The result is that only \MyVendor\getDefaultStage() is run.
keep_releases
保留的發布版本數量. -1 為無限制. 默認值 5.
repository
Git 倉庫.
要使用私有庫,需要在主機上生成SSH密鑰(SSH-key)并將其添加到存儲庫中作為部署密鑰(又稱訪問密鑰)。這個密鑰允許你的主機取出代碼。或者使用代理轉發。
請注意,當主機第一次連接時,它要求在 known_hosts 文件中添加主機。
最簡單的方法是在主機上運行 git clone <repo> 并在提示時說 yes 。
git_tty
為 git clone 命令分配TTY。默認情況下為false 。這允許您輸入密鑰的密碼短語或將主機添加到known_hosts。
set('git_tty', true);
git_recursive
為git clone設置 --recursive 標志。默認情況下為 true 。將此設置為 false 將阻止子模塊被克隆。
set('git_recursive', false);
branch
要部署的分支.
如果要部署特定的標記或修訂,可以在運行 dep deploy時使用 --tag 和 --revision 選項。例如:
dep deploy --tag="v0.1"
dep deploy --revision="5daefb59edbaa75"
請注意 tag 的優先級高于 branch ,而低于 revision。
shared_dirs
共享目錄列表.
set('shared_dirs', [
'logs',
'var',
...
]);
shared_files
共享文件列表.
copy_dirs
要在版本之間復制的文件列表.
writable_dirs
web服務器中必須可寫的目錄列表.
writable_mode
可寫模式
acl(默認) 使用setfacl用于更改目錄的ACL.chmod使用 unixchmod命令,chown使用 unixchown命令,chgrp使用 unixchgrp命令,
writable_use_sudo
是否將 sudo 與可寫命令一起使用。默認為 false。
writable_chmod_mode
用于在writable_mode的模式時,chmod設置的權限 。默認值:0755。
writable_chmod_recursive
是否對chmod 操作的目錄進行遞歸設置 。默認值:true。
http_user
運行web服務器的用戶。如果未配置此參數,deployer將嘗試從進程列表中檢測它。
clear_paths
更新代碼后需要在發布版本中刪除的路徑列表。
clear_use_sudo
是否使用 sudo 在clear_paths中一起使用。默認為 false。
cleanup_use_sudo
是否將 sudo 與 cleanup 任務一起使用。默認為false。
use_relative_symlink
是否使用軟連接。默認情況下,deployer將檢測系統是否支持軟連接并使用它們。
如果系統支持,則默認使用軟連接.
use_atomic_symlink
是否使用原子符號鏈接。默認情況下,部署程序將檢測系統是否支持原子符號鏈接并使用它們。
如果系統支持,則默認情況下使用原子符號鏈接.
composer_action
Composer 動作. 默認為 install.
composer_options
Composer 選項.
env
環境變量數組.
set('env', [
'VARIABLE' => 'value',
]);
了解更多請關注 任務.