Files
coolify/app/Actions/Development/ManageDevelopmentQemuVm.php
T
Andras BacsaiandClaude Opus 5.5 338f1f837f feat(dev): run one isolated dev instance per git branch
Merge scripts/dev-instances into scripts/dev. Each branch gets its own
Compose project, container, volumes, port block, libvirt network, and
KVM VMs, so stop and start reuse the same data and worktrees do not
collide.

- Name instances after the branch; keep slots and APP_KEYs in the main
  checkout's .dev-instances/ so they survive worktree removal
- Reuse existing QEMU VMs instead of recreating them; add dev:qemu --fresh
- Give each instance an isolated libvirt network (10.221.<slot>.0/24)
  and VM names coolify-dev-<branch>--<profile>
- Publish per-instance browser ports and publish them with tailscale
  serve when APP_URL is a tailnet host
- Add urls, exec, logs, container, destroy, and teardown commands; run
  teardown from jean.json before Jean deletes a worktree
- Fix Reverb/terminal browser ports and the testing-host alias in the
  instance compose file
- Keep fresh worktree instances working: pre-create laravel.log, log the
  host dev:qemu call to stderr, and stop Vite from watching vendor/

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-09-25 11:55:49 +02:00

40 lines
1.4 KiB
PHP

<?php
namespace App\Actions\Development;
use Illuminate\Database\QueryException;
use Illuminate\Support\Facades\Process;
use Lorisleiva\Actions\Concerns\AsAction;
class ManageDevelopmentQemuVm
{
use AsAction;
/**
* Start (or create) the selected VMs and seed their servers. Existing VMs are reused unless $fresh is set.
*
* @param string|array<int, string> $profileNames
*/
public function handle(string|array $profileNames, bool $asLocalhost = false, bool $fresh = false): void
{
$profileNames = is_array($profileNames) ? array_values(array_unique($profileNames)) : [$profileNames];
foreach ($profileNames as $index => $profileName) {
StartDevelopmentQemuVm::run($profileName, $fresh);
try {
SeedDevelopmentQemuServer::run($profileName, $index === 0, $asLocalhost);
} catch (QueryException $exception) {
$keepOthers = $index === 0 ? '' : ' --keep-others';
$localhostOption = $asLocalhost ? ' --as-localhost' : '';
$container = escapeshellarg(config('development-qemu.coolify_container'));
$result = Process::run("docker exec {$container} php artisan dev:qemu:seed ".escapeshellarg($profileName).$keepOthers.$localhostOption);
if ($result->failed()) {
throw $exception;
}
}
}
}
}