配置
若要設(shè)置配置參數(shù), 使用 set 函數(shù);若要在任務(wù)中獲取配置參數(shù), 使用 get 函數(shù).
set('param', 'value');
task('deploy', function () {
$param = get('param');
});
各個(gè)主機(jī)可以分別覆蓋這些參數(shù):
host(...)
->set('param', 'new value');
配置參數(shù)也可以指定為回調(diào)函數(shù), 該函數(shù)將在第一次 get 調(diào)用時(shí)在遠(yuǎn)程主機(jī)上執(zhí)行:
set('current_path', function () {
return run('pwd');
});
可以在調(diào)用 run 函數(shù)中使用帶有 {{ }} 的參數(shù)值, 就像下面這樣:
run('cd {{release_path}} && command');
替代下面這種寫法:
run('cd ' . get('release_path') . ' && command');
common recipe附帶了一些預(yù)定義的配置參數(shù), 如下所示.
獲取可用參數(shù)的列表, 請(qǐng)運(yùn)行:
dep config:dump
顯示當(dāng)前部署的版本:
dep config:current
Show inventory:
dep config:hosts
常見變量列表.
deploy_path
在遠(yuǎn)程主機(jī)上部署應(yīng)用程序的位置. 應(yīng)該為所有主機(jī)定義此變量. 例如, 要將應(yīng)用程序部署到主目錄下:
host(...)
->set('deploy_path', '~/project');
hostname
當(dāng)前主機(jī)名. 由 host 函數(shù)自動(dòng)設(shè)置.
user
當(dāng)前用戶名. 默認(rèn)為當(dāng)前git用戶名:
set('user', function () {
return runLocally('git config --get user.name');
});
你可以在 deploy.php 中覆蓋它, 如, 使用環(huán)境變量中的值:
set('user', function () {
return getenv('DEP_USER');
});
user 參數(shù)可用于配置通知系統(tǒng):
set('slack_text', '{{user}} 正在部署分支 {{branch}} 到 {{hostname}}主機(jī)上');
release_path
當(dāng)前版本目錄的完整路徑。非部署上下文中的當(dāng)前目錄路徑。 將其用作構(gòu)建的工作路徑:
task('build', function () {
cd('{{release_path}}');
// ...
});
默認(rèn)情況下, 簡單任務(wù)的工作路徑是
release_path:php task('build', 'webpack -p');
previous_release
前一個(gè)版本的完整路徑. (如果第一次發(fā)布, 變量不存在)
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 多路復(fù)用 提速原生客戶端.
set('ssh_multiplexing', true);
default_stage
默認(rèn)場(chǎng)景設(shè)置. 如果主機(jī)有場(chǎng)景的聲明,則使用dep deploy命令部署時(shí), 自動(dòng)選擇有默認(rèn)場(chǎng)景聲明的主機(jī)進(jìn)行部署。
set('default_stage', 'prod');
host(...)
->stage('prod');
如果需要復(fù)雜的方式來聲明場(chǎng)景, 你還可以將可調(diào)用的程序(callable)做為參數(shù).
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()中使用可調(diào)用程序時(shí),允許在聲明值時(shí)不設(shè)置該值, 而是在稍后使用該值時(shí)設(shè)置該值。這種情況與指定一個(gè)簡單的字符串沒有區(qū)別。
但當(dāng)我們給一個(gè)函數(shù)賦值時(shí),如果這個(gè)函數(shù)不能作為可調(diào)用函數(shù)使用,那么它必須立即被調(diào)用。
通過callable,可以在使用時(shí)調(diào)用它,因此聲明變量的函數(shù)可以被用戶用自己的函數(shù)覆蓋。這是在set()中使用callable而不是在函數(shù)調(diào)用中使用direct的強(qiáng)大功能。
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
保留的發(fā)布版本數(shù)量. -1 為無限制. 默認(rèn)值 5.
repository
Git 倉庫.
要使用私有庫,需要在主機(jī)上生成SSH密鑰(SSH-key)并將其添加到存儲(chǔ)庫中作為部署密鑰(又稱訪問密鑰)。這個(gè)密鑰允許你的主機(jī)取出代碼。或者使用代理轉(zhuǎn)發(fā)。
請(qǐng)注意,當(dāng)主機(jī)第一次連接時(shí),它要求在 known_hosts 文件中添加主機(jī)。
最簡單的方法是在主機(jī)上運(yùn)行 git clone <repo> 并在提示時(shí)說 yes 。
git_tty
為 git clone 命令分配TTY。默認(rèn)情況下為false 。這允許您輸入密鑰的密碼短語或?qū)⒅鳈C(jī)添加到known_hosts。
set('git_tty', true);
git_recursive
為git clone設(shè)置 --recursive 標(biāo)志。默認(rèn)情況下為 true 。將此設(shè)置為 false 將阻止子模塊被克隆。
set('git_recursive', false);
branch
要部署的分支.
如果要部署特定的標(biāo)記或修訂,可以在運(yùn)行 dep deploy時(shí)使用 --tag 和 --revision 選項(xiàng)。例如:
dep deploy --tag="v0.1"
dep deploy --revision="5daefb59edbaa75"
請(qǐng)注意 tag 的優(yōu)先級(jí)高于 branch ,而低于 revision。
shared_dirs
共享目錄列表.
set('shared_dirs', [
'logs',
'var',
...
]);
shared_files
共享文件列表.
copy_dirs
要在版本之間復(fù)制的文件列表.
writable_dirs
web服務(wù)器中必須可寫的目錄列表.
writable_mode
可寫模式
acl(默認(rèn)) 使用setfacl用于更改目錄的ACL.chmod使用 unixchmod命令,chown使用 unixchown命令,chgrp使用 unixchgrp命令,
writable_use_sudo
是否將 sudo 與可寫命令一起使用。默認(rèn)為 false。
writable_chmod_mode
用于在writable_mode的模式時(shí),chmod設(shè)置的權(quán)限 。默認(rèn)值:0755。
writable_chmod_recursive
是否對(duì)chmod 操作的目錄進(jìn)行遞歸設(shè)置 。默認(rèn)值:true。
http_user
運(yùn)行web服務(wù)器的用戶。如果未配置此參數(shù),deployer將嘗試從進(jìn)程列表中檢測(cè)它。
clear_paths
更新代碼后需要在發(fā)布版本中刪除的路徑列表。
clear_use_sudo
是否使用 sudo 在clear_paths中一起使用。默認(rèn)為 false。
cleanup_use_sudo
是否將 sudo 與 cleanup 任務(wù)一起使用。默認(rèn)為false。
use_relative_symlink
是否使用軟連接。默認(rèn)情況下,deployer將檢測(cè)系統(tǒng)是否支持軟連接并使用它們。
如果系統(tǒng)支持,則默認(rèn)使用軟連接.
use_atomic_symlink
是否使用原子符號(hào)鏈接。默認(rèn)情況下,部署程序?qū)z測(cè)系統(tǒng)是否支持原子符號(hào)鏈接并使用它們。
如果系統(tǒng)支持,則默認(rèn)情況下使用原子符號(hào)鏈接.
composer_action
Composer 動(dòng)作. 默認(rèn)為 install.
composer_options
Composer 選項(xiàng).
env
環(huán)境變量數(shù)組.
set('env', [
'VARIABLE' => 'value',
]);
了解更多請(qǐng)關(guān)注 任務(wù).