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.
PHP coolifydatabasesdeploymentdockerdocker-composeinertiajslaravelmariadbmysqlnextjsnodejsphppostgresredisself-hostedself-hostingserverstatic-sitesveltesvelte5
Add support for Dockerfile target build
Andras Bacsaia7f9fad6270c
diff --git a/app/Http/Livewire/Project/Application/General.php b/app/Http/Livewire/Project/Application/General.phpindex 703c85b927..bc853108fb 100644--- a/app/Http/Livewire/Project/Application/General.php+++ b/app/Http/Livewire/Project/Application/General.php@@ -55,6 +55,7 @@ class General extends Component'application.docker_registry_image_tag' => 'nullable','application.dockerfile_location' => 'nullable','application.custom_labels' => 'nullable',+ 'application.dockerfile_target_build' => 'nullable',];protected $validationAttributes = ['application.name' => 'name',@@ -77,6 +78,7 @@ class General extends Component'application.docker_registry_image_tag' => 'Docker registry image tag','application.dockerfile_location' => 'Dockerfile location','application.custom_labels' => 'Custom labels',+ 'application.dockerfile_target_build' => 'Dockerfile target build',];public function mount()diff --git a/app/Jobs/ApplicationDeploymentJob.php b/app/Jobs/ApplicationDeploymentJob.phpindex 4ffc1f6b6d..d913347454 100644--- a/app/Jobs/ApplicationDeploymentJob.php+++ b/app/Jobs/ApplicationDeploymentJob.php@@ -69,6 +69,7 @@ class ApplicationDeploymentJob implements ShouldQueue, ShouldBeEncryptedprivate $docker_compose_base64;private string $dockerfile_location = '/Dockerfile';private ?string $addHosts = null;+ private ?string $buildTarget = null;private $log_model;private Collection $saved_outputs;@@ -178,6 +179,10 @@ class ApplicationDeploymentJob implements ShouldQueue, ShouldBeEncryptedreturn "--add-host $name:$ip";})->implode(' ');+ if ($this->application->dockerfile_target_build) {+ $this->buildTarget = " --target {$this->application->dockerfile_target_build} ";+ }+// Get user home directory$this->serverUserHomeDir = instant_remote_process(["echo \$HOME"], $this->server);$this->dockerConfigFileExists = instant_remote_process(["test -f {$this->serverUserHomeDir}/.docker/config.json && echo 'OK' || echo 'NOK'"], $this->server);@@ -921,7 +926,7 @@ class ApplicationDeploymentJob implements ShouldQueue, ShouldBeEncryptedif ($this->application->settings->is_static) {$this->execute_remote_command([- executeInDocker($this->deployment_uuid, "docker build $this->addHosts --network host -f {$this->workdir}/{$this->dockerfile_location} {$this->build_args} --progress plain -t $this->build_image_name {$this->workdir}"), "hidden" => true+ executeInDocker($this->deployment_uuid, "docker build $this->buildTarget $this->addHosts --network host -f {$this->workdir}/{$this->dockerfile_location} {$this->build_args} --progress plain -t $this->build_image_name {$this->workdir}"), "hidden" => true]);$dockerfile = base64_encode("FROM {$this->application->static_image}@@ -959,7 +964,7 @@ COPY ./nginx.conf /etc/nginx/conf.d/default.conf"););} else {$this->execute_remote_command([- executeInDocker($this->deployment_uuid, "docker build $this->addHosts --network host -f {$this->workdir}{$this->dockerfile_location} {$this->build_args} --progress plain -t $this->production_image_name {$this->workdir}"), "hidden" => true+ executeInDocker($this->deployment_uuid, "docker build $this->buildTarget $this->addHosts --network host -f {$this->workdir}{$this->dockerfile_location} {$this->build_args} --progress plain -t $this->production_image_name {$this->workdir}"), "hidden" => true]);}}diff --git a/database/migrations/2023_11_07_123731_add_target_build_dockerfile.php b/database/migrations/2023_11_07_123731_add_target_build_dockerfile.phpnew file mode 100644index 0000000000..26f43e9252--- /dev/null+++ b/database/migrations/2023_11_07_123731_add_target_build_dockerfile.php@@ -0,0 +1,28 @@+<?php++use Illuminate\Database\Migrations\Migration;+use Illuminate\Database\Schema\Blueprint;+use Illuminate\Support\Facades\Schema;++return new class extends Migration+{+ /**+ * Run the migrations.+ */+ public function up(): void+ {+ Schema::table('applications', function (Blueprint $table) {+ $table->string('dockerfile_target_build')->nullable();+ });+ }++ /**+ * Reverse the migrations.+ */+ public function down(): void+ {+ Schema::table('applications', function (Blueprint $table) {+ $table->dropColumn('dockerfile_target_build');+ });+ }+};diff --git a/resources/views/livewire/project/application/general.blade.php b/resources/views/livewire/project/application/general.blade.phpindex a5440aa036..475763e41e 100644--- a/resources/views/livewire/project/application/general.blade.php+++ b/resources/views/livewire/project/application/general.blade.php@@ -72,6 +72,7 @@<x-forms.input placeholder="/Dockerfile" id="application.dockerfile_location"label="Dockerfile Location"helper="It is calculated together with the Base Directory: {{ Str::start($application->base_directory . $application->dockerfile_location, '/') }}" />+ <x-forms.input id="application.dockerfile_target_build" label="Docker Build Stage Target" helper="Useful if you have multi-staged dockerfile." />@endif@if ($application->could_set_build_commands())@if ($application->settings->is_static)