Skip to content

An open-source, self-hostable PaaS alternative to Vercel, Heroku & Netlify that lets you easily deploy static sites, databases, full-stack applications and 360+ one-click services on your own servers.

fix: volumes for prs

Andras Bacsai42715bba5018
diff --git a/app/Jobs/ApplicationDeploymentJob.php b/app/Jobs/ApplicationDeploymentJob.php
index 1346a6deda..98c1892757 100644
--- a/app/Jobs/ApplicationDeploymentJob.php
+++ b/app/Jobs/ApplicationDeploymentJob.php
@@ -298,6 +298,8 @@ class ApplicationDeploymentJob implements ShouldQueue, ShouldBeEncrypted
"ignore_errors" => true,
]
);
+
+
// $this->execute_remote_command(
// [
// "docker image prune -f >/dev/null 2>&1",
@@ -305,6 +307,8 @@ class ApplicationDeploymentJob implements ShouldQueue, ShouldBeEncrypted
// "ignore_errors" => true,
// ]
// );
+
+
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
]);
}
- $this->write_deployment_configurations();
// Start compose file
if ($this->application->settings->is_raw_compose_deployment_enabled) {
@@ -425,7 +428,9 @@ class ApplicationDeploymentJob implements ShouldQueue, ShouldBeEncrypted
$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 @@ class ApplicationDeploymentJob implements ShouldQueue, ShouldBeEncrypted
$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 @@ class ApplicationDeploymentJob implements ShouldQueue, ShouldBeEncrypted
}
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;
}
diff --git a/bootstrap/helpers/shared.php b/bootstrap/helpers/shared.php
index c9f98e48a1..7810e01555 100644
--- a/bootstrap/helpers/shared.php
+++ b/bootstrap/helpers/shared.php
@@ -1240,84 +1240,95 @@ 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,
- ]);
+ if (count($serviceVolumes) > 0) {
+ $serviceVolumes = $serviceVolumes->map(function ($volume) use ($resource, $topLevelVolumes, $pull_request_id) {
+ if (is_string($volume)) {
+ $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);
}
- }
- }
- return $volume->value();
- });
- data_set($service, 'volumes', $serviceVolumes->toArray());
- }
- } else {
- if (count($serviceVolumes) > 0) {
- $serviceVolumes = $serviceVolumes->map(function ($volume) use ($resource, $topLevelVolumes) {
- if (is_string($volume)) {
- $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);
- }
+ 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 (is_array($volume)) {
- $source = data_get($volume, 'source');
- if ($source) {
- if ((str($source)->startsWith('.') || str($source)->startsWith('~')) && !str($source)->startsWith('/')) {
- $dir = base_configuration_dir() . '/applications/' . $resource->uuid;
- if (str($source, '.')) {
- $source = str('.', $dir, $source);
- }
- if (str($source, '~')) {
- $source = str('~', $dir, $source);
- }
- data_set($volume, 'source', $source);
+ } 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');
+ $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 {
+ 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);
+ data_set($volume, 'source', $source . ':' . $target);
+ }
+ if (!str($source)->startsWith('/')) {
$topLevelVolumes->put($source, [
'name' => $source,
]);
}
}
}
- return $volume->value();
- });
- data_set($service, 'volumes', $serviceVolumes->toArray());
- }
+ }
+ 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(),