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