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
init of static deployments
Andras Bacsai3e9e1e94d64f
diff --git a/app/Http/Livewire/Project/Application/General.php b/app/Http/Livewire/Project/Application/General.phpindex e760eb9758..2edfab88dd 100644--- a/app/Http/Livewire/Project/Application/General.php+++ b/app/Http/Livewire/Project/Application/General.php@@ -17,6 +17,7 @@ class General extends Componentpublic string|null $git_commit_sha;public string $build_pack;+ public bool $is_static;public bool $is_git_submodules_allowed;public bool $is_git_lfs_allowed;public bool $is_debug;@@ -34,6 +35,7 @@ class General extends Component'application.git_branch' => 'required','application.git_commit_sha' => 'nullable','application.build_pack' => 'required',+ 'application.static_image' => 'required','application.base_directory' => 'required','application.publish_directory' => 'nullable','application.ports_exposes' => 'required',@@ -42,6 +44,7 @@ class General extends Componentpublic function instantSave(){// @TODO: find another way+ $this->application->settings->is_static = $this->is_static;$this->application->settings->is_git_submodules_allowed = $this->is_git_submodules_allowed;$this->application->settings->is_git_lfs_allowed = $this->is_git_lfs_allowed;$this->application->settings->is_debug = $this->is_debug;@@ -56,6 +59,7 @@ class General extends Componentpublic function mount(){$this->application = Application::where('id', $this->applicationId)->with('destination', 'settings')->firstOrFail();+ $this->is_static = $this->application->settings->is_static;$this->is_git_submodules_allowed = $this->application->settings->is_git_submodules_allowed;$this->is_git_lfs_allowed = $this->application->settings->is_git_lfs_allowed;$this->is_debug = $this->application->settings->is_debug;diff --git a/app/Jobs/DeployApplicationJob.php b/app/Jobs/DeployApplicationJob.phpindex 7f973107aa..511e3b5e83 100644--- a/app/Jobs/DeployApplicationJob.php+++ b/app/Jobs/DeployApplicationJob.php@@ -163,10 +163,26 @@ class DeployApplicationJob implements ShouldQueue"echo -n 'Building image... '",]);- $this->executeNow([- $this->execute_in_builder("docker build -f {$this->workdir}/Dockerfile --build-arg SOURCE_COMMIT={$this->git_commit} --progress plain -t {$this->application->uuid}:{$this->git_commit} {$this->workdir}"),- ], isDebuggable: true);+ if ($this->application->settings->is_static) {+ $this->executeNow([+ $this->execute_in_builder("docker build -f {$this->workdir}/Dockerfile --build-arg SOURCE_COMMIT={$this->git_commit} --progress plain -t {$this->application->uuid}:{$this->git_commit}-build {$this->workdir}"),+ ], isDebuggable: true);++ $dockerfile = "FROM {$this->application->static_image}+WORKDIR /usr/share/nginx/html/+LABEL coolify.deploymentId={$this->deployment_uuid}+COPY --from={$this->application->uuid}:{$this->git_commit}-build /app/{$this->application->publish_directory} .";+ $docker_file = base64_encode($dockerfile);+ $this->executeNow([+ $this->execute_in_builder("echo '{$docker_file}' | base64 -d > {$this->workdir}/Dockerfile-prod"),+ $this->execute_in_builder("docker build -f {$this->workdir}/Dockerfile-prod --build-arg SOURCE_COMMIT={$this->git_commit} --progress plain -t {$this->application->uuid}:{$this->git_commit} {$this->workdir}"),+ ], hideFromOutput: true);+ } else {+ $this->executeNow([+ $this->execute_in_builder("docker build -f {$this->workdir}/Dockerfile --build-arg SOURCE_COMMIT={$this->git_commit} --progress plain -t {$this->application->uuid}:{$this->git_commit} {$this->workdir}"),+ ], isDebuggable: true);+ }$this->executeNow(["echo 'Done.'","echo -n 'Removing old instance... '",@@ -422,21 +438,17 @@ class DeployApplicationJob implements ShouldQueue}private function nixpacks_build_cmd(){- if (str_starts_with($this->application->base_image, 'apache') || str_starts_with($this->application->base_image, 'nginx')) {- // @TODO: Add static site builds- } else {- $nixpacks_command = "nixpacks build -o {$this->workdir} --no-error-without-start";- if ($this->application->install_command) {- $nixpacks_command .= " --install-cmd '{$this->application->install_command}'";- }- if ($this->application->build_command) {- $nixpacks_command .= " --build-cmd '{$this->application->build_command}'";- }- if ($this->application->start_command) {- $nixpacks_command .= " --start-cmd '{$this->application->start_command}'";- }- $nixpacks_command .= " {$this->workdir}";+ $nixpacks_command = "nixpacks build -o {$this->workdir} --no-error-without-start";+ if ($this->application->install_command) {+ $nixpacks_command .= " --install-cmd '{$this->application->install_command}'";+ }+ if ($this->application->build_command) {+ $nixpacks_command .= " --build-cmd '{$this->application->build_command}'";+ }+ if ($this->application->start_command) {+ $nixpacks_command .= " --start-cmd '{$this->application->start_command}'";}+ $nixpacks_command .= " {$this->workdir}";return $this->execute_in_builder($nixpacks_command);}}diff --git a/database/migrations/2023_03_27_081716_create_applications_table.php b/database/migrations/2023_03_27_081716_create_applications_table.phpindex fe3345bb19..b408589d29 100644--- a/database/migrations/2023_03_27_081716_create_applications_table.php+++ b/database/migrations/2023_03_27_081716_create_applications_table.php@@ -27,8 +27,7 @@ return new class extends Migration$table->string('docker_registry_image_tag')->nullable();$table->string('build_pack');- $table->string('base_image')->nullable();- $table->string('build_image')->nullable();+ $table->string('static_image')->default('nginx:alpine');$table->string('install_command')->nullable();$table->string('build_command')->nullable();diff --git a/database/migrations/2023_03_27_081717_create_application_settings_table.php b/database/migrations/2023_03_27_081717_create_application_settings_table.phpindex dbb94446f6..ccb89926e8 100644--- a/database/migrations/2023_03_27_081717_create_application_settings_table.php+++ b/database/migrations/2023_03_27_081717_create_application_settings_table.php@@ -13,6 +13,7 @@ return new class extends Migration{Schema::create('application_settings', function (Blueprint $table) {$table->id();+ $table->boolean('is_static')->default(false);$table->boolean('is_git_submodules_allowed')->default(true);$table->boolean('is_git_lfs_allowed')->default(true);$table->boolean('is_auto_deploy')->default(true);diff --git a/resources/views/livewire/project/application/general.blade.php b/resources/views/livewire/project/application/general.blade.phpindex 9da146dd92..7d5c95ea6b 100644--- a/resources/views/livewire/project/application/general.blade.php+++ b/resources/views/livewire/project/application/general.blade.php@@ -10,6 +10,9 @@<x-form-input id="application.build_command" label="Build Command" /><x-form-input id="application.start_command" label="Start Command" /><x-form-input id="application.build_pack" label="Build Pack" />+ @if ($application->settings->is_static)+ <x-form-input id="application.static_image" label="Static Image" />+ @endif</div><div class="flex flex-col w-96"><x-form-input id="application.base_directory" label="Base Directory" />@@ -25,6 +28,7 @@</button></form><div class="flex flex-col pt-4 text-right w-52">+ <x-form-input instantSave type="checkbox" id="is_static" label="Static website?" /><x-form-input instantSave type="checkbox" id="is_auto_deploy" label="Auto Deploy?" /><x-form-input instantSave type="checkbox" id="is_dual_cert" label="Dual Certs?" /><x-form-input instantSave type="checkbox" id="is_previews" label="Previews?" />