使用 Deployer 部署代码

发布于 2023-07-18 12:52:22 字数 4208 浏览 43 评论 0

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据

关于作者

压抑⊿情绪

暂无简介

文章
评论
29 人气
更多

推荐作者

櫻之舞

文章 0 评论 0

弥枳

文章 0 评论 0

m2429

文章 0 评论 0

野却迷人

文章 0 评论 0

我怀念的。

文章 0 评论 0

    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文