mirror of
https://github.com/ershisan99/coolify.git
synced 2025-12-17 04:59:30 +00:00
Merge pull request #1061 from coollabsio/patricio-wip-11
Refactor for CoolifyTask
This commit is contained in:
8
.github/workflows/docker-image.yml
vendored
8
.github/workflows/docker-image.yml
vendored
@@ -1,10 +1,14 @@
|
|||||||
name: Docker Image CI
|
name: Docker Image CI
|
||||||
|
|
||||||
on:
|
on:
|
||||||
|
# push:
|
||||||
|
# branches: [ "main" ]
|
||||||
|
# pull_request:
|
||||||
|
# branches: [ "*" ]
|
||||||
push:
|
push:
|
||||||
branches: [ "main" ]
|
branches: ["this-does-not-exist"]
|
||||||
pull_request:
|
pull_request:
|
||||||
branches: [ "*" ]
|
branches: ["this-does-not-exist"]
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
build:
|
build:
|
||||||
|
|||||||
3
.gitignore
vendored
3
.gitignore
vendored
@@ -21,5 +21,8 @@ yarn-error.log
|
|||||||
/.bash_history
|
/.bash_history
|
||||||
/_volumes
|
/_volumes
|
||||||
|
|
||||||
|
resources/recipes
|
||||||
|
|
||||||
.lesshst
|
.lesshst
|
||||||
psysh_history
|
psysh_history
|
||||||
|
.psql_history
|
||||||
|
|||||||
@@ -1,16 +1,21 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace App\Actions\RemoteProcess;
|
namespace App\Actions\CoolifyTask;
|
||||||
|
|
||||||
use App\Data\RemoteProcessArgs;
|
use App\Data\CoolifyTaskArgs;
|
||||||
use App\Jobs\ExecuteRemoteProcess;
|
use App\Jobs\CoolifyTask;
|
||||||
use Spatie\Activitylog\Models\Activity;
|
use Spatie\Activitylog\Models\Activity;
|
||||||
|
|
||||||
class DispatchRemoteProcess
|
/**
|
||||||
|
* 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;
|
protected Activity $activity;
|
||||||
|
|
||||||
public function __construct(RemoteProcessArgs $remoteProcessArgs)
|
public function __construct(CoolifyTaskArgs $remoteProcessArgs)
|
||||||
{
|
{
|
||||||
if ($remoteProcessArgs->model) {
|
if ($remoteProcessArgs->model) {
|
||||||
$properties = $remoteProcessArgs->toArray();
|
$properties = $remoteProcessArgs->toArray();
|
||||||
@@ -31,7 +36,7 @@ class DispatchRemoteProcess
|
|||||||
|
|
||||||
public function __invoke(): Activity
|
public function __invoke(): Activity
|
||||||
{
|
{
|
||||||
$job = new ExecuteRemoteProcess($this->activity);
|
$job = new CoolifyTask($this->activity);
|
||||||
dispatch($job);
|
dispatch($job);
|
||||||
$this->activity->refresh();
|
$this->activity->refresh();
|
||||||
return $this->activity;
|
return $this->activity;
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace App\Actions\RemoteProcess;
|
namespace App\Actions\CoolifyTask;
|
||||||
|
|
||||||
use App\Enums\ActivityTypes;
|
use App\Enums\ActivityTypes;
|
||||||
use App\Enums\ProcessStatus;
|
use App\Enums\ProcessStatus;
|
||||||
@@ -36,7 +36,7 @@ class RunRemoteProcess
|
|||||||
public function __construct(Activity $activity, bool $hideFromOutput = false, bool $isFinished = false, bool $ignoreErrors = false)
|
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::INLINE->value && $activity->getExtraProperty('type') !== ActivityTypes::DEPLOYMENT->value) {
|
||||||
throw new \RuntimeException('Incompatible Activity to run a remote command.');
|
throw new \RuntimeException('Incompatible Activity to run a remote command.');
|
||||||
}
|
}
|
||||||
|
|
||||||
26
app/Data/CoolifyTaskArgs.php
Normal file
26
app/Data/CoolifyTaskArgs.php
Normal file
@@ -0,0 +1,26 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Data;
|
||||||
|
|
||||||
|
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(
|
||||||
|
public string $server_ip,
|
||||||
|
public string $private_key_location,
|
||||||
|
public string $command,
|
||||||
|
public int $port,
|
||||||
|
public string $user,
|
||||||
|
public string $type,
|
||||||
|
public ?string $type_uuid = null,
|
||||||
|
public ?Model $model = null,
|
||||||
|
public string $status = ProcessStatus::HOLDING->value,
|
||||||
|
) {
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,24 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
namespace App\Data;
|
|
||||||
|
|
||||||
use App\Enums\ActivityTypes;
|
|
||||||
use App\Enums\ProcessStatus;
|
|
||||||
use Illuminate\Database\Eloquent\Model;
|
|
||||||
use Spatie\LaravelData\Data;
|
|
||||||
|
|
||||||
class RemoteProcessArgs extends Data
|
|
||||||
{
|
|
||||||
public function __construct(
|
|
||||||
public string $server_ip,
|
|
||||||
public string $private_key_location,
|
|
||||||
public string|null $deployment_uuid,
|
|
||||||
public string $command,
|
|
||||||
public int $port,
|
|
||||||
public string $user,
|
|
||||||
public string $type = ActivityTypes::REMOTE_PROCESS->value,
|
|
||||||
public string $status = ProcessStatus::HOLDING->value,
|
|
||||||
public ?Model $model = null,
|
|
||||||
) {
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -4,6 +4,6 @@ namespace App\Enums;
|
|||||||
|
|
||||||
enum ActivityTypes: string
|
enum ActivityTypes: string
|
||||||
{
|
{
|
||||||
case REMOTE_PROCESS = 'remote_process';
|
case INLINE = 'inline';
|
||||||
case DEPLOYMENT = 'deployment';
|
case DEPLOYMENT = 'deployment';
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -56,8 +56,14 @@ class ApplicationController extends Controller
|
|||||||
if (!$application) {
|
if (!$application) {
|
||||||
return redirect()->route('dashboard');
|
return redirect()->route('dashboard');
|
||||||
}
|
}
|
||||||
$activity = Activity::where('properties->deployment_uuid', '=', $deployment_uuid)->first();
|
$activity = Activity::where('properties->type_uuid', '=', $deployment_uuid)->first();
|
||||||
|
if (!$activity) {
|
||||||
|
return redirect()->route('project.application.deployments', [
|
||||||
|
'project_uuid' => $project->uuid,
|
||||||
|
'environment_name' => $environment->name,
|
||||||
|
'application_uuid' => $application->uuid,
|
||||||
|
]);
|
||||||
|
}
|
||||||
return view('project.application.deployment', [
|
return view('project.application.deployment', [
|
||||||
'application' => $application,
|
'application' => $application,
|
||||||
'activity' => $activity,
|
'activity' => $activity,
|
||||||
|
|||||||
@@ -93,7 +93,10 @@ class ProjectController extends Controller
|
|||||||
if (!$application) {
|
if (!$application) {
|
||||||
return redirect()->route('dashboard');
|
return redirect()->route('dashboard');
|
||||||
}
|
}
|
||||||
$activity = Activity::where('properties->deployment_uuid', '=', $deployment_uuid)->first();
|
$activity = Activity::query()
|
||||||
|
->where('properties->type', '=', 'deployment')
|
||||||
|
->where('properties->uuid', '=', $deployment_uuid)
|
||||||
|
->first();
|
||||||
|
|
||||||
return view('project.application.deployment', [
|
return view('project.application.deployment', [
|
||||||
'application' => $application,
|
'application' => $application,
|
||||||
|
|||||||
@@ -45,7 +45,7 @@ class StandaloneDocker extends Component
|
|||||||
|
|
||||||
$server = Server::find($this->server_id);
|
$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);
|
return redirect()->route('destination.show', $docker->uuid);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,25 +2,26 @@
|
|||||||
|
|
||||||
namespace App\Http\Livewire;
|
namespace App\Http\Livewire;
|
||||||
|
|
||||||
|
use App\Enums\ActivityTypes;
|
||||||
use App\Models\Server;
|
use App\Models\Server;
|
||||||
use Illuminate\Support\Facades\Http;
|
|
||||||
use Livewire\Component;
|
use Livewire\Component;
|
||||||
|
|
||||||
class ForceUpgrade extends Component
|
class ForceUpgrade extends Component
|
||||||
{
|
{
|
||||||
public function upgrade()
|
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();
|
$server = Server::where('ip', 'coolify-testing-host')->first();
|
||||||
if (!$server) {
|
if (!$server) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
runRemoteCommandSync($server, [
|
instantRemoteProcess($server, [
|
||||||
"sleep 2"
|
"sleep 2"
|
||||||
]);
|
]);
|
||||||
remoteProcess([
|
remoteProcess([
|
||||||
"sleep 10"
|
"sleep 10"
|
||||||
], $server);
|
], $server, ActivityTypes::INLINE->value);
|
||||||
$this->emit('updateInitiated');
|
$this->emit('updateInitiated');
|
||||||
} else {
|
} else {
|
||||||
$latestVersion = getLatestVersionOfCoolify();
|
$latestVersion = getLatestVersionOfCoolify();
|
||||||
@@ -31,19 +32,19 @@ class ForceUpgrade extends Component
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
runRemoteCommandSync($server, [
|
instantRemoteProcess($server, [
|
||||||
"curl -fsSL $cdn/docker-compose.yml -o /data/coolify/source/docker-compose.yml",
|
"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/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/.env.production -o /data/coolify/source/.env.production",
|
||||||
"curl -fsSL $cdn/upgrade.sh -o /data/coolify/source/upgrade.sh",
|
"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",
|
"docker compose -f /data/coolify/source/docker-compose.yml -f /data/coolify/source/docker-compose.prod.yml pull",
|
||||||
]);
|
]);
|
||||||
|
|
||||||
remoteProcess([
|
remoteProcess([
|
||||||
"bash /data/coolify/source/upgrade.sh $latestVersion"
|
"bash /data/coolify/source/upgrade.sh $latestVersion"
|
||||||
], $server);
|
], $server, ActivityTypes::INLINE->value);
|
||||||
|
|
||||||
$this->emit('updateInitiated');
|
$this->emit('updateInitiated');
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -73,7 +73,7 @@ class Deploy extends Component
|
|||||||
}
|
}
|
||||||
public function stop()
|
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') {
|
if ($this->application->status != 'exited') {
|
||||||
$this->application->status = 'exited';
|
$this->application->status = 'exited';
|
||||||
$this->application->save();
|
$this->application->save();
|
||||||
|
|||||||
@@ -12,7 +12,7 @@ class GetDeployments extends Component
|
|||||||
public string $status;
|
public string $status;
|
||||||
public function polling()
|
public function polling()
|
||||||
{
|
{
|
||||||
$activity = Activity::where('properties->deployment_uuid', '=', $this->deployment_uuid)->first();
|
$activity = Activity::where('properties->type_uuid', '=', $this->deployment_uuid)->first();
|
||||||
$this->created_at = $activity->created_at;
|
$this->created_at = $activity->created_at;
|
||||||
$this->status = data_get($activity, 'properties.status');
|
$this->status = data_get($activity, 'properties.status');
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
namespace App\Http\Livewire\Project\Application;
|
namespace App\Http\Livewire\Project\Application;
|
||||||
|
|
||||||
|
use App\Enums\ActivityTypes;
|
||||||
use Livewire\Component;
|
use Livewire\Component;
|
||||||
use Spatie\Activitylog\Models\Activity;
|
use Spatie\Activitylog\Models\Activity;
|
||||||
|
|
||||||
@@ -14,7 +15,9 @@ class PollDeployment extends Component
|
|||||||
public function polling()
|
public function polling()
|
||||||
{
|
{
|
||||||
if ( is_null($this->activity) && isset($this->deployment_uuid)) {
|
if ( is_null($this->activity) && isset($this->deployment_uuid)) {
|
||||||
$this->activity = Activity::where('properties->deployment_uuid', '=', $this->deployment_uuid)
|
$this->activity = Activity::query()
|
||||||
|
->where('properties->type', '=', ActivityTypes::DEPLOYMENT->value)
|
||||||
|
->where('properties->type_uuid', '=', $this->deployment_uuid)
|
||||||
->first();
|
->first();
|
||||||
} else {
|
} else {
|
||||||
$this->activity?->refresh();
|
$this->activity?->refresh();
|
||||||
|
|||||||
@@ -38,7 +38,7 @@ class PublicGitRepository extends Component
|
|||||||
];
|
];
|
||||||
public function mount()
|
public function mount()
|
||||||
{
|
{
|
||||||
if (env('APP_ENV') === 'local') {
|
if (config('app.env') === 'local') {
|
||||||
$this->public_repository_url = 'https://github.com/coollabsio/coolify-examples/tree/nodejs-fastify';
|
$this->public_repository_url = 'https://github.com/coollabsio/coolify-examples/tree/nodejs-fastify';
|
||||||
$this->port = 3000;
|
$this->port = 3000;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
namespace App\Http\Livewire;
|
namespace App\Http\Livewire;
|
||||||
|
|
||||||
|
use App\Enums\ActivityTypes;
|
||||||
use App\Models\Server;
|
use App\Models\Server;
|
||||||
use Livewire\Component;
|
use Livewire\Component;
|
||||||
|
|
||||||
@@ -31,19 +32,19 @@ class RunCommand extends Component
|
|||||||
public function runCommand()
|
public function runCommand()
|
||||||
{
|
{
|
||||||
$this->isKeepAliveOn = true;
|
$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::INLINE->value);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function runSleepingBeauty()
|
public function runSleepingBeauty()
|
||||||
{
|
{
|
||||||
$this->isKeepAliveOn = true;
|
$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::INLINE->value);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function runDummyProjectBuild()
|
public function runDummyProjectBuild()
|
||||||
{
|
{
|
||||||
$this->isKeepAliveOn = true;
|
$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::INLINE->value);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function polling()
|
public function polling()
|
||||||
|
|||||||
@@ -28,15 +28,15 @@ class Form extends Component
|
|||||||
public function installDocker()
|
public function installDocker()
|
||||||
{
|
{
|
||||||
$config = base64_encode('{ "live-restore": true }');
|
$config = base64_encode('{ "live-restore": true }');
|
||||||
runRemoteCommandSync($this->server, [
|
instantRemoteProcess($this->server, [
|
||||||
"curl https://releases.rancher.com/install-docker/23.0.sh | sh"
|
"curl https://releases.rancher.com/install-docker/23.0.sh | sh"
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
public function checkServer()
|
public function checkServer()
|
||||||
{
|
{
|
||||||
$this->uptime = runRemoteCommandSync($this->server, ['uptime']);
|
$this->uptime = instantRemoteProcess($this->server, ['uptime']);
|
||||||
$this->dockerVersion = runRemoteCommandSync($this->server, ['docker version|head -2|grep -i version'], false);
|
$this->dockerVersion = instantRemoteProcess($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->dockerComposeVersion = instantRemoteProcess($this->server, ['docker compose version|head -2|grep -i version'], false);
|
||||||
}
|
}
|
||||||
public function submit()
|
public function submit()
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -38,7 +38,7 @@ class ContainerStatusJob implements ShouldQueue
|
|||||||
$not_found_applications = $applications;
|
$not_found_applications = $applications;
|
||||||
$containers = collect();
|
$containers = collect();
|
||||||
foreach ($servers as $server) {
|
foreach ($servers as $server) {
|
||||||
$output = runRemoteCommandSync($server, ['docker ps -a -q --format \'{{json .}}\'']);
|
$output = instantRemoteProcess($server, ['docker ps -a -q --format \'{{json .}}\'']);
|
||||||
$containers = $containers->concat(formatDockerCmdOutputToJson($output));
|
$containers = $containers->concat(formatDockerCmdOutputToJson($output));
|
||||||
}
|
}
|
||||||
foreach ($containers as $container) {
|
foreach ($containers as $container) {
|
||||||
@@ -67,7 +67,7 @@ class ContainerStatusJob implements ShouldQueue
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if ($application->destination->server) {
|
if ($application->destination->server) {
|
||||||
$container = runRemoteCommandSync($application->destination->server, ["docker inspect --format '{{json .State}}' {$this->container_id}"]);
|
$container = instantRemoteProcess($application->destination->server, ["docker inspect --format '{{json .State}}' {$this->container_id}"]);
|
||||||
$container = formatDockerCmdOutputToJson($container);
|
$container = formatDockerCmdOutputToJson($container);
|
||||||
$application->status = $container[0]['Status'];
|
$application->status = $container[0]['Status'];
|
||||||
$application->save();
|
$application->save();
|
||||||
|
|||||||
@@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
namespace App\Jobs;
|
namespace App\Jobs;
|
||||||
|
|
||||||
use App\Actions\RemoteProcess\RunRemoteProcess;
|
use App\Actions\CoolifyTask\RunRemoteProcess;
|
||||||
use Illuminate\Bus\Queueable;
|
use Illuminate\Bus\Queueable;
|
||||||
use Illuminate\Contracts\Queue\ShouldQueue;
|
use Illuminate\Contracts\Queue\ShouldQueue;
|
||||||
use Illuminate\Foundation\Bus\Dispatchable;
|
use Illuminate\Foundation\Bus\Dispatchable;
|
||||||
@@ -10,7 +10,7 @@ use Illuminate\Queue\InteractsWithQueue;
|
|||||||
use Illuminate\Queue\SerializesModels;
|
use Illuminate\Queue\SerializesModels;
|
||||||
use Spatie\Activitylog\Models\Activity;
|
use Spatie\Activitylog\Models\Activity;
|
||||||
|
|
||||||
class ExecuteRemoteProcess implements ShouldQueue
|
class CoolifyTask implements ShouldQueue
|
||||||
{
|
{
|
||||||
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
|
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
|
||||||
|
|
||||||
@@ -2,8 +2,8 @@
|
|||||||
|
|
||||||
namespace App\Jobs;
|
namespace App\Jobs;
|
||||||
|
|
||||||
use App\Actions\RemoteProcess\RunRemoteProcess;
|
use App\Actions\CoolifyTask\RunRemoteProcess;
|
||||||
use App\Data\RemoteProcessArgs;
|
use App\Data\CoolifyTaskArgs;
|
||||||
use App\Enums\ActivityTypes;
|
use App\Enums\ActivityTypes;
|
||||||
use App\Models\Application;
|
use App\Models\Application;
|
||||||
use App\Models\InstanceSettings;
|
use App\Models\InstanceSettings;
|
||||||
@@ -55,14 +55,14 @@ class DeployApplicationJob implements ShouldQueue
|
|||||||
|
|
||||||
$private_key_location = savePrivateKeyForServer($server);
|
$private_key_location = savePrivateKeyForServer($server);
|
||||||
|
|
||||||
$remoteProcessArgs = new RemoteProcessArgs(
|
$remoteProcessArgs = new CoolifyTaskArgs(
|
||||||
server_ip: $server->ip,
|
server_ip: $server->ip,
|
||||||
private_key_location: $private_key_location,
|
private_key_location: $private_key_location,
|
||||||
deployment_uuid: $this->deployment_uuid,
|
|
||||||
command: 'overwritten-later',
|
command: 'overwritten-later',
|
||||||
port: $server->port,
|
port: $server->port,
|
||||||
user: $server->user,
|
user: $server->user,
|
||||||
type: ActivityTypes::DEPLOYMENT->value,
|
type: ActivityTypes::DEPLOYMENT->value,
|
||||||
|
type_uuid: $this->deployment_uuid,
|
||||||
);
|
);
|
||||||
|
|
||||||
$this->activity = activity()
|
$this->activity = activity()
|
||||||
|
|||||||
@@ -31,7 +31,7 @@ class DockerCleanupDanglingImagesJob implements ShouldQueue
|
|||||||
try {
|
try {
|
||||||
$servers = Server::all();
|
$servers = Server::all();
|
||||||
foreach ($servers as $server) {
|
foreach ($servers as $server) {
|
||||||
runRemoteCommandSync($server, ['docker image prune -f']);
|
instantRemoteProcess($server, ['docker image prune -f']);
|
||||||
}
|
}
|
||||||
} catch (\Exception $e) {
|
} catch (\Exception $e) {
|
||||||
Log::error($e->getMessage());
|
Log::error($e->getMessage());
|
||||||
|
|||||||
@@ -94,13 +94,12 @@ class Application extends BaseModel
|
|||||||
return $this->morphMany(LocalPersistentVolume::class, 'resource');
|
return $this->morphMany(LocalPersistentVolume::class, 'resource');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public function deployments()
|
public function deployments()
|
||||||
{
|
{
|
||||||
return Activity::where('subject_id', $this->id)->where('properties->deployment_uuid', '!=', null)->orderBy('created_at', 'desc')->get();
|
return Activity::where('subject_id', $this->id)->where('properties->type', '=', 'deployment')->orderBy('created_at', 'desc')->get();
|
||||||
}
|
}
|
||||||
public function get_deployment(string $deployment_uuid)
|
public function get_deployment(string $deployment_uuid)
|
||||||
{
|
{
|
||||||
return Activity::where('subject_id', $this->id)->where('properties->deployment_uuid', '=', $deployment_uuid)->first();
|
return Activity::where('subject_id', $this->id)->where('properties->type_uuid', '=', $deployment_uuid)->first();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
namespace App\Providers;
|
namespace App\Providers;
|
||||||
|
|
||||||
|
use App\Jobs\CoolifyTask;
|
||||||
use Illuminate\Queue\Events\JobProcessed;
|
use Illuminate\Queue\Events\JobProcessed;
|
||||||
use Illuminate\Support\Facades\Process;
|
use Illuminate\Support\Facades\Process;
|
||||||
use Illuminate\Support\Facades\Queue;
|
use Illuminate\Support\Facades\Queue;
|
||||||
@@ -31,7 +32,7 @@ class AppServiceProvider extends ServiceProvider
|
|||||||
{
|
{
|
||||||
Queue::after(function (JobProcessed $event) {
|
Queue::after(function (JobProcessed $event) {
|
||||||
// @TODO: Remove `coolify-builder` container after the remoteProcess job is finishged and remoteProcess->type == `deployment`.
|
// @TODO: Remove `coolify-builder` container after the remoteProcess job is finishged and remoteProcess->type == `deployment`.
|
||||||
if ($event->job->resolveName() === 'App\Jobs\ExecuteRemoteProcess') {
|
if ($event->job->resolveName() === CoolifyTask::class) {
|
||||||
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -1,8 +1,7 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
use App\Actions\RemoteProcess\DispatchRemoteProcess;
|
use App\Actions\CoolifyTask\PrepareCoolifyTask;
|
||||||
use App\Data\RemoteProcessArgs;
|
use App\Data\CoolifyTaskArgs;
|
||||||
use App\Enums\ActivityTypes;
|
|
||||||
use App\Models\Server;
|
use App\Models\Server;
|
||||||
use Illuminate\Database\Eloquent\Model;
|
use Illuminate\Database\Eloquent\Model;
|
||||||
use Illuminate\Support\Collection;
|
use Illuminate\Support\Collection;
|
||||||
@@ -21,7 +20,8 @@ if (!function_exists('remoteProcess')) {
|
|||||||
function remoteProcess(
|
function remoteProcess(
|
||||||
array $command,
|
array $command,
|
||||||
Server $server,
|
Server $server,
|
||||||
?string $deployment_uuid = null,
|
string $type,
|
||||||
|
?string $type_uuid = null,
|
||||||
?Model $model = null,
|
?Model $model = null,
|
||||||
): Activity {
|
): Activity {
|
||||||
|
|
||||||
@@ -32,17 +32,17 @@ if (!function_exists('remoteProcess')) {
|
|||||||
|
|
||||||
$private_key_location = savePrivateKeyForServer($server);
|
$private_key_location = savePrivateKeyForServer($server);
|
||||||
|
|
||||||
return resolve(DispatchRemoteProcess::class, [
|
return resolve(PrepareCoolifyTask::class, [
|
||||||
'remoteProcessArgs' => new RemoteProcessArgs(
|
'remoteProcessArgs' => new CoolifyTaskArgs(
|
||||||
server_ip: $server->ip,
|
server_ip: $server->ip,
|
||||||
private_key_location: $private_key_location,
|
private_key_location: $private_key_location,
|
||||||
deployment_uuid: $deployment_uuid,
|
|
||||||
command: <<<EOT
|
command: <<<EOT
|
||||||
{$command_string}
|
{$command_string}
|
||||||
EOT,
|
EOT,
|
||||||
port: $server->port,
|
port: $server->port,
|
||||||
user: $server->user,
|
user: $server->user,
|
||||||
type: $deployment_uuid ? ActivityTypes::DEPLOYMENT->value : ActivityTypes::REMOTE_PROCESS->value,
|
type: $type,
|
||||||
|
type_uuid: $type_uuid,
|
||||||
model: $model,
|
model: $model,
|
||||||
),
|
),
|
||||||
])();
|
])();
|
||||||
@@ -119,8 +119,8 @@ if (!function_exists('formatDockerLabelsToJson')) {
|
|||||||
})[0];
|
})[0];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (!function_exists('runRemoteCommandSync')) {
|
if (!function_exists('instantRemoteProcess')) {
|
||||||
function runRemoteCommandSync(Server $server, array $command, $throwError = true)
|
function instantRemoteProcess(Server $server, array $command, $throwError = true)
|
||||||
{
|
{
|
||||||
$command_string = implode("\n", $command);
|
$command_string = implode("\n", $command);
|
||||||
$private_key_location = savePrivateKeyForServer($server);
|
$private_key_location = savePrivateKeyForServer($server);
|
||||||
|
|||||||
@@ -18,7 +18,7 @@
|
|||||||
|
|
||||||
@if (data_get($application, 'ports_mappings_array'))
|
@if (data_get($application, 'ports_mappings_array'))
|
||||||
@foreach ($application->ports_mappings_array as $port)
|
@foreach ($application->ports_mappings_array as $port)
|
||||||
@if (env('APP_ENV') === 'local')
|
@if (config('app.env') === 'local')
|
||||||
<a target="_blank" href="http://localhost:{{ explode(':', $port)[0] }}">Open
|
<a target="_blank" href="http://localhost:{{ explode(':', $port)[0] }}">Open
|
||||||
{{ explode(':', $port)[0] }}</a>
|
{{ explode(':', $port)[0] }}</a>
|
||||||
@else
|
@else
|
||||||
|
|||||||
@@ -1,3 +1,6 @@
|
|||||||
<div>
|
<div>
|
||||||
<pre style="width: 100%;overflow-y: scroll;" @if ($isKeepAliveOn) wire:poll.750ms="polling" @endif>{{ \App\Actions\RemoteProcess\RunRemoteProcess::decodeOutput($activity) }}</pre>
|
<pre
|
||||||
|
style="width: 100%;overflow-y: scroll;"
|
||||||
|
@if ($isKeepAliveOn) wire:poll.750ms="polling" @endif
|
||||||
|
>{{ \App\Actions\CoolifyTask\RunRemoteProcess::decodeOutput($activity) }}</pre>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -21,6 +21,9 @@
|
|||||||
@endif
|
@endif
|
||||||
</div>
|
</div>
|
||||||
@isset($activity?->id)
|
@isset($activity?->id)
|
||||||
<pre style="width: 100%;overflow-y: scroll;" @if ($isKeepAliveOn || $manualKeepAlive) wire:poll.750ms="polling" @endif>{{ data_get($activity, 'description') }}</pre>
|
<pre
|
||||||
|
style="width: 100%;overflow-y: scroll;"
|
||||||
|
@if ($isKeepAliveOn) wire:poll.750ms="polling" @endif
|
||||||
|
>{{ \App\Actions\CoolifyTask\RunRemoteProcess::decodeOutput($activity) }}</pre>
|
||||||
@endisset
|
@endisset
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -3,7 +3,7 @@
|
|||||||
<x-applications.navbar :applicationId="$application->id" />
|
<x-applications.navbar :applicationId="$application->id" />
|
||||||
<div class="pt-2">
|
<div class="pt-2">
|
||||||
@forelse ($deployments as $deployment)
|
@forelse ($deployments as $deployment)
|
||||||
<livewire:project.application.get-deployments :deployment_uuid="data_get($deployment->properties, 'deployment_uuid')" :created_at="data_get($deployment, 'created_at')" :status="data_get($deployment->properties, 'status')" />
|
<livewire:project.application.get-deployments :deployment_uuid="data_get($deployment->properties, 'type_uuid')" :created_at="data_get($deployment, 'created_at')" :status="data_get($deployment->properties, 'status')" />
|
||||||
@empty
|
@empty
|
||||||
<p>No deployments found.</p>
|
<p>No deployments found.</p>
|
||||||
@endforelse
|
@endforelse
|
||||||
|
|||||||
@@ -48,6 +48,12 @@ function vite {
|
|||||||
function build-builder {
|
function build-builder {
|
||||||
act -W .github/workflows/coolify-builder.yml --secret-file .env.secrets
|
act -W .github/workflows/coolify-builder.yml --secret-file .env.secrets
|
||||||
}
|
}
|
||||||
|
function tinker {
|
||||||
|
bash vendor/bin/spin exec -u webuser coolify php artisan tinker
|
||||||
|
}
|
||||||
|
function db {
|
||||||
|
bash vendor/bin/spin exec -u webuser coolify php artisan db
|
||||||
|
}
|
||||||
function default {
|
function default {
|
||||||
help
|
help
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
use App\Actions\RemoteProcess\RunRemoteProcess;
|
use App\Actions\CoolifyTask\RunRemoteProcess;
|
||||||
use App\Actions\RemoteProcess\TidyOutput;
|
use App\Actions\CoolifyTask\TidyOutput;
|
||||||
use App\Models\User;
|
use App\Models\User;
|
||||||
use App\Models\Server;
|
use App\Models\Server;
|
||||||
use Database\Seeders\DatabaseSeeder;
|
use Database\Seeders\DatabaseSeeder;
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
use App\Actions\RemoteProcess\RunRemoteProcess;
|
use App\Actions\CoolifyTask\RunRemoteProcess;
|
||||||
use App\Models\Server;
|
use App\Models\Server;
|
||||||
use Database\Seeders\DatabaseSeeder;
|
use Database\Seeders\DatabaseSeeder;
|
||||||
use Illuminate\Foundation\Testing\DatabaseMigrations;
|
use Illuminate\Foundation\Testing\DatabaseMigrations;
|
||||||
|
|||||||
Reference in New Issue
Block a user