Laravel部署构想

问题描述

我正在为我的客户公司开发Laravel应用程序。那家公司有一个服务员。在开发过程的中间,我请他为该应用程序设置服务器。但是他建立了没有任何自动部署程序的服务器,而是给了我一个C-Pannel来手动部署更改。该应用程序变得如此复杂,现在手动部署变得非常繁琐。我正在手动构建js和CSS,并将它们上传到服务器。经过与他激烈的争论之后,我终于让他致力于自动化部署。他没有正确地部署,而是采用这种方式。

 
<?PHP
//app/Console/Commands/GitPull.PHP

namespace App\Console\Commands;

use Illuminate\Console\Command;

class GitPull extends Command
{
    /**
     * The name and signature of the console command.
     *
     * @var string
     */
    protected $signature = 'git:pull';

    /**
     * The console command description.
     *
     * @var string
     */
    protected $description = 'Get updates from git server';

    /**
     * Create a new command instance.
     *
     * @return void
     */
    public function __construct()
    {
        parent::__construct();
    }

    /**
     * Execute the console command.
     *
     * @return mixed
     */
    public function handle()
    {
        exec('git pull origin master');
    }
}

<?PHP
app/Console/Kernel.PHP

namespace App\Console;

use Illuminate\Console\Scheduling\Schedule;
use Illuminate\Foundation\Console\Kernel as ConsoleKernel;

class Kernel extends ConsoleKernel
{
    /**
     * The Artisan commands provided by your application.
     *
     * @var array
     */
    protected $commands = [
       Commands\GitPull::class,];

    /**
     * Define the application's command schedule.
     *
     * @param  \Illuminate\Console\Scheduling\Schedule  $schedule
     * @return void
     */
    protected function schedule(Schedule $schedule)
    {
        $schedule->command('git:pull')
                  ->everyMinute();
    }

    /**
     * Register the commands for the application.
     *
     * @return void
     */
    protected function commands()
    {
        $this->load(__DIR__.'/Commands');

        require base_path('routes/console.PHP');
    }
}

基本上,他已经安排了调度程序每分钟执行一次git pull。这是部署的正确方法吗?这种方式有什么弊端?部署必须依赖于应用程序吗?是否可以在没有laravel框架帮助的情况下添加自动化部署?我对dev-ops不太熟悉。

此外,我的源代码在bitbucket中。我准备回答有关此的任何问题。预先感谢。

解决方法

我当然不会使用Laravel命令来运行部署。自动化部署可以根据需要简单或复杂,但是我希望构建代理执行以下操作:

  • 收听更改以进行主生产部署
  • 运行测试(并在测试失败时发出警报并停止部署)
  • 建立我的静态资产(js / css / etc)
  • 将代码复制到服务器(执行此操作的几种方法)
  • 运行迁移
  • 重新启动队列,以便它们以最新代码运行

由于您使用的是位存储桶,因此可以查看用于执行ci / cd的管道。