mirror of
https://github.com/coollabsio/coolify.git
synced 2026-11-14 08:42:38 -04:00
The compose parser queued ServerFilesFromServerJob for every volume on each parse, and pages that only show data parse the Compose file. Each sync also sent two SSH commands for each file. - Queue the sync only for a compose deployment, and for each service resource with file storages when the service starts or deploys. - Read the compose service names without a parse on the Domains and scheduled task pages. - Check all file storages with one remote command, and stop when a symbolic link, a special file, or an unknown state is at a file path. - Keep the application path in a file storage when a pull request preview is parsed. Preview deployments of the current parser write their `-pr-<id>` copies through LocalFileVolume::forPullRequest(). - Remove the unreachable file sync from the service resource page.
78 lines
3.6 KiB
PHP
78 lines
3.6 KiB
PHP
<?php
|
|
|
|
namespace App\Actions\Service;
|
|
|
|
use App\Actions\Shared\EnsureContentFilesOnServer;
|
|
use App\Models\ServiceApplication;
|
|
use App\Models\ServiceDatabase;
|
|
use Lorisleiva\Actions\Concerns\AsAction;
|
|
use Spatie\Activitylog\Contracts\Activity;
|
|
|
|
class DeployServiceApplication
|
|
{
|
|
use AsAction;
|
|
|
|
public string $jobQueue = 'high';
|
|
|
|
public function handle(ServiceApplication|ServiceDatabase $serviceApplication, bool $pullLatestImages = false, bool $forceRebuild = false): Activity
|
|
{
|
|
$service = $serviceApplication->service;
|
|
$composeServiceName = $serviceApplication->name;
|
|
|
|
$service->parse();
|
|
StartService::queueFileStorageSync($service);
|
|
$service->saveComposeConfigs();
|
|
$service->isConfigurationChanged(save: true);
|
|
|
|
$workdir = $service->workdir();
|
|
$composeFile = "{$workdir}/docker-compose.yml";
|
|
$safeWorkdir = escapeshellarg($workdir);
|
|
$safeComposeFile = escapeshellarg($composeFile);
|
|
$safeProjectName = escapeshellarg($service->uuid);
|
|
$safeComposeServiceName = escapeshellarg($composeServiceName);
|
|
|
|
$commands = collect([
|
|
'echo '.escapeshellarg("Saved configuration files to {$workdir}."),
|
|
'touch '.escapeshellarg("{$workdir}/.env"),
|
|
...EnsureContentFilesOnServer::echoCommands($serviceApplication->fileStorages()->get(), $service->server),
|
|
...StartService::composeVolumeWarningCommands($service),
|
|
]);
|
|
|
|
if ($pullLatestImages) {
|
|
$commands->push('echo Pulling image for service.');
|
|
$commands->push(serverDockerConfigPrefix($service->server)."docker compose --project-directory {$safeWorkdir} -f {$safeComposeFile} --project-name {$safeProjectName} pull {$safeComposeServiceName} < /dev/null");
|
|
}
|
|
|
|
if ($service->networks()->count() > 0) {
|
|
$commands->push('echo Creating Docker network.');
|
|
$commands->push("docker network inspect {$safeProjectName} >/dev/null 2>&1 || docker network create --attachable {$safeProjectName}");
|
|
}
|
|
|
|
$connectToPredefinedNetwork = (bool) data_get($service, 'connect_to_docker_network');
|
|
$upCommand = serverDockerConfigPrefix($service->server)."docker compose --project-directory {$safeWorkdir} -f {$safeComposeFile} --project-name {$safeProjectName} up -d --no-deps";
|
|
if ($forceRebuild) {
|
|
$upCommand .= ' --build';
|
|
}
|
|
if ($connectToPredefinedNetwork) {
|
|
$upCommand .= ' --no-start';
|
|
}
|
|
// No stdin for Compose prompts: they would read the next script lines (see StartService).
|
|
$upCommand .= " {$safeComposeServiceName} < /dev/null";
|
|
$commands->push('echo Starting service container.');
|
|
$commands->push($upCommand);
|
|
|
|
if ($connectToPredefinedNetwork) {
|
|
// Connect to the predefined network before the container starts (see StartService).
|
|
$serviceConfig = data_get(parseDockerComposeYaml($service->docker_compose ?? ''), "services.{$composeServiceName}");
|
|
if ($command = StartService::predefinedNetworkConnectCommand($service, $composeServiceName, $serviceConfig)) {
|
|
$commands->push($command);
|
|
}
|
|
$commands->push('docker start '.escapeshellarg("{$composeServiceName}-{$service->uuid}").' >/dev/null');
|
|
}
|
|
|
|
$commands->push("docker network connect {$safeProjectName} coolify-proxy >/dev/null 2>&1 || true");
|
|
|
|
return remote_process($commands->toArray(), $service->server, type_uuid: $service->uuid, callEventOnFinish: 'ServiceStartFinished', callEventData: $service->id, queue: deployment_queue());
|
|
}
|
|
}
|