pragmarx/deeployer

Laravel 4.1+ 通过 git webhooks 自动应用部署包

v0.8.4 2015-02-18 16:26 UTC

This package is auto-updated.

Last update: 2024-09-21 19:45:21 UTC


README

Latest Stable Version

每次将代码推送到远程仓库时,自动部署 Laravel 应用程序

通过 git webhooks 部署是当今大多数 PaaS 的常见功能。本包旨在供那些托管网站在 VPS、专用服务器或任何不支持 webhooks 的其他主机提供商的用户使用。

由于此包使用 Laravel 远程 (SSH-2) 功能远程或本地部署应用程序,因此您的部署应用程序可以位于一个服务器上,并部署到其他服务器,数量根据需要而定。

兼容性

此包目前与以下兼容

  • Github
  • Bitbucket

与 Laravel Envoy 一起使用

为您的部署器定义一个 URL,在 Github 中,您可以在“设置”>“服务钩子”>“WebHook URL”>“URL”中找到它,例如

http://deployer.yoursite.io/deploy

在您的应用程序中为部署器 URL 创建一个路由

Route::post('deploy', function() 
{
    return Deeployer::run();
});

如果您正在使用 Laravel Envoy,请安装它并创建使用您的项目 URL 和分支名称作为任务名称的任务

@task('https://github.com/you/repo-name:master', ['on' => ['localhost']])
    touch /tmp/envoy-passthrough.txt
@endtask

这样就可以了!配置您的 webhook,推送一些内容并等待。

常规用法

如果您希望使用 Deeployer 自身的部署系统,请编辑文件 app/config/packages/pragmarx/deeployer/config.php 并创建您的项目。在我看来,在自动部署应用程序时最好不要使用 master 分支。

'projects' => array(
                        array(
                                'ssh_connection' => 'yoursite-staging',

                                'git_repository' => 'https://github.com/yourname/yoursite.io',

                                'git_remote' => 'origin',

                                'git_branch' => 'staging',

                                'remote_directory' => '/var/www/vhosts/yoursite.io/staging/',

                                'composer_update' => true,

                                'composer_optimize_autoload' => true,

                                'composer_extra_options' => '',

                                'composer_timeout' => 60 * 5, // 5 minutes

                                'artisan_migrate' => false,

                                'post_deploy_commands' => array(
                                                                    'zsh send-deployment-emails.sh',
                                                                ),
                            ),
                    ),

通过编辑 app/config/remote.php 创建远程连接

	'connections' => array(

		'yoursite-staging' => array(
			'host'     => 'yoursite.com:22', <-- you can set a different SSH port if you need 
			'username' => 'root',            <-- the user you use to deploy applications on your server
			'password' => 'Bassw0rt',
			'key'      => '',                <-- key files are safer than passwords
			'root'     => '/var/www',        <-- you can ignore this, deployment path will be changed by Deeployer
		),

	),

转到您的服务器并 tail 日志文件

php artisan tail

将此 URL 添加到 Github 或 Bitbucket。

将分支上的内容推送到您的应用程序以自动部署

git pull origin master:testing
git pull origin master:staging
git pull origin master:production

如果您只是测试,在 Github 中,您可以在保存您的 URL 后点击“测试钩子”按钮。

安装

要求

  • Laravel 4.1+
  • Composer >= 2014-01-07 - 这是一个 PSR-4 包
  • SSH-2 服务器

安装

首先,您需要确保您有一个支持 PSR-4 的 Composer,因此执行

composer self-update

sudo composer self-update

要求 Deeployer 包

composer require pragmarx/deeployer dev-master

此操作完成后,将服务提供者添加到您的 app/config/app.php

'PragmaRX\Deeployer\Vendor\Laravel\ServiceProvider',

发布并编辑配置文件

artisan config:publish pragmarx/deeployer

待办事项

  • 创建一个部署 artisan 命令,以手动部署有问题的内容。

  • 测试,测试,测试。

  • Bitbucket 尚未完成。(已完成!)

作者

Antonio Carlos Ribeiro - acr@antoniocarlosribeiro.com - http://twitter.com/iantonioribeiro

许可

Deeployer 在 MIT 许可证下授权 - 有关详细信息,请参阅 LICENSE 文件

贡献

欢迎 pull requests 和 issues。