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.

wip

Joao Patricio79a850f3b904
diff --git a/app/Actions/CoolifyTask/PrepareCoolifyTask.php b/app/Actions/CoolifyTask/PrepareCoolifyTask.php
index d9a3ece2bb..c67a8bcb32 100644
--- a/app/Actions/CoolifyTask/PrepareCoolifyTask.php
+++ b/app/Actions/CoolifyTask/PrepareCoolifyTask.php
@@ -3,9 +3,14 @@
namespace App\Actions\CoolifyTask;
use App\Data\CoolifyTaskArgs;
-use App\Jobs\HandleCoolifyTaskInQueue;
+use App\Jobs\CoolifyTask;
use Spatie\Activitylog\Models\Activity;
+/**
+ * The initial step to run a `CoolifyTask`: a remote SSH process
+ * with monitoring/tracking/trace feature. Such thing is made
+ * possible using an Activity model and some attributes.
+ */
class PrepareCoolifyTask
{
protected Activity $activity;
@@ -31,7 +36,7 @@ class PrepareCoolifyTask
public function __invoke(): Activity
{
- $job = new HandleCoolifyTaskInQueue($this->activity);
+ $job = new CoolifyTask($this->activity);
dispatch($job);
$this->activity->refresh();
return $this->activity;
diff --git a/app/Actions/CoolifyTask/RunRemoteProcess.php b/app/Actions/CoolifyTask/RunRemoteProcess.php
index a8c49a7c7f..979144b010 100644
--- a/app/Actions/CoolifyTask/RunRemoteProcess.php
+++ b/app/Actions/CoolifyTask/RunRemoteProcess.php
@@ -36,7 +36,7 @@ class RunRemoteProcess
public function __construct(Activity $activity, bool $hideFromOutput = false, bool $isFinished = false, bool $ignoreErrors = false)
{
- if ($activity->getExtraProperty('type') !== ActivityTypes::REMOTE_PROCESS->value && $activity->getExtraProperty('type') !== ActivityTypes::DEPLOYMENT->value) {
+ if ($activity->getExtraProperty('type') !== ActivityTypes::INSTANT->value && $activity->getExtraProperty('type') !== ActivityTypes::DEPLOYMENT->value) {
throw new \RuntimeException('Incompatible Activity to run a remote command.');
}
diff --git a/app/Data/CoolifyTaskArgs.php b/app/Data/CoolifyTaskArgs.php
index 803143a9a9..09ab923abb 100644
--- a/app/Data/CoolifyTaskArgs.php
+++ b/app/Data/CoolifyTaskArgs.php
@@ -6,6 +6,9 @@ use App\Enums\ProcessStatus;
use Illuminate\Database\Eloquent\Model;
use Spatie\LaravelData\Data;
+/**
+ * The parameters to execute a CoolifyTask, organized in a DTO.
+ */
class CoolifyTaskArgs extends Data
{
public function __construct(
diff --git a/app/Enums/ActivityTypes.php b/app/Enums/ActivityTypes.php
index 5bcab7cd77..fac79267d7 100644
--- a/app/Enums/ActivityTypes.php
+++ b/app/Enums/ActivityTypes.php
@@ -4,6 +4,6 @@ namespace App\Enums;
enum ActivityTypes: string
{
- case REMOTE_PROCESS = 'remote_process';
+ case INSTANT = 'instant';
case DEPLOYMENT = 'deployment';
}
diff --git a/app/Http/Livewire/Destination/New/StandaloneDocker.php b/app/Http/Livewire/Destination/New/StandaloneDocker.php
index 1d22e65fbc..5abf19a90a 100644
--- a/app/Http/Livewire/Destination/New/StandaloneDocker.php
+++ b/app/Http/Livewire/Destination/New/StandaloneDocker.php
@@ -45,7 +45,7 @@ class StandaloneDocker extends Component
$server = Server::find($this->server_id);
- runRemoteCommandSync($server, ['docker network create --attachable ' . $this->network], throwError: false);
+ instantRemoteProcess($server, ['docker network create --attachable ' . $this->network], throwError: false);
return redirect()->route('destination.show', $docker->uuid);
}
}
diff --git a/app/Http/Livewire/ForceUpgrade.php b/app/Http/Livewire/ForceUpgrade.php
index ad6dd2ba49..7064170146 100644
--- a/app/Http/Livewire/ForceUpgrade.php
+++ b/app/Http/Livewire/ForceUpgrade.php
@@ -2,25 +2,26 @@
namespace App\Http\Livewire;
+use App\Enums\ActivityTypes;
use App\Models\Server;
-use Illuminate\Support\Facades\Http;
use Livewire\Component;
class ForceUpgrade extends Component
{
public function upgrade()
{
- if (env('APP_ENV') === 'local') {
+ //if (env('APP_ENV') === 'local') {
+ if (config('app.env') === 'local') {
$server = Server::where('ip', 'coolify-testing-host')->first();
if (!$server) {
return;
}
- runRemoteCommandSync($server, [
+ instantRemoteProcess($server, [
"sleep 2"
]);
remoteProcess([
"sleep 10"
- ], $server);
+ ], $server, ActivityTypes::INSTANT->value);
$this->emit('updateInitiated');
} else {
$latestVersion = getLatestVersionOfCoolify();
@@ -31,19 +32,19 @@ class ForceUpgrade extends Component
return;
}
- runRemoteCommandSync($server, [
+ instantRemoteProcess($server, [
"curl -fsSL $cdn/docker-compose.yml -o /data/coolify/source/docker-compose.yml",
"curl -fsSL $cdn/docker-compose.prod.yml -o /data/coolify/source/docker-compose.prod.yml",
"curl -fsSL $cdn/.env.production -o /data/coolify/source/.env.production",
"curl -fsSL $cdn/upgrade.sh -o /data/coolify/source/upgrade.sh",
]);
- runRemoteCommandSync($server, [
+ instantRemoteProcess($server, [
"docker compose -f /data/coolify/source/docker-compose.yml -f /data/coolify/source/docker-compose.prod.yml pull",
]);
remoteProcess([
"bash /data/coolify/source/upgrade.sh $latestVersion"
- ], $server);
+ ], $server, ActivityTypes::INSTANT->value);
$this->emit('updateInitiated');
}
diff --git a/app/Http/Livewire/Project/Application/Deploy.php b/app/Http/Livewire/Project/Application/Deploy.php
index a4ac4ab2d9..ba31e4fbf4 100644
--- a/app/Http/Livewire/Project/Application/Deploy.php
+++ b/app/Http/Livewire/Project/Application/Deploy.php
@@ -73,7 +73,7 @@ class Deploy extends Component
}
public function stop()
{
- runRemoteCommandSync($this->destination->server, ["docker rm -f {$this->application->uuid}"]);
+ instantRemoteProcess($this->destination->server, ["docker rm -f {$this->application->uuid}"]);
if ($this->application->status != 'exited') {
$this->application->status = 'exited';
$this->application->save();
diff --git a/app/Http/Livewire/RunCommand.php b/app/Http/Livewire/RunCommand.php
index 9eaa2bbd1b..1e3f78f15c 100755
--- a/app/Http/Livewire/RunCommand.php
+++ b/app/Http/Livewire/RunCommand.php
@@ -2,6 +2,7 @@
namespace App\Http\Livewire;
+use App\Enums\ActivityTypes;
use App\Models\Server;
use Livewire\Component;
@@ -31,19 +32,19 @@ class RunCommand extends Component
public function runCommand()
{
$this->isKeepAliveOn = true;
- $this->activity = remoteProcess([$this->command], Server::where('uuid', $this->server)->first());
+ $this->activity = remoteProcess([$this->command], Server::where('uuid', $this->server)->first(), ActivityTypes::INSTANT->value);
}
public function runSleepingBeauty()
{
$this->isKeepAliveOn = true;
- $this->activity = remoteProcess(['x=1; while [ $x -le 40 ]; do sleep 0.1 && echo "Welcome $x times" $(( x++ )); done'], Server::where('uuid', $this->server)->first());
+ $this->activity = remoteProcess(['x=1; while [ $x -le 40 ]; do sleep 0.1 && echo "Welcome $x times" $(( x++ )); done'], Server::where('uuid', $this->server)->first(), ActivityTypes::INSTANT->value);
}
public function runDummyProjectBuild()
{
$this->isKeepAliveOn = true;
- $this->activity = remoteProcess([' cd projects/dummy-project', 'docker-compose build --no-cache'], Server::where('uuid', $this->server)->first());
+ $this->activity = remoteProcess([' cd projects/dummy-project', 'docker-compose build --no-cache'], Server::where('uuid', $this->server)->first(), ActivityTypes::INSTANT->value);
}
public function polling()
diff --git a/app/Http/Livewire/Server/Form.php b/app/Http/Livewire/Server/Form.php
index e4d9916fde..08d2d7cf95 100644
--- a/app/Http/Livewire/Server/Form.php
+++ b/app/Http/Livewire/Server/Form.php
@@ -28,15 +28,15 @@ class Form extends Component
public function installDocker()
{
$config = base64_encode('{ "live-restore": true }');
- runRemoteCommandSync($this->server, [
+ instantRemoteProcess($this->server, [
"curl https://releases.rancher.com/install-docker/23.0.sh | sh"
]);
}
public function checkServer()
{
- $this->uptime = runRemoteCommandSync($this->server, ['uptime']);
- $this->dockerVersion = runRemoteCommandSync($this->server, ['docker version|head -2|grep -i version'], false);
- $this->dockerComposeVersion = runRemoteCommandSync($this->server, ['docker compose version|head -2|grep -i version'], false);
+ $this->uptime = instantRemoteProcess($this->server, ['uptime']);
+ $this->dockerVersion = instantRemoteProcess($this->server, ['docker version|head -2|grep -i version'], false);
+ $this->dockerComposeVersion = instantRemoteProcess($this->server, ['docker compose version|head -2|grep -i version'], false);
}
public function submit()
{
diff --git a/app/Jobs/CoolifyTask.php b/app/Jobs/CoolifyTask.php
index d2236027ec..d96095cc4f 100755
--- a/app/Jobs/CoolifyTask.php
+++ b/app/Jobs/CoolifyTask.php
@@ -10,7 +10,7 @@ use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Queue\SerializesModels;
use Spatie\Activitylog\Models\Activity;
-class HandleCoolifyTaskInQueue implements ShouldQueue
+class CoolifyTask implements ShouldQueue
{
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
diff --git a/app/Jobs/DockerCleanupDanglingImagesJob.php b/app/Jobs/DockerCleanupDanglingImagesJob.php
index d5798ba54a..0938b6bb87 100644
--- a/app/Jobs/DockerCleanupDanglingImagesJob.php
+++ b/app/Jobs/DockerCleanupDanglingImagesJob.php
@@ -31,7 +31,7 @@ class DockerCleanupDanglingImagesJob implements ShouldQueue
try {
$servers = Server::all();
foreach ($servers as $server) {
- runRemoteCommandSync($server, ['docker image prune -f']);
+ instantRemoteProcess($server, ['docker image prune -f']);
}
} catch (\Exception $e) {
Log::error($e->getMessage());
diff --git a/app/Providers/AppServiceProvider.php b/app/Providers/AppServiceProvider.php
index 1256de2cbc..9945221c8a 100644
--- a/app/Providers/AppServiceProvider.php
+++ b/app/Providers/AppServiceProvider.php
@@ -2,7 +2,7 @@
namespace App\Providers;
-use App\Jobs\HandleCoolifyTaskInQueue;
+use App\Jobs\CoolifyTask;
use Illuminate\Queue\Events\JobProcessed;
use Illuminate\Support\Facades\Process;
use Illuminate\Support\Facades\Queue;
@@ -32,7 +32,7 @@ class AppServiceProvider extends ServiceProvider
{
Queue::after(function (JobProcessed $event) {
// @TODO: Remove `coolify-builder` container after the remoteProcess job is finishged and remoteProcess->type == `deployment`.
- if ($event->job->resolveName() === HandleCoolifyTaskInQueue::class) {
+ if ($event->job->resolveName() === CoolifyTask::class) {
}
});
diff --git a/bootstrap/helpers.php b/bootstrap/helpers.php
index 2ff7395705..49569d1a42 100644
--- a/bootstrap/helpers.php
+++ b/bootstrap/helpers.php
@@ -20,6 +20,7 @@ if (!function_exists('remoteProcess')) {
function remoteProcess(
array $command,
Server $server,
+ string $type,
?string $type_uuid = null,
?Model $model = null,
): Activity {
@@ -40,7 +41,7 @@ if (!function_exists('remoteProcess')) {
EOT,
port: $server->port,
user: $server->user,
- type: $type_uuid,
+ type: $type,
type_uuid: $type_uuid,
model: $model,
),