使用 Deployer 部署代码
Deployer 主页: http://deployer.org/docs/getting-started
之前用 rocketeer
,但是好像不怎么更新了,ruby 的 cap
自定义任务比较蛋疼,不会 ruby
配置实例:
<?php /* * This file has been generated automatically. * Please change the configuration for correct use deploy. */ require 'recipe/common.php'; // Set configurations set('repository', 'https://github.com/twn39/SilexStack.git'); set('shared_files', []); set('shared_dirs', ['cache', 'logs']); set('writable_dirs', ['cache', 'logs']); set('keep_releases', 8); set('branch', 'master'); env('timezone', 'Asia/Shanghai'); // Configure servers server('production', '60.205.177.xx') ->user('root') ->password('password') ->env('deploy_path', '/var/www/html/silex'); /* server('beta', 'beta.domain.com') ->user('username') ->password() ->env('deploy_path', '/var/www/beta.domain.com'); */ /** * Restart php-fpm on success deploy. */ task('php-fpm:restart', function () { // Attention: The user must have rights for restart service // Attention: the command "sudo /bin/systemctl restart php-fpm.service" used only on CentOS system // /etc/sudoers: username ALL=NOPASSWD:/bin/systemctl restart php-fpm.service run('sudo service php5-fpm restart'); })->desc('Restart PHP-FPM service'); after('success', 'php-fpm:restart'); task('composer:install', function () { cd("{{ release_path }}"); run("composer install"); })->desc('Composer install'); task('check', function () { $output = run('git --version'); writeln('Git Version:'); writeln(" <info>$output</info>"); $output = run('php --version'); writeln('PHP Version:'); writeln(" <info>$output</info>"); $output = run('composer --version'); writeln('Composer Version:'); writeln(" <info>$output</info>"); })->desc('Server check'); /** * Main task */ task('deploy', [ 'deploy:prepare', 'deploy:release', 'deploy:update_code', 'deploy:shared', 'deploy:writable', 'composer:install', 'deploy:symlink', 'cleanup', ])->desc('Deploy your project'); after('deploy', 'success');
开启调试
vendor/bin/dep deploy production -vvv
Deployer 6.0 版 Windows 下测试可用
<?php namespace Deployer; require 'recipe/common.php'; // Configuration // set('ssh_type', 'native'); // set('ssh_multiplexing', true); set('repository', 'git@example.api.git'); set('shared_files', []); // set('git_tty', true); set('shared_dirs', [ 'logs', 'cache', 'public/images/captcha' ]); set('writable_dirs', [ 'logs', 'cache', 'public/images/captcha' ]); set('default_stage', 'development'); set('keep_releases', 20); // Servers host( 'production') ->hostname('127.0.0.1') ->stage('production') ->user('root') ->set('deploy_path', '/var/www/html/giliapi'); host( 'development') ->hostname('127.0.0.1') ->user('root') ->set('deploy_path', '/var/www/html/giliapidev') ->stage('development'); desc('Restart PHP-FPM service'); task('php-fpm:restart', function () { // The user must have rights for restart service // /etc/sudoers: username ALL=NOPASSWD:/bin/systemctl restart php-fpm.service run('sudo systemctl restart php-fpm.service'); }); task('autoload:optimize', function () { run('cd {{release_path}} && composer dump-autoload -o'); }); before('deploy:symlink', 'autoload:optimize'); after('deploy:symlink', 'php-fpm:restart'); desc('Deploy your project'); task('deploy', [ 'deploy:info', 'deploy:prepare', 'deploy:lock', 'deploy:release', 'deploy:update_code', 'deploy:shared', 'deploy:writable', 'deploy:vendors', 'deploy:clear_paths', 'deploy:symlink', 'deploy:unlock', 'cleanup', 'success' ]); // [Optional] if deploy fails automatically unlock. after('deploy:failed', 'deploy:unlock');
远程部署应用时,部署的客户机跟主机需要使用 rsa 文件认证,如果使用密码认证的话,他会一直弹 openssh 输入密码的输入框
注意:需要 ssh 客户端,可以使用 git bash
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

上一篇: R 链接 MySQL
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论