deployer 服务器代码部署
2018-09-06 本文已影响115人
fingerQin
工具安装
deployer 工具支持 PHP5.x 和 PHP 7.x 版本。deployer 4.x 版本支持 PHP 5.6 版本,5.x 版本支持 PHP 7.x 版本。
一、安装 deployer
$ curl -LO https://deployer.org/releases/v4.3.0/deployer.phar
$ mv deployer.phar /usr/local/bin/dep
$ chmod +x /usr/local/bin/dep
执行完上述步骤之后,我们就已经安装好了 deployer 工具。此时,我们可以在任意目录执行如下命令验证是否安装成功:
$ dep
如果此时能输入如下内容,说明已经安装成功:
Deployer 4.3.0
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
self-update Updates deployer.phar to the latest version
二、升级 deployer
升级 deployer 很简单:
$ dep self-update
三、使用 deployer
这里我需要对 deployer 的机制大概说明一下。 deployer 工具的模式是通过跳板机(deployer所在服务器)对一台或多台 WEB 服务器进行的代码部署工作。
所以,我们此时需要在跳板机上使用 deployer 工具创建一个部署目录。以此来定义我们要部署的工作内容。
1) 初始化
在跳板机任意目录执行如下命令:
dep init
在目录下面会生成一个 deploy.php 脚本。
我们接下来的工作就是对 deploy.php 脚本进行编辑。
2) 设定要部署的 WEB 服务器
我们在 deploy.php 脚本中找到类似代码:
server('production', 'domain.com')
->user('root')
->identityFile()
->set('deploy_path', 'xxxx');
server 方法的第一个参数是为我们的 WEB 服务器指定一个名字,第二个参数是 WEB 服务器的 IP 地址。
提供两种方式连接到 WEB 服务器。一是账号密码方式、一种是 ssh key 方式。
3) 账号密码方式
PHP 代码如下:
server('prod_1', 'xxx.xxx.xxx.xxx')
->user('root')
->password('123456')
->set('deploy_path', '/data/web/www.xxx.com')
->stage('production');
4) SSH KEY 方式
PHP 代码如下:
server('prod_1', 'xxx.xxx.xxx.xxx')
->user('root')
->identityFile()
->set('deploy_path', '/data/web/www.xxx.com')
->stage('production');
关于 server 方法更多文档:https://github.com/deployphp/docs/blob/4.x/servers.md
三、执行部署
dep deploy