fix: live event
This commit is contained in:
parent
828fec9448
commit
a249ee1b1f
@ -21,7 +21,7 @@ class StartService
|
|||||||
$commands[] = "echo 'Pulling images.'";
|
$commands[] = "echo 'Pulling images.'";
|
||||||
$commands[] = "docker compose pull";
|
$commands[] = "docker compose pull";
|
||||||
$commands[] = "echo 'Starting containers.'";
|
$commands[] = "echo 'Starting containers.'";
|
||||||
$commands[] = "docker compose up -d --remove-orphans --force-recreate --build";
|
$commands[] = "docker compose up --wait --remove-orphans --force-recreate --build";
|
||||||
$commands[] = "docker network connect $service->uuid coolify-proxy >/dev/null 2>&1 || true";
|
$commands[] = "docker network connect $service->uuid coolify-proxy >/dev/null 2>&1 || true";
|
||||||
$compose = data_get($service, 'docker_compose', []);
|
$compose = data_get($service, 'docker_compose', []);
|
||||||
$serviceNames = data_get(Yaml::parse($compose), 'services', []);
|
$serviceNames = data_get(Yaml::parse($compose), 'services', []);
|
||||||
|
@ -8,7 +8,7 @@ use Spatie\Activitylog\Models\Activity;
|
|||||||
|
|
||||||
class ActivityMonitor extends Component
|
class ActivityMonitor extends Component
|
||||||
{
|
{
|
||||||
public string|null $header = null;
|
public ?string $header = null;
|
||||||
public $activityId;
|
public $activityId;
|
||||||
public $isPollingActive = false;
|
public $isPollingActive = false;
|
||||||
|
|
||||||
@ -26,31 +26,30 @@ class ActivityMonitor extends Component
|
|||||||
|
|
||||||
public function hydrateActivity()
|
public function hydrateActivity()
|
||||||
{
|
{
|
||||||
$this->activity = Activity::query()
|
$this->activity = Activity::find($this->activityId);
|
||||||
->find($this->activityId);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function polling()
|
public function polling()
|
||||||
{
|
{
|
||||||
$this->hydrateActivity();
|
$this->hydrateActivity();
|
||||||
$this->setStatus(ProcessStatus::IN_PROGRESS);
|
// $this->setStatus(ProcessStatus::IN_PROGRESS);
|
||||||
$exit_code = data_get($this->activity, 'properties.exitCode');
|
$exit_code = data_get($this->activity, 'properties.exitCode');
|
||||||
if ($exit_code !== null) {
|
if ($exit_code !== null) {
|
||||||
if ($exit_code === 0) {
|
if ($exit_code === 0) {
|
||||||
$this->setStatus(ProcessStatus::FINISHED);
|
// $this->setStatus(ProcessStatus::FINISHED);
|
||||||
} else {
|
} else {
|
||||||
$this->setStatus(ProcessStatus::ERROR);
|
// $this->setStatus(ProcessStatus::ERROR);
|
||||||
}
|
}
|
||||||
$this->isPollingActive = false;
|
$this->isPollingActive = false;
|
||||||
$this->dispatch('activityFinished');
|
$this->dispatch('activityFinished');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function setStatus($status)
|
// protected function setStatus($status)
|
||||||
{
|
// {
|
||||||
$this->activity->properties = $this->activity->properties->merge([
|
// $this->activity->properties = $this->activity->properties->merge([
|
||||||
'status' => $status,
|
// 'status' => $status,
|
||||||
]);
|
// ]);
|
||||||
$this->activity->save();
|
// $this->activity->save();
|
||||||
}
|
// }
|
||||||
}
|
}
|
||||||
|
@ -38,6 +38,7 @@ class Index extends Component
|
|||||||
{
|
{
|
||||||
dispatch_sync(new ContainerStatusJob($this->service->server));
|
dispatch_sync(new ContainerStatusJob($this->service->server));
|
||||||
$this->refreshStacks();
|
$this->refreshStacks();
|
||||||
|
$this->dispatch('serviceStatusChanged');
|
||||||
}
|
}
|
||||||
public function refreshStacks()
|
public function refreshStacks()
|
||||||
{
|
{
|
||||||
|
@ -29,9 +29,8 @@ class Navbar extends Component
|
|||||||
}
|
}
|
||||||
public function getListeners()
|
public function getListeners()
|
||||||
{
|
{
|
||||||
$userId = auth()->user()->id;
|
|
||||||
return [
|
return [
|
||||||
"echo-private:custom.{$userId},ServiceStatusChanged" => 'serviceStatusChanged',
|
"serviceStatusChanged"
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
public function serviceStatusChanged()
|
public function serviceStatusChanged()
|
||||||
|
@ -10,6 +10,7 @@ use App\Models\StandaloneMongodb;
|
|||||||
use App\Models\StandaloneMysql;
|
use App\Models\StandaloneMysql;
|
||||||
use App\Models\StandalonePostgresql;
|
use App\Models\StandalonePostgresql;
|
||||||
use App\Models\StandaloneRedis;
|
use App\Models\StandaloneRedis;
|
||||||
|
use Illuminate\Support\Sleep;
|
||||||
use Livewire\Component;
|
use Livewire\Component;
|
||||||
|
|
||||||
class ExecuteContainerCommand extends Component
|
class ExecuteContainerCommand extends Component
|
||||||
@ -23,7 +24,16 @@ class ExecuteContainerCommand extends Component
|
|||||||
public string $workDir = '';
|
public string $workDir = '';
|
||||||
public Server $server;
|
public Server $server;
|
||||||
public $servers = [];
|
public $servers = [];
|
||||||
|
public function getListeners()
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
"serviceStatusChanged",
|
||||||
|
];
|
||||||
|
}
|
||||||
|
public function serviceStatusChanged()
|
||||||
|
{
|
||||||
|
$this->getContainers();
|
||||||
|
}
|
||||||
protected $rules = [
|
protected $rules = [
|
||||||
'server' => 'required',
|
'server' => 'required',
|
||||||
'container' => 'required',
|
'container' => 'required',
|
||||||
@ -33,8 +43,12 @@ class ExecuteContainerCommand extends Component
|
|||||||
|
|
||||||
public function mount()
|
public function mount()
|
||||||
{
|
{
|
||||||
$this->containers = collect();
|
|
||||||
$this->parameters = get_route_parameters();
|
$this->parameters = get_route_parameters();
|
||||||
|
$this->getContainers();
|
||||||
|
}
|
||||||
|
public function getContainers()
|
||||||
|
{
|
||||||
|
$this->containers = collect();
|
||||||
if (data_get($this->parameters, 'application_uuid')) {
|
if (data_get($this->parameters, 'application_uuid')) {
|
||||||
$this->type = 'application';
|
$this->type = 'application';
|
||||||
$this->resource = Application::where('uuid', $this->parameters['application_uuid'])->firstOrFail();
|
$this->resource = Application::where('uuid', $this->parameters['application_uuid'])->firstOrFail();
|
||||||
@ -92,10 +106,12 @@ class ExecuteContainerCommand extends Component
|
|||||||
{
|
{
|
||||||
$this->validate();
|
$this->validate();
|
||||||
try {
|
try {
|
||||||
|
// Wrap command to prevent escaped execution in the host.
|
||||||
|
$cmd = 'sh -c "' . str_replace('"', '\"', $this->command) . '"';
|
||||||
if (!empty($this->workDir)) {
|
if (!empty($this->workDir)) {
|
||||||
$exec = "docker exec -w {$this->workDir} {$this->container} {$this->command}";
|
$exec = "docker exec -w {$this->workDir} {$this->container} {$cmd}";
|
||||||
} else {
|
} else {
|
||||||
$exec = "docker exec {$this->container} {$this->command}";
|
$exec = "docker exec {$this->container} {$cmd}";
|
||||||
}
|
}
|
||||||
$activity = remote_process([$exec], $this->server, ignore_errors: true);
|
$activity = remote_process([$exec], $this->server, ignore_errors: true);
|
||||||
$this->dispatch('newMonitorActivity', $activity->id);
|
$this->dispatch('newMonitorActivity', $activity->id);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user