bitcodesa/deployment-script

该软件包添加了 artisan 命令,允许用户一次性收集 artisan 或终端命令。

0.0.2 2023-11-21 09:24 UTC

README

Latest Version on Packagist GitHub Tests Action Status Total Downloads

软件包描述

该软件包提供了一种方便的方式,通过预定义的配置文件运行 artisan 命令组。这对于自动化部署、数据库维护和测试等任务非常有用。

功能

  • 使用单个命令运行 artisan 命令组
  • 在配置文件中覆盖命令选项
  • 向 artisan 命令传递值,如 --force
  • 运行类似 git pull 的命令。

示例

例如,要运行以下命令

php artisan migrate:fresh
php artisan cache:clear
php artisan route:cache
return [
    'commands' => [
        [
            "type" => "artisan",
            "command" => "migrate:fresh"
        ],
        [
            "type" => "artisan",
            "command" => "cache:clear"
        ],
        [
            "type" => "artisan",
            "command" => "route:cache"
        ],
    ],
];

然后,您将运行以下命令

php artisan deploy

该软件包是任何需要定期自动化任务或运行 artisan 命令组的 Laravel 开发者的宝贵工具。

安装

您可以通过 composer 安装该软件包

composer require bitcodesa/deployment-script

您可以使用以下命令发布配置文件

php artisan vendor:publish --tag="deployment-script-config"

这是发布配置文件的内容

return [
     "commands" => [
        [
            "type" => "console",
            "command" => "git pull"
        ],
        [
            "type" => "console",
            "command" => "composer install --optimize-autoloader",
        ],
        [
            "type" => "artisan",
            "command" => "migrate",
            "values" => [
                "--force" => true
            ]
        ],
        [
            "type" => "artisan",
            "command" => "cache:clear",
        ],
    ]
];

允许在生产环境中使用

要允许在生产环境 production env 中使用部署脚本,您应该在配置 config/deployment-script.php 中允许它

[
// config/deployment-script.php
"allow_in_production" => true;
]

注意: 默认情况下,脚本不允许在生产环境中使用。

生产命令

您可以指定仅在 production env 中运行的命令:将数组放在配置文件 config/deployment-script.php 中,然后指定该数组的键名到变量 production 中,例如

[
// config/deployment-script.php
"production_commands" => [
    [
            "type" => "artisan",
            "command" => "migrate",
            "values" => [
                "--force" => true
            ]
        ],
        [
            "type" => "artisan",
            "command" => "cache:clear",
        ],
    ]
"production" => "production_commands";
];

注意: 如果未指定,将使用默认的命令数组。

使用方法

php artisan deploy

测试

composer test

变更日志

请参阅 CHANGELOG 了解最近更改的详细信息。

贡献

请参阅 CONTRIBUTING 了解详细信息。

鸣谢

许可

MIT 许可证 (MIT)。有关更多信息,请参阅 许可文件