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.
PHP coolifydatabasesdeploymentdockerdocker-composeinertiajslaravelmariadbmysqlnextjsnodejsphppostgresredisself-hostedself-hostingserverstatic-sitesveltesvelte5
Refactoring: extract process handling from async job.
Joao Patriciod0d33da493ac
diff --git a/app/Http/Livewire/RunCommand.php b/app/Http/Livewire/RunCommand.phpindex 76425e0122..ae189422ea 100755--- a/app/Http/Livewire/RunCommand.php+++ b/app/Http/Livewire/RunCommand.php@@ -23,21 +23,21 @@ class RunCommand extends Component{$this->isKeepAliveOn = true;- $this->activity = coolifyProcess($this->command, 'testing-host');+ $this->activity = remoteProcess($this->command, 'testing-host');}public function runSleepingBeauty(){$this->isKeepAliveOn = true;- $this->activity = coolifyProcess('x=1; while [ $x -le 40 ]; do sleep 0.1 && echo "Welcome $x times" $(( x++ )); done', 'testing-host');+ $this->activity = remoteProcess('x=1; while [ $x -le 40 ]; do sleep 0.1 && echo "Welcome $x times" $(( x++ )); done', 'testing-host');}public function runDummyProjectBuild(){$this->isKeepAliveOn = true;- $this->activity = coolifyProcess(<<<EOT+ $this->activity = remoteProcess(<<<EOTcd projects/dummy-project~/.docker/cli-plugins/docker-compose build --no-cacheEOT, 'testing-host');diff --git a/app/Jobs/ExecuteCoolifyProcess.php b/app/Jobs/ExecuteCoolifyProcess.phpindex e6e6898e66..2f128a9bac 100755--- a/app/Jobs/ExecuteCoolifyProcess.php+++ b/app/Jobs/ExecuteCoolifyProcess.php@@ -7,7 +7,6 @@ use Illuminate\Bus\Queueable;use Illuminate\Contracts\Queue\ShouldBeUnique;use Illuminate\Contracts\Queue\ShouldQueue;use Illuminate\Foundation\Bus\Dispatchable;-use Illuminate\Process\ProcessResult;use Illuminate\Queue\InteractsWithQueue;use Illuminate\Queue\SerializesModels;use Spatie\Activitylog\Contracts\Activity;diff --git a/app/Services/CoolifyProcess.php b/app/Services/CoolifyProcess.phpindex cba46ebac5..890d7a0032 100644--- a/app/Services/CoolifyProcess.php+++ b/app/Services/CoolifyProcess.php@@ -3,7 +3,6 @@namespace App\Services;use App\Jobs\ExecuteCoolifyProcess;-use Illuminate\Process\ProcessResult;use Spatie\Activitylog\Contracts\Activity;class CoolifyProcess@@ -36,8 +35,11 @@ class CoolifyProcessdispatch($job);+ $this->activity->refresh();++ ray($this->activity->id);+return $this->activity;}-}diff --git a/bootstrap/helpers.php b/bootstrap/helpers.phpindex 4d26314f22..e4d1f51a74 100644--- a/bootstrap/helpers.php+++ b/bootstrap/helpers.php@@ -3,21 +3,17 @@use App\Services\CoolifyProcess;use Spatie\Activitylog\Contracts\Activity;-if (! function_exists('coolifyProcess')) {+if (! function_exists('remoteProcess')) {/*** Run a Coolify Process, which SSH's into a machine to run the command(s).**/- function coolifyProcess($command, $destination): Activity+ function remoteProcess($command, $destination): Activity{- $process = resolve(CoolifyProcess::class, [+ return resolve(CoolifyProcess::class, ['destination' => $destination,'command' => $command,- ]);-- $activityLog = $process();-- return $activityLog;+ ])();}}diff --git a/tests/Feature/DockerCommandsTest.php b/tests/Feature/DockerCommandsTest.phpindex 45a2f1f649..918025525a 100644--- a/tests/Feature/DockerCommandsTest.php+++ b/tests/Feature/DockerCommandsTest.php@@ -13,21 +13,21 @@ it('starts a docker container correctly', function () {$host = 'testing-host';// Assert there's no containers start with coolify_test_*- $activity = coolifyProcess($areThereCoolifyTestContainers, $host);+ $activity = remoteProcess($areThereCoolifyTestContainers, $host);ray($activity);$containers = Output::containerList($activity->getExtraProperty('stdout'));expect($containers)->toBeEmpty();// start a container nginx -d --name = $containerName- $activity = coolifyProcess("docker run -d --name {$containerName} nginx", $host);+ $activity = remoteProcess("docker run -d --name {$containerName} nginx", $host);expect($activity->getExtraProperty('exitCode'))->toBe(0);// docker ps name = $container- $activity = coolifyProcess($areThereCoolifyTestContainers, $host);+ $activity = remoteProcess($areThereCoolifyTestContainers, $host);$containers = Output::containerList($activity->getExtraProperty('stdout'));expect($containers->where('Names', $containerName)->count())->toBe(1);// Stop testing containers- $activity = coolifyProcess("docker stop $(docker ps --filter='name={$coolifyNamePrefix}*' -q)", $host);+ $activity = remoteProcess("docker stop $(docker ps --filter='name={$coolifyNamePrefix}*' -q)", $host);expect($activity->getExtraProperty('exitCode'))->toBe(0);});