feat: adding new COOLIFY_ variables
This commit is contained in:
parent
e341121f61
commit
b992b19c66
@ -107,6 +107,8 @@ class ApplicationDeploymentJob implements ShouldQueue, ShouldBeEncrypted
|
|||||||
private ?string $fullRepoUrl = null;
|
private ?string $fullRepoUrl = null;
|
||||||
private ?string $branch = null;
|
private ?string $branch = null;
|
||||||
|
|
||||||
|
private ?string $coolify_variables = null;
|
||||||
|
|
||||||
public $tries = 1;
|
public $tries = 1;
|
||||||
public function __construct(int $application_deployment_queue_id)
|
public function __construct(int $application_deployment_queue_id)
|
||||||
{
|
{
|
||||||
@ -406,7 +408,7 @@ class ApplicationDeploymentJob implements ShouldQueue, ShouldBeEncrypted
|
|||||||
);
|
);
|
||||||
} 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} build"), "hidden" => true],
|
[executeInDocker($this->deployment_uuid, "{$this->coolify_variables} docker compose --project-directory {$this->workdir} -f {$this->workdir}{$this->docker_compose_location} build"), "hidden" => true],
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -436,9 +438,9 @@ class ApplicationDeploymentJob implements ShouldQueue, ShouldBeEncrypted
|
|||||||
} else {
|
} else {
|
||||||
$this->write_deployment_configurations();
|
$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("{$this->coolify_variables} docker compose --project-directory {$server_workdir} -f {$server_workdir}{$this->docker_compose_location} up -d");
|
||||||
$this->execute_remote_command(
|
$this->execute_remote_command(
|
||||||
["SOURCE_COMMIT={$this->commit} docker compose --project-directory {$server_workdir} -f {$server_workdir}{$this->docker_compose_location} up -d", "hidden" => true],
|
["{$this->coolify_variables} docker compose --project-directory {$server_workdir} -f {$server_workdir}{$this->docker_compose_location} up -d", "hidden" => true],
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
@ -449,7 +451,7 @@ class ApplicationDeploymentJob implements ShouldQueue, ShouldBeEncrypted
|
|||||||
$this->write_deployment_configurations();
|
$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, "{$this->coolify_variables} docker compose --project-directory {$this->workdir} -f {$this->workdir}{$this->docker_compose_location} up -d"), "hidden" => true],
|
||||||
);
|
);
|
||||||
$this->write_deployment_configurations();
|
$this->write_deployment_configurations();
|
||||||
}
|
}
|
||||||
@ -743,6 +745,16 @@ class ApplicationDeploymentJob implements ShouldQueue, ShouldBeEncrypted
|
|||||||
$envs->push("SOURCE_COMMIT=unknown");
|
$envs->push("SOURCE_COMMIT=unknown");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if ($this->application->environment_variables_preview->where('key', 'COOLIFY_FQDN')->isEmpty()) {
|
||||||
|
$envs->push("COOLIFY_FQDN={$this->preview->fqdn}");
|
||||||
|
}
|
||||||
|
if ($this->application->environment_variables_preview->where('key', 'COOLIFY_URL')->isEmpty()) {
|
||||||
|
$url = str($this->preview->fqdn)->replace('http://', '')->replace('https://', '');
|
||||||
|
$envs->push("COOLIFY_URL={$url}");
|
||||||
|
}
|
||||||
|
if ($this->application->environment_variables_preview->where('key', 'COOLIFY_BRANCH')->isEmpty()) {
|
||||||
|
$envs->push("COOLIFY_BRANCH={$this->application->git_branch}");
|
||||||
|
}
|
||||||
$envs = $envs->sort(function ($a, $b) {
|
$envs = $envs->sort(function ($a, $b) {
|
||||||
return strpos($a, '$') === false ? -1 : 1;
|
return strpos($a, '$') === false ? -1 : 1;
|
||||||
});
|
});
|
||||||
@ -777,6 +789,16 @@ class ApplicationDeploymentJob implements ShouldQueue, ShouldBeEncrypted
|
|||||||
$envs->push("SOURCE_COMMIT=unknown");
|
$envs->push("SOURCE_COMMIT=unknown");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if ($this->application->environment_variables->where('key', 'COOLIFY_FQDN')->isEmpty()) {
|
||||||
|
$envs->push("COOLIFY_FQDN={$this->application->fqdn}");
|
||||||
|
}
|
||||||
|
if ($this->application->environment_variables->where('key', 'COOLIFY_URL')->isEmpty()) {
|
||||||
|
$url = str($this->application->fqdn)->replace('http://', '')->replace('https://', '');
|
||||||
|
$envs->push("COOLIFY_URL={$url}");
|
||||||
|
}
|
||||||
|
if ($this->application->environment_variables_preview->where('key', 'COOLIFY_BRANCH')->isEmpty()) {
|
||||||
|
$envs->push("COOLIFY_BRANCH={$this->application->git_branch}");
|
||||||
|
}
|
||||||
$envs = $envs->sort(function ($a, $b) {
|
$envs = $envs->sort(function ($a, $b) {
|
||||||
return strpos($a, '$') === false ? -1 : 1;
|
return strpos($a, '$') === false ? -1 : 1;
|
||||||
});
|
});
|
||||||
@ -1080,6 +1102,23 @@ class ApplicationDeploymentJob implements ShouldQueue, ShouldBeEncrypted
|
|||||||
{
|
{
|
||||||
$this->application_deployment_queue->addLogEntry("Setting base directory to {$this->workdir}.");
|
$this->application_deployment_queue->addLogEntry("Setting base directory to {$this->workdir}.");
|
||||||
}
|
}
|
||||||
|
private function set_coolify_variables()
|
||||||
|
{
|
||||||
|
$this->coolify_variables = "SOURCE_COMMIT={$this->commit} ";
|
||||||
|
if ($this->pull_request_id === 0) {
|
||||||
|
$fqdn = $this->application->fqdn;
|
||||||
|
} else {
|
||||||
|
$fqdn = $this->preview->fqdn;
|
||||||
|
}
|
||||||
|
if (isset($fqdn)) {
|
||||||
|
$this->coolify_variables .= "COOLIFY_FQDN={$fqdn} ";
|
||||||
|
$url = str($fqdn)->replace('http://', '')->replace('https://', '');
|
||||||
|
$this->coolify_variables .= "COOLIFY_URL={$url} ";
|
||||||
|
}
|
||||||
|
if (isset($this->application->git_branch)) {
|
||||||
|
$this->coolify_variables .= "COOLIFY_BRANCH={$this->application->git_branch} ";
|
||||||
|
}
|
||||||
|
}
|
||||||
private function check_git_if_build_needed()
|
private function check_git_if_build_needed()
|
||||||
{
|
{
|
||||||
$this->generate_git_import_commands();
|
$this->generate_git_import_commands();
|
||||||
@ -1116,6 +1155,7 @@ class ApplicationDeploymentJob implements ShouldQueue, ShouldBeEncrypted
|
|||||||
$this->application_deployment_queue->commit = $this->commit;
|
$this->application_deployment_queue->commit = $this->commit;
|
||||||
$this->application_deployment_queue->save();
|
$this->application_deployment_queue->save();
|
||||||
}
|
}
|
||||||
|
$this->set_coolify_variables();
|
||||||
}
|
}
|
||||||
private function clone_repository()
|
private function clone_repository()
|
||||||
{
|
{
|
||||||
@ -1131,6 +1171,19 @@ class ApplicationDeploymentJob implements ShouldQueue, ShouldBeEncrypted
|
|||||||
]
|
]
|
||||||
);
|
);
|
||||||
$this->create_workdir();
|
$this->create_workdir();
|
||||||
|
$this->execute_remote_command(
|
||||||
|
[
|
||||||
|
executeInDocker($this->deployment_uuid, "cd {$this->workdir} && git log -1 {$this->commit} --pretty=%B"),
|
||||||
|
"hidden" => true,
|
||||||
|
"save" => "commit_message"
|
||||||
|
]
|
||||||
|
);
|
||||||
|
if ($this->saved_outputs->get('commit_message')) {
|
||||||
|
$this->application_deployment_queue->addLogEntry("Commit message: {$this->saved_outputs->get('commit_message')}");
|
||||||
|
$this->application_deployment_queue->commit_message = $this->saved_outputs->get('commit_message');
|
||||||
|
ApplicationDeploymentQueue::whereCommit($this->commit)->whereApplicationId($this->application->id)->update(['commit_message' => $this->saved_outputs->get('commit_message')]);
|
||||||
|
$this->application_deployment_queue->save();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private function generate_git_import_commands()
|
private function generate_git_import_commands()
|
||||||
@ -1769,11 +1822,11 @@ COPY ./nginx.conf /etc/nginx/conf.d/default.conf");
|
|||||||
$this->application_deployment_queue->addLogEntry("Pulling latest images from the registry.");
|
$this->application_deployment_queue->addLogEntry("Pulling latest images from the registry.");
|
||||||
$this->execute_remote_command(
|
$this->execute_remote_command(
|
||||||
[executeInDocker($this->deployment_uuid, "docker compose --project-directory {$this->workdir} pull"), "hidden" => true],
|
[executeInDocker($this->deployment_uuid, "docker compose --project-directory {$this->workdir} pull"), "hidden" => true],
|
||||||
[executeInDocker($this->deployment_uuid, "SOURCE_COMMIT={$this->commit} docker compose --project-directory {$this->workdir} build"), "hidden" => true],
|
[executeInDocker($this->deployment_uuid, "{$this->coolify_variables} docker compose --project-directory {$this->workdir} build"), "hidden" => true],
|
||||||
);
|
);
|
||||||
} 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} build"), "hidden" => true],
|
[executeInDocker($this->deployment_uuid, "{$this->coolify_variables} docker compose --project-directory {$this->workdir} -f {$this->workdir}{$this->docker_compose_location} build"), "hidden" => true],
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
$this->application_deployment_queue->addLogEntry("New images built.");
|
$this->application_deployment_queue->addLogEntry("New images built.");
|
||||||
@ -1785,16 +1838,16 @@ COPY ./nginx.conf /etc/nginx/conf.d/default.conf");
|
|||||||
$this->application_deployment_queue->addLogEntry("Pulling latest images from the registry.");
|
$this->application_deployment_queue->addLogEntry("Pulling latest images from the registry.");
|
||||||
$this->execute_remote_command(
|
$this->execute_remote_command(
|
||||||
[executeInDocker($this->deployment_uuid, "docker compose --project-directory {$this->workdir} pull"), "hidden" => true],
|
[executeInDocker($this->deployment_uuid, "docker compose --project-directory {$this->workdir} pull"), "hidden" => true],
|
||||||
[executeInDocker($this->deployment_uuid, "SOURCE_COMMIT={$this->commit} docker compose --project-directory {$this->workdir} up --build -d"), "hidden" => true],
|
[executeInDocker($this->deployment_uuid, "{$this->coolify_variables} docker compose --project-directory {$this->workdir} up --build -d"), "hidden" => true],
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
if ($this->use_build_server) {
|
if ($this->use_build_server) {
|
||||||
$this->execute_remote_command(
|
$this->execute_remote_command(
|
||||||
["SOURCE_COMMIT={$this->commit} docker compose --project-directory {$this->configuration_dir} -f {$this->configuration_dir}{$this->docker_compose_location} up --build -d", "hidden" => true],
|
["{$this->coolify_variables} docker compose --project-directory {$this->configuration_dir} -f {$this->configuration_dir}{$this->docker_compose_location} up --build -d", "hidden" => true],
|
||||||
);
|
);
|
||||||
} 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 --build -d"), "hidden" => true],
|
[executeInDocker($this->deployment_uuid, "{$this->coolify_variables} docker compose --project-directory {$this->workdir} -f {$this->workdir}{$this->docker_compose_location} up --build -d"), "hidden" => true],
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user