init of static deployments

This commit is contained in:
Andras Bacsai
2023-04-25 15:48:45 +02:00
parent 9051214278
commit 3e9e1e94d6
5 changed files with 39 additions and 19 deletions

View File

@@ -17,6 +17,7 @@ class General extends Component
public string|null $git_commit_sha; public string|null $git_commit_sha;
public string $build_pack; public string $build_pack;
public bool $is_static;
public bool $is_git_submodules_allowed; public bool $is_git_submodules_allowed;
public bool $is_git_lfs_allowed; public bool $is_git_lfs_allowed;
public bool $is_debug; public bool $is_debug;
@@ -34,6 +35,7 @@ class General extends Component
'application.git_branch' => 'required', 'application.git_branch' => 'required',
'application.git_commit_sha' => 'nullable', 'application.git_commit_sha' => 'nullable',
'application.build_pack' => 'required', 'application.build_pack' => 'required',
'application.static_image' => 'required',
'application.base_directory' => 'required', 'application.base_directory' => 'required',
'application.publish_directory' => 'nullable', 'application.publish_directory' => 'nullable',
'application.ports_exposes' => 'required', 'application.ports_exposes' => 'required',
@@ -42,6 +44,7 @@ class General extends Component
public function instantSave() public function instantSave()
{ {
// @TODO: find another way // @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_submodules_allowed = $this->is_git_submodules_allowed;
$this->application->settings->is_git_lfs_allowed = $this->is_git_lfs_allowed; $this->application->settings->is_git_lfs_allowed = $this->is_git_lfs_allowed;
$this->application->settings->is_debug = $this->is_debug; $this->application->settings->is_debug = $this->is_debug;
@@ -56,6 +59,7 @@ class General extends Component
public function mount() public function mount()
{ {
$this->application = Application::where('id', $this->applicationId)->with('destination', 'settings')->firstOrFail(); $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_submodules_allowed = $this->application->settings->is_git_submodules_allowed;
$this->is_git_lfs_allowed = $this->application->settings->is_git_lfs_allowed; $this->is_git_lfs_allowed = $this->application->settings->is_git_lfs_allowed;
$this->is_debug = $this->application->settings->is_debug; $this->is_debug = $this->application->settings->is_debug;

View File

@@ -163,10 +163,26 @@ class DeployApplicationJob implements ShouldQueue
"echo -n 'Building image... '", "echo -n 'Building image... '",
]); ]);
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->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}"), $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); ], isDebuggable: true);
}
$this->executeNow([ $this->executeNow([
"echo 'Done.'", "echo 'Done.'",
"echo -n 'Removing old instance... '", "echo -n 'Removing old instance... '",
@@ -422,9 +438,6 @@ class DeployApplicationJob implements ShouldQueue
} }
private function nixpacks_build_cmd() 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"; $nixpacks_command = "nixpacks build -o {$this->workdir} --no-error-without-start";
if ($this->application->install_command) { if ($this->application->install_command) {
$nixpacks_command .= " --install-cmd '{$this->application->install_command}'"; $nixpacks_command .= " --install-cmd '{$this->application->install_command}'";
@@ -436,7 +449,6 @@ class DeployApplicationJob implements ShouldQueue
$nixpacks_command .= " --start-cmd '{$this->application->start_command}'"; $nixpacks_command .= " --start-cmd '{$this->application->start_command}'";
} }
$nixpacks_command .= " {$this->workdir}"; $nixpacks_command .= " {$this->workdir}";
}
return $this->execute_in_builder($nixpacks_command); return $this->execute_in_builder($nixpacks_command);
} }
} }

View File

@@ -27,8 +27,7 @@ return new class extends Migration
$table->string('docker_registry_image_tag')->nullable(); $table->string('docker_registry_image_tag')->nullable();
$table->string('build_pack'); $table->string('build_pack');
$table->string('base_image')->nullable(); $table->string('static_image')->default('nginx:alpine');
$table->string('build_image')->nullable();
$table->string('install_command')->nullable(); $table->string('install_command')->nullable();
$table->string('build_command')->nullable(); $table->string('build_command')->nullable();

View File

@@ -13,6 +13,7 @@ return new class extends Migration
{ {
Schema::create('application_settings', function (Blueprint $table) { Schema::create('application_settings', function (Blueprint $table) {
$table->id(); $table->id();
$table->boolean('is_static')->default(false);
$table->boolean('is_git_submodules_allowed')->default(true); $table->boolean('is_git_submodules_allowed')->default(true);
$table->boolean('is_git_lfs_allowed')->default(true); $table->boolean('is_git_lfs_allowed')->default(true);
$table->boolean('is_auto_deploy')->default(true); $table->boolean('is_auto_deploy')->default(true);

View File

@@ -10,6 +10,9 @@
<x-form-input id="application.build_command" label="Build Command" /> <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.start_command" label="Start Command" />
<x-form-input id="application.build_pack" label="Build Pack" /> <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>
<div class="flex flex-col w-96"> <div class="flex flex-col w-96">
<x-form-input id="application.base_directory" label="Base Directory" /> <x-form-input id="application.base_directory" label="Base Directory" />
@@ -25,6 +28,7 @@
</button> </button>
</form> </form>
<div class="flex flex-col pt-4 text-right w-52"> <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_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_dual_cert" label="Dual Certs?" />
<x-form-input instantSave type="checkbox" id="is_previews" label="Previews?" /> <x-form-input instantSave type="checkbox" id="is_previews" label="Previews?" />