mirror of
https://github.com/coollabsio/coolify.git
synced 2026-11-14 08:42:38 -04:00
Add a Lima backend to scripts/dev. Auto mode picks it on macOS when limactl (Lima >= 2.0) is installed, and COOLIFY_DEV_SERVER_BACKEND=lima forces it. Lima VMs are named coolify-dev-<slot>-<profile>. Coolify connects to them through Lima's forwarded SSH port on host.docker.internal, and only guest ports 80/443 are forwarded to the host. dev:qemu:seed now takes --ip and --port options, so the seeded server can use a forwarded SSH address instead of the profile IP. Add tests for the Lima start flow and for seeding with an overridden address, and document the macOS setup in AGENTS.md.
66 lines
2.2 KiB
PHP
66 lines
2.2 KiB
PHP
<?php
|
|
|
|
namespace App\Actions\Development;
|
|
|
|
use App\Models\PrivateKey;
|
|
use App\Models\Server;
|
|
use InvalidArgumentException;
|
|
use Lorisleiva\Actions\Concerns\AsAction;
|
|
use RuntimeException;
|
|
|
|
class SeedDevelopmentQemuServer
|
|
{
|
|
use AsAction;
|
|
|
|
/**
|
|
* $ip and $port override the profile address, for example for a Lima VM whose SSH port is forwarded to the host.
|
|
*/
|
|
public function handle(string $profileName, bool $removeOtherServers = true, bool $asLocalhost = false, ?string $ip = null, int $port = 22): Server
|
|
{
|
|
$this->ensureDevelopmentEnvironment();
|
|
$profile = config("development-qemu.profiles.{$profileName}");
|
|
|
|
if (! is_array($profile)) {
|
|
throw new InvalidArgumentException("Unknown development QEMU profile: {$profileName}");
|
|
}
|
|
|
|
$privateKey = PrivateKey::query()->find(1);
|
|
|
|
if (! $privateKey) {
|
|
throw new RuntimeException('Development private key 1 is missing. Run the development database seeders first.');
|
|
}
|
|
|
|
if ($removeOtherServers) {
|
|
Server::query()
|
|
->where('uuid', 'like', 'development-qemu-%')
|
|
->where('uuid', '!=', $profile['uuid'])
|
|
->delete();
|
|
}
|
|
|
|
$server = $asLocalhost
|
|
? (Server::withTrashed()->find(0) ?? new Server)
|
|
: (Server::withTrashed()->where('uuid', $profile['uuid'])->first() ?? new Server);
|
|
$server->forceFill($asLocalhost ? ['id' => 0, 'uuid' => 'localhost'] : ['uuid' => $profile['uuid']]);
|
|
$server->fill([
|
|
'name' => $asLocalhost ? 'localhost' : $profile['name'],
|
|
'description' => 'Development QEMU virtual machine',
|
|
'ip' => $ip ?? $profile['ip'],
|
|
'port' => $port,
|
|
'user' => $profile['user'],
|
|
'team_id' => 0,
|
|
'private_key_id' => $privateKey->id,
|
|
]);
|
|
$server->deleted_at = null;
|
|
$server->save();
|
|
|
|
return $server->fresh();
|
|
}
|
|
|
|
private function ensureDevelopmentEnvironment(): void
|
|
{
|
|
if (! in_array(config('app.env'), ['local', 'development', 'dev'], true)) {
|
|
throw new RuntimeException('QEMU VM servers may only be seeded in development environments.');
|
|
}
|
|
}
|
|
}
|