fix: volumes for prs
This commit is contained in:
parent
0aacad655d
commit
42715bba50
@ -298,6 +298,8 @@ public function handle(): void
|
||||
"ignore_errors" => true,
|
||||
]
|
||||
);
|
||||
|
||||
|
||||
// $this->execute_remote_command(
|
||||
// [
|
||||
// "docker image prune -f >/dev/null 2>&1",
|
||||
@ -305,6 +307,8 @@ public function handle(): void
|
||||
// "ignore_errors" => true,
|
||||
// ]
|
||||
// );
|
||||
|
||||
|
||||
ApplicationStatusChanged::dispatch(data_get($this->application, 'environment.project.team.id'));
|
||||
}
|
||||
}
|
||||
@ -417,7 +421,6 @@ private function deploy_docker_compose_buildpack()
|
||||
"docker network connect {$networkId} coolify-proxy || true", "hidden" => true, "ignore_errors" => true
|
||||
]);
|
||||
}
|
||||
$this->write_deployment_configurations();
|
||||
|
||||
// Start compose file
|
||||
if ($this->application->settings->is_raw_compose_deployment_enabled) {
|
||||
@ -425,7 +428,9 @@ private function deploy_docker_compose_buildpack()
|
||||
$this->execute_remote_command(
|
||||
[executeInDocker($this->deployment_uuid, "cd {$this->workdir} && {$this->docker_compose_custom_start_command}"), "hidden" => true],
|
||||
);
|
||||
$this->write_deployment_configurations();
|
||||
} else {
|
||||
$this->write_deployment_configurations();
|
||||
$server_workdir = $this->application->workdir();
|
||||
ray("SOURCE_COMMIT={$this->commit} docker compose --project-directory {$server_workdir} -f {$server_workdir}{$this->docker_compose_location} up -d");
|
||||
$this->execute_remote_command(
|
||||
@ -437,14 +442,15 @@ private function deploy_docker_compose_buildpack()
|
||||
$this->execute_remote_command(
|
||||
[executeInDocker($this->deployment_uuid, "cd {$this->basedir} && {$this->docker_compose_custom_start_command}"), "hidden" => true],
|
||||
);
|
||||
$this->write_deployment_configurations();
|
||||
} else {
|
||||
$this->execute_remote_command(
|
||||
[executeInDocker($this->deployment_uuid, "SOURCE_COMMIT={$this->commit} docker compose --project-directory {$this->workdir} -f {$this->workdir}{$this->docker_compose_location} up -d"), "hidden" => true],
|
||||
);
|
||||
$this->write_deployment_configurations();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
$this->application_deployment_queue->addLogEntry("New container started.");
|
||||
}
|
||||
private function deploy_dockerfile_buildpack()
|
||||
@ -822,6 +828,10 @@ private function health_check()
|
||||
}
|
||||
private function deploy_pull_request()
|
||||
{
|
||||
if ($this->application->build_pack === 'dockercompose') {
|
||||
$this->deploy_docker_compose_buildpack();
|
||||
return;
|
||||
}
|
||||
if ($this->use_build_server) {
|
||||
$this->server = $this->build_server;
|
||||
}
|
||||
|
@ -1240,39 +1240,8 @@ function parseDockerComposeFile(Service|Application $resource, bool $isNew = fal
|
||||
}
|
||||
$baseName = generateApplicationContainerName($resource, $pull_request_id);
|
||||
$containerName = "$serviceName-$baseName";
|
||||
if ($pull_request_id !== 0) {
|
||||
if (count($serviceVolumes) > 0) {
|
||||
$serviceVolumes = $serviceVolumes->map(function ($volume) use ($resource, $pull_request_id, $topLevelVolumes) {
|
||||
if (is_string($volume)) {
|
||||
$volume = str($volume);
|
||||
if ($volume->contains(':') && !$volume->startsWith('/')) {
|
||||
$name = $volume->before(':');
|
||||
$mount = $volume->after(':');
|
||||
$newName = $resource->uuid . "-{$name}-pr-$pull_request_id";
|
||||
$volume = str("$newName:$mount");
|
||||
$topLevelVolumes->put($newName, [
|
||||
'name' => $newName,
|
||||
]);
|
||||
}
|
||||
} else if (is_array($volume)) {
|
||||
$source = data_get($volume, 'source');
|
||||
if ($source) {
|
||||
$newSource = $resource->uuid . "-{$source}-pr-$pull_request_id";
|
||||
data_set($volume, 'source', $newSource);
|
||||
if (!str($source)->startsWith('/')) {
|
||||
$topLevelVolumes->put($newSource, [
|
||||
'name' => $newSource,
|
||||
]);
|
||||
}
|
||||
}
|
||||
}
|
||||
return $volume->value();
|
||||
});
|
||||
data_set($service, 'volumes', $serviceVolumes->toArray());
|
||||
}
|
||||
} else {
|
||||
if (count($serviceVolumes) > 0) {
|
||||
$serviceVolumes = $serviceVolumes->map(function ($volume) use ($resource, $topLevelVolumes) {
|
||||
$serviceVolumes = $serviceVolumes->map(function ($volume) use ($resource, $topLevelVolumes, $pull_request_id) {
|
||||
if (is_string($volume)) {
|
||||
$volume = str($volume);
|
||||
if ($volume->contains(':') && !$volume->startsWith('/')) {
|
||||
@ -1286,38 +1255,80 @@ function parseDockerComposeFile(Service|Application $resource, bool $isNew = fal
|
||||
if ($name->startsWith('~')) {
|
||||
$name = $name->replaceFirst('~', $dir);
|
||||
}
|
||||
if ($pull_request_id !== 0) {
|
||||
$name = $name . "-pr-$pull_request_id";
|
||||
}
|
||||
$volume = str("$name:$mount");
|
||||
} else {
|
||||
if ($pull_request_id !== 0) {
|
||||
$name = $name . "-pr-$pull_request_id";
|
||||
$volume = str("$name:$mount");
|
||||
$topLevelVolumes->put($name, [
|
||||
'name' => $name,
|
||||
]);
|
||||
} else {
|
||||
$topLevelVolumes->put($name->value(), [
|
||||
'name' => $name->value(),
|
||||
]);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if ($volume->startsWith('/')) {
|
||||
$name = $volume->before(':');
|
||||
$mount = $volume->after(':');
|
||||
if ($pull_request_id !== 0) {
|
||||
$name = $name . "-pr-$pull_request_id";
|
||||
}
|
||||
$volume = str("$name:$mount");
|
||||
}
|
||||
}
|
||||
|
||||
} else if (is_array($volume)) {
|
||||
$source = data_get($volume, 'source');
|
||||
if ($source) {
|
||||
if ((str($source)->startsWith('.') || str($source)->startsWith('~')) && !str($source)->startsWith('/')) {
|
||||
$target = data_get($volume, 'target');
|
||||
$read_only = data_get($volume, 'read_only');
|
||||
if ($source && $target) {
|
||||
if ((str($source)->startsWith('.') || str($source)->startsWith('~'))) {
|
||||
$dir = base_configuration_dir() . '/applications/' . $resource->uuid;
|
||||
if (str($source, '.')) {
|
||||
$source = str('.', $dir, $source);
|
||||
$source = str($source)->replaceFirst('.', $dir);
|
||||
}
|
||||
if (str($source, '~')) {
|
||||
$source = str('~', $dir, $source);
|
||||
$source = str($source)->replaceFirst('~', $dir);
|
||||
}
|
||||
data_set($volume, 'source', $source);
|
||||
if ($pull_request_id !== 0) {
|
||||
$source = $source . "-pr-$pull_request_id";
|
||||
}
|
||||
if ($read_only) {
|
||||
data_set($volume, 'source', $source . ':' . $target . ':ro');
|
||||
} else {
|
||||
data_set($volume, 'source', $source);
|
||||
data_set($volume, 'source', $source . ':' . $target);
|
||||
}
|
||||
} else {
|
||||
if ($pull_request_id !== 0) {
|
||||
$source = $source . "-pr-$pull_request_id";
|
||||
}
|
||||
if ($read_only) {
|
||||
data_set($volume, 'source', $source . ':' . $target . ':ro');
|
||||
} else {
|
||||
data_set($volume, 'source', $source . ':' . $target);
|
||||
}
|
||||
if (!str($source)->startsWith('/')) {
|
||||
$topLevelVolumes->put($source, [
|
||||
'name' => $source,
|
||||
]);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (is_array($volume)) {
|
||||
return data_get($volume, 'source');
|
||||
}
|
||||
return $volume->value();
|
||||
});
|
||||
data_set($service, 'volumes', $serviceVolumes->toArray());
|
||||
}
|
||||
}
|
||||
|
||||
// Decide if the service is a database
|
||||
$isDatabase = isDatabaseImage(data_get_str($service, 'image'));
|
||||
data_set($service, 'is_database', $isDatabase);
|
||||
@ -1602,6 +1613,12 @@ function parseDockerComposeFile(Service|Application $resource, bool $isNew = fal
|
||||
|
||||
return $service;
|
||||
});
|
||||
if ($pull_request_id !== 0) {
|
||||
$services->each(function ($service, $serviceName) use ($pull_request_id, $services) {
|
||||
$services[$serviceName . "-pr-$pull_request_id"] = $service;
|
||||
data_forget($services, $serviceName);
|
||||
});
|
||||
}
|
||||
$finalServices = [
|
||||
'version' => $dockerComposeVersion,
|
||||
'services' => $services->toArray(),
|
||||
|
Loading…
Reference in New Issue
Block a user