diff --git a/app/Http/Livewire/Project/Application/General.php b/app/Http/Livewire/Project/Application/General.php
index e760eb975..2edfab88d 100644
--- a/app/Http/Livewire/Project/Application/General.php
+++ b/app/Http/Livewire/Project/Application/General.php
@@ -17,6 +17,7 @@ class General extends Component
public 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 Component
public 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 Component
public 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.php
index 7f973107a..511e3b5e8 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.php
index fe3345bb1..b408589d2 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.php
index dbb94446f..ccb89926e 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.php
index 9da146dd9..7d5c95ea6 100644
--- a/resources/views/livewire/project/application/general.blade.php
+++ b/resources/views/livewire/project/application/general.blade.php
@@ -10,6 +10,9 @@