thejawker/laravel-deployer

让部署 Laravel 应用变得轻而易举。

0.1.10 2019-04-18 07:56 UTC

This package is auto-updated.

Last update: 2024-09-18 20:42:19 UTC


README

让部署 Laravel 应用变得轻而易举!💨💨💨💨 此包将生成你的部署 bash 脚本,并在出错或正确时提供一些友好的通知。

🚨 进行中

功能齐全,但完全完成前可能需要一些时间。

安装

你可以通过运行以下 composer 命令来安装此包

$ composer require thejawker/laravel-deployer

如果你正在运行 Laravel 5.4 或更低的版本,你必须手动添加 ServiceProvider。

接下来发布 vendor

$ php artisan vendor:publish --tag=deployer-config

然后将你的 Slack 频道详情和其他部署配置添加到 config/deployer.php 文件中。

配置

配置相当复杂,注释详尽,因此更容易理解。

# config/deployer.php

<?php

return [

    /*
    |--------------------------------------------------------------------------
    | The Name of the Deployment Script
    |--------------------------------------------------------------------------
    |
    */

    'script-name' => 'deployer.sh',

    /*
    |--------------------------------------------------------------------------
    | Notifications Settings
    |--------------------------------------------------------------------------
    |
    | These are your notification settings. For now we only support the
    | Slack platform to send Notifications.
    |
    */

    'slack-channel' => 'some-channel',
    'slack-url' => 'http://some-domain.xx',

    /*
    |--------------------------------------------------------------------------
    | Environment Notification Level
    |--------------------------------------------------------------------------
    |
    | You can add an array with the various levels where you like to
    | receive notifications. Adding just ['production'] will only
    | send notifications when deploying on the production env.
    |
    */

    'env-level' => ['*'],

    /*
    |--------------------------------------------------------------------------
    | Duration Warning Time Threshold
    |--------------------------------------------------------------------------
    |
    | If the deployment takes longer than this amount of time, the
    | message will be sent with a warning to the Slack Channel.
    |
    | Value is in seconds.
    |
    */

    'warn-after' => 20,

    /*
    |--------------------------------------------------------------------------
    | Commands
    |--------------------------------------------------------------------------
    |
    | Here you can define the commands you want to run. They run in
    | order of addition. They will be wrapped
    |
    */

    'commands' => [
        'initialize' => [

        ],

        'set-up' => [
            'php artisan down'
        ],


        'deploy' => [
            'git pull'
        ],

        'post-deploy' => [
            'php artisan up',
            'php artisan config:cache',
            'php artisan route:cache',
            'php artisan view:clear',
            'php artisan horizon:terminate'
        ]

        //...
    ]
];

发布脚本

如果你对你的配置满意,你可以通过运行以下命令发布 bash 脚本

$ php artisan deployer

这将在应用根目录下创建一个 deployer.sh bash 文件。运行此文件将部署并通知你部署的状态。

bash ./deployer.sh # (or make it executable and just run it)

注意:你必须运行它才能更新脚本。另外,当你在 php artisan config:cache 时要小心,因为这将会锁定配置而不会更新脚本。

推送以部署?

当然可能,阅读你 git 提供商的文档(例如 Bitbucket、GitHub)。你只需要确保在部署(或其他操作)时 bash 脚本能够运行。

再次强调,这还在进行中,所以可能随时会出错。