2023-10-14 12:22:07 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Actions\Application;
|
|
|
|
|
|
|
|
use App\Models\Application;
|
2024-02-06 14:05:11 +00:00
|
|
|
use App\Models\StandaloneDocker;
|
|
|
|
use App\Notifications\Application\StatusChanged;
|
2023-10-14 12:22:07 +00:00
|
|
|
use Lorisleiva\Actions\Concerns\AsAction;
|
|
|
|
|
|
|
|
class StopApplication
|
|
|
|
{
|
|
|
|
use AsAction;
|
|
|
|
public function handle(Application $application)
|
|
|
|
{
|
2024-02-06 14:05:11 +00:00
|
|
|
if ($application->destination->server->isSwarm()) {
|
|
|
|
instant_remote_process(["docker stack rm {$application->uuid}"], $application->destination->server);
|
|
|
|
return;
|
2024-01-30 08:48:51 +00:00
|
|
|
}
|
2024-02-06 14:05:11 +00:00
|
|
|
|
|
|
|
$servers = collect([]);
|
|
|
|
$servers->push($application->destination->server);
|
|
|
|
$application->additional_networks->map(function ($network) use ($servers) {
|
|
|
|
$servers->push($network->server);
|
|
|
|
});
|
|
|
|
foreach ($servers as $server) {
|
|
|
|
if (!$server->isFunctional()) {
|
|
|
|
return 'Server is not functional';
|
|
|
|
}
|
2023-11-28 17:31:04 +00:00
|
|
|
$containers = getCurrentApplicationContainerStatus($server, $application->id, 0);
|
|
|
|
if ($containers->count() > 0) {
|
|
|
|
foreach ($containers as $container) {
|
|
|
|
$containerName = data_get($container, 'Names');
|
|
|
|
if ($containerName) {
|
|
|
|
instant_remote_process(
|
|
|
|
["docker rm -f {$containerName}"],
|
|
|
|
$server
|
|
|
|
);
|
|
|
|
}
|
2023-10-14 12:22:07 +00:00
|
|
|
}
|
2023-11-28 17:31:04 +00:00
|
|
|
// $application->environment->project->team->notify(new StatusChanged($application));
|
2023-10-14 12:22:07 +00:00
|
|
|
}
|
2023-11-27 14:25:15 +00:00
|
|
|
}
|
|
|
|
|
2024-02-06 14:05:11 +00:00
|
|
|
// // Delete Preview Deployments
|
|
|
|
// $previewDeployments = $application->previews;
|
|
|
|
// foreach ($previewDeployments as $previewDeployment) {
|
|
|
|
// $containers = getCurrentApplicationContainerStatus($server, $application->id, $previewDeployment->pull_request_id);
|
|
|
|
// foreach ($containers as $container) {
|
|
|
|
// $name = str_replace('/', '', $container['Names']);
|
|
|
|
// instant_remote_process(["docker rm -f $name"], $application->destination->server, throwError: false);
|
|
|
|
// }
|
|
|
|
// }
|
2023-10-14 12:22:07 +00:00
|
|
|
}
|
|
|
|
}
|