Add pre-deployment and post-deployment commands

This commit is contained in:
Andras Bacsai 2024-03-13 14:41:31 +01:00
parent 62905f084f
commit a53d888747
2 changed files with 26 additions and 24 deletions

View File

@ -240,6 +240,7 @@ public function handle(): void
} }
$this->next(ApplicationDeploymentStatus::FINISHED->value); $this->next(ApplicationDeploymentStatus::FINISHED->value);
$this->application->isConfigurationChanged(false); $this->application->isConfigurationChanged(false);
$this->run_post_deployment_command();
return; return;
} else if ($this->pull_request_id !== 0) { } else if ($this->pull_request_id !== 0) {
$this->deploy_pull_request(); $this->deploy_pull_request();
@ -1700,7 +1701,7 @@ private function run_pre_deployment_command()
if ($containers->count() == 0) { if ($containers->count() == 0) {
return; return;
} }
$this->application_deployment_queue->addLogEntry("Executing pre deployment command: {$this->application->post_deployment_command}"); $this->application_deployment_queue->addLogEntry("Executing pre-deployment command (see debug log for output): {$this->application->pre_deployment_command}");
foreach ($containers as $container) { foreach ($containers as $container) {
$containerName = data_get($container, 'Names'); $containerName = data_get($container, 'Names');
@ -1715,7 +1716,7 @@ private function run_pre_deployment_command()
return; return;
} }
} }
throw new RuntimeException('Pre deployment command: Could not find a valid container. Is the container name correct?'); throw new RuntimeException('Pre-deployment command: Could not find a valid container. Is the container name correct?');
} }
private function run_post_deployment_command() private function run_post_deployment_command()
@ -1723,7 +1724,7 @@ private function run_post_deployment_command()
if (empty($this->application->post_deployment_command)) { if (empty($this->application->post_deployment_command)) {
return; return;
} }
$this->application_deployment_queue->addLogEntry("Executing post deployment command: {$this->application->post_deployment_command}"); $this->application_deployment_queue->addLogEntry("Executing post-deployment command (see debug log for output): {$this->application->post_deployment_command}");
$containers = getCurrentApplicationContainerStatus($this->server, $this->application->id, $this->pull_request_id); $containers = getCurrentApplicationContainerStatus($this->server, $this->application->id, $this->pull_request_id);
foreach ($containers as $container) { foreach ($containers as $container) {
@ -1739,7 +1740,7 @@ private function run_post_deployment_command()
return; return;
} }
} }
throw new RuntimeException('Post deployment command: Could not find a valid container. Is the container name correct?'); throw new RuntimeException('Post-deployment command: Could not find a valid container. Is the container name correct?');
} }
private function next(string $status) private function next(string $status)

View File

@ -251,17 +251,18 @@ class="underline" href="https://coolify.io/docs/docker/registry"
<x-forms.button wire:click="resetDefaultLabels">Reset to Coolify Generated Labels</x-forms.button> <x-forms.button wire:click="resetDefaultLabels">Reset to Coolify Generated Labels</x-forms.button>
@endif @endif
<h3 class="pt-8">Deployment scripts</h3> <h3 class="pt-8">Pre/Post Deployment Commands</h3>
<div class="flex flex-col gap-2 xl:flex-row"> <div class="flex flex-col gap-2 xl:flex-row">
<x-forms.input placeholder="" id="application.pre_deployment_command" label="Pre deployment command" <x-forms.input id="application.pre_deployment_command" label="Pre-deployment Command"
helper="An optional script or command to execute in the existing container before the deployment begins." /> helper="An optional script or command to execute in the existing container before the deployment begins." />
<x-forms.input placeholder="" id="application.pre_deployment_command_container" label="Container name" <x-forms.input id="application.pre_deployment_command_container" label="Container Name"
helper="The name of the container to execute within. You can leave it blank if your application only has one container." /> helper="The name of the container to execute within. You can leave it blank if your application only has one container." />
</div> </div>
<div class="flex flex-col gap-2 xl:flex-row"> <div class="flex flex-col gap-2 xl:flex-row">
<x-forms.input placeholder="php artisan migrate" id="application.post_deployment_command" label="Post deployment command" <x-forms.input placeholder="php artisan migrate" id="application.post_deployment_command"
label="Post-deployment Command"
helper="An optional script or command to execute in the newly built container after the deployment completes." /> helper="An optional script or command to execute in the newly built container after the deployment completes." />
<x-forms.input placeholder="php" id="application.post_deployment_command_container" label="Container name" <x-forms.input id="application.post_deployment_command_container" label="Container Name"
helper="The name of the container to execute within. You can leave it blank if your application only has one container." /> helper="The name of the container to execute within. You can leave it blank if your application only has one container." />
</div> </div>
</div> </div>