diff --git a/app/Jobs/ApplicationDeploymentJob.php b/app/Jobs/ApplicationDeploymentJob.php index 652fd2262..d684473ad 100644 --- a/app/Jobs/ApplicationDeploymentJob.php +++ b/app/Jobs/ApplicationDeploymentJob.php @@ -75,6 +75,8 @@ class ApplicationDeploymentJob implements ShouldQueue, ShouldBeEncrypted private $docker_compose_base64; private string $dockerfile_location = '/Dockerfile'; private string $docker_compose_location = '/docker-compose.yml'; + private ?string $docker_compose_custom_start_command = null; + private ?string $docker_compose_custom_build_command = null; private ?string $addHosts = null; private ?string $buildTarget = null; private Collection $saved_outputs; @@ -432,6 +434,12 @@ class ApplicationDeploymentJob implements ShouldQueue, ShouldBeEncrypted if (data_get($this->application, 'docker_compose_location')) { $this->docker_compose_location = $this->application->docker_compose_location; } + if (data_get($this->application, 'docker_compose_custom_start_command')) { + $this->docker_compose_custom_start_command = $this->application->docker_compose_custom_start_command; + } + if (data_get($this->application, 'docker_compose_custom_build_command')) { + $this->docker_compose_custom_build_command = $this->application->docker_compose_custom_build_command; + } if ($this->pull_request_id === 0) { $this->application_deployment_queue->addLogEntry("Starting deployment of {$this->application->name}."); } else { @@ -454,7 +462,18 @@ class ApplicationDeploymentJob implements ShouldQueue, ShouldBeEncrypted ]); $this->save_environment_variables(); // Build new container to limit downtime. - $this->build_by_compose_file(); + $this->application_deployment_queue->addLogEntry("Pulling & building required images."); + + if ($this->docker_compose_custom_build_command) { + $this->execute_remote_command( + [executeInDocker($this->deployment_uuid, "cd {$this->basedir} && {$this->docker_compose_custom_build_command}"), "hidden" => true], + ); + } else { + $this->execute_remote_command( + [executeInDocker($this->deployment_uuid, "docker compose --project-directory {$this->workdir} -f {$this->workdir}{$this->docker_compose_location} build"), "hidden" => true], + ); + } + $this->stop_running_container(force: true); $networkId = $this->application->uuid; @@ -488,7 +507,17 @@ class ApplicationDeploymentJob implements ShouldQueue, ShouldBeEncrypted ] ); } - $this->start_by_compose_file(); + // Start compose file + if ($this->docker_compose_custom_start_command) { + $this->execute_remote_command( + [executeInDocker($this->deployment_uuid, "cd {$this->basedir} && {$this->docker_compose_custom_start_command}"), "hidden" => true], + ); + } else { + $this->execute_remote_command( + [executeInDocker($this->deployment_uuid, "docker compose --project-directory {$this->workdir} -f {$this->workdir}{$this->docker_compose_location} up -d"), "hidden" => true], + ); + } + $this->application_deployment_queue->addLogEntry("New container started."); } private function deploy_dockerfile_buildpack() { @@ -1258,15 +1287,9 @@ COPY ./nginx.conf /etc/nginx/conf.d/default.conf"); [executeInDocker($this->deployment_uuid, "docker compose --project-directory {$this->workdir} build"), "hidden" => true], ); } else { - if ($this->docker_compose_location) { - $this->execute_remote_command( - [executeInDocker($this->deployment_uuid, "docker compose --project-directory {$this->workdir} -f {$this->workdir}{$this->docker_compose_location} build"), "hidden" => true], - ); - } else { - $this->execute_remote_command( - [executeInDocker($this->deployment_uuid, "docker compose --project-directory {$this->workdir} build"), "hidden" => true], - ); - } + $this->execute_remote_command( + [executeInDocker($this->deployment_uuid, "docker compose --project-directory {$this->workdir} -f {$this->workdir}{$this->docker_compose_location} build"), "hidden" => true], + ); } $this->application_deployment_queue->addLogEntry("New images built."); } diff --git a/app/Livewire/Project/Application/General.php b/app/Livewire/Project/Application/General.php index abc091917..996774e0b 100644 --- a/app/Livewire/Project/Application/General.php +++ b/app/Livewire/Project/Application/General.php @@ -64,6 +64,8 @@ class General extends Component 'application.custom_labels' => 'nullable', 'application.dockerfile_target_build' => 'nullable', 'application.settings.is_static' => 'boolean|required', + 'application.docker_compose_custom_start_command' => 'nullable', + 'application.docker_compose_custom_build_command' => 'nullable', ]; protected $validationAttributes = [ 'application.name' => 'name', @@ -94,6 +96,8 @@ class General extends Component 'application.custom_labels' => 'Custom labels', 'application.dockerfile_target_build' => 'Dockerfile target build', 'application.settings.is_static' => 'Is static', + 'application.docker_compose_custom_start_command' => 'Docker compose custom start command', + 'application.docker_compose_custom_build_command' => 'Docker compose custom build command', ]; public function mount() { @@ -195,7 +199,8 @@ class General extends Component public function submit($showToaster = true) { try { - if ($this->application->build_pack === 'dockercompose' && ($this->initialDockerComposeLocation !== $this->application->docker_compose_location || $this->initialDockerComposePrLocation !== $this->application->docker_compose_pr_location)) { + ray($this->initialDockerComposeLocation, $this->application->docker_compose_location); + if ($this->application->build_pack === 'dockercompose' && $this->initialDockerComposeLocation !== $this->application->docker_compose_location) { $this->loadComposeFile(); } $this->validate(); diff --git a/database/migrations/2023_12_17_155616_add_custom_docker_compose_start_command.php b/database/migrations/2023_12_17_155616_add_custom_docker_compose_start_command.php new file mode 100644 index 000000000..e9e1031b8 --- /dev/null +++ b/database/migrations/2023_12_17_155616_add_custom_docker_compose_start_command.php @@ -0,0 +1,33 @@ +string('docker_compose_custom_start_command')->nullable(); + $table->string('docker_compose_custom_build_command')->nullable(); + + + + }); + } + + /** + * Reverse the migrations. + */ + public function down(): void + { + Schema::table('applications', function (Blueprint $table) { + $table->dropColumn('docker_compose_custom_start_command'); + $table->dropColumn('docker_compose_custom_build_command'); + }); + } +}; diff --git a/resources/views/livewire/project/application/general.blade.php b/resources/views/livewire/project/application/general.blade.php index ce4fd10a2..963a30ca4 100644 --- a/resources/views/livewire/project/application/general.blade.php +++ b/resources/views/livewire/project/application/general.blade.php @@ -126,37 +126,57 @@ @endif @endif -