Skip to content

An open-source, self-hostable PaaS alternative to Vercel, Heroku & Netlify that lets you easily deploy static sites, databases, full-stack applications and 360+ one-click services on your own servers.

1.8 KB
Raw Blame
<?php

namespace App\Console\Commands;

use App\Actions\Development\InstallDevelopmentGpuDriver;
use App\Actions\Development\SeedDevelopmentQemuServer;
use App\Actions\Development\StartDevelopmentInstanceDatabase;
use Illuminate\Console\Command;
use Throwable;

class SeedDevelopmentQemuServerCommand extends Command
{
    protected $signature = 'dev:qemu:seed {profile : Profile key from config/development-qemu.php} {--keep-others} {--as-localhost : Use the VM for the localhost server (id 0)} {--ip= : SSH host instead of the profile IP} {--port=22 : SSH port} {--gpu : Install the NVIDIA driver and container toolkit in the VM}';

    protected $description = 'Seed one development QEMU server in the Coolify database';

    public function handle(): int
    {
        if (! isDev()) {
            $this->error('This command may only run in development mode.');

            return self::FAILURE;
        }

        $server = SeedDevelopmentQemuServer::run($this->argument('profile'), ! $this->option('keep-others'), (bool) $this->option('as-localhost'), $this->option('ip') ?: null, (int) $this->option('port'));
        $this->info("Seeded {$server->name} at {$server->ip}.");

        if ($this->option('as-localhost')) {
            try {
                StartDevelopmentInstanceDatabase::run($server);
                $this->info('Started the coolify-db container for instance backups.');
            } catch (Throwable $e) {
                $this->warn("Could not start the coolify-db container for instance backups: {$e->getMessage()}");
            }
        }

        if ($this->option('gpu')) {
            $this->info('Installing the NVIDIA driver and container toolkit. This can take some minutes.');
            InstallDevelopmentGpuDriver::run($server);
            $this->info('The GPU is ready.');
        }

        return self::SUCCESS;
    }
}