Skip to content

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.

feat: concurrent builds / server

Andras Bacsai01f7b07fa34b
diff --git a/app/Jobs/ApplicationDeploymentJob.php b/app/Jobs/ApplicationDeploymentJob.php
index 595e222404..a8a94351e7 100644
--- a/app/Jobs/ApplicationDeploymentJob.php
+++ b/app/Jobs/ApplicationDeploymentJob.php
@@ -220,7 +220,6 @@ class ApplicationDeploymentJob implements ShouldQueue, ShouldBeEncrypted
$this->build_server = $this->server;
$this->original_server = $this->server;
}
- ray($this->build_server);
try {
if ($this->restart_only && $this->application->build_pack !== 'dockerimage') {
$this->just_restart();
@@ -311,7 +310,6 @@ class ApplicationDeploymentJob implements ShouldQueue, ShouldBeEncrypted
}
private function push_to_docker_registry($forceFail = false)
{
- ray((str($this->saved_outputs->get('local_image_found'))->isNotEmpty() && !$this->application->isConfigurationChanged()));
if (
$this->application->docker_registry_image_name &&
$this->application->build_pack !== 'dockerimage' &&
diff --git a/app/Livewire/Server/Form.php b/app/Livewire/Server/Form.php
index b8cabd58ba..df92ffaa4c 100644
--- a/app/Livewire/Server/Form.php
+++ b/app/Livewire/Server/Form.php
@@ -27,6 +27,7 @@ class Form extends Component
'server.settings.is_swarm_manager' => 'required|boolean',
'server.settings.is_swarm_worker' => 'required|boolean',
'server.settings.is_build_server' => 'required|boolean',
+ 'server.settings.concurrent_builds' => 'required|integer',
'wildcard_domain' => 'nullable|url',
];
protected $validationAttributes = [
@@ -40,6 +41,7 @@ class Form extends Component
'server.settings.is_swarm_manager' => 'Swarm Manager',
'server.settings.is_swarm_worker' => 'Swarm Worker',
'server.settings.is_build_server' => 'Build Server',
+ 'server.settings.concurrent_builds' => 'Concurrent Builds',
];
public function mount()
diff --git a/bootstrap/helpers/applications.php b/bootstrap/helpers/applications.php
index 6a0eeb01f5..02aedb8a72 100644
--- a/bootstrap/helpers/applications.php
+++ b/bootstrap/helpers/applications.php
@@ -24,8 +24,11 @@ function queue_application_deployment(int $application_id, string $deployment_uu
'commit' => $commit,
'git_type' => $git_type
]);
- $queued_deployments = ApplicationDeploymentQueue::where('application_id', $application_id)->where('status', 'queued')->get()->sortByDesc('created_at');
- $running_deployments = ApplicationDeploymentQueue::where('application_id', $application_id)->where('status', 'in_progress')->get()->sortByDesc('created_at');
+ $server = Application::find($application_id)->destination->server;
+ $deployments = ApplicationDeploymentQueue::where('application_id', $application_id);
+ $queued_deployments = $deployments->where('status', 'queued')->get()->sortByDesc('created_at');
+ $running_deployments = $deployments->where('status', 'in_progress')->get()->sortByDesc('created_at');
+ $all_deployments = $deployments->where('status', 'queued')->orWhere('status', 'in_progress')->get();
ray('Q:' . $queued_deployments->count() . 'R:' . $running_deployments->count() . '| Queuing deployment: ' . $deployment_uuid . ' of applicationID: ' . $application_id . ' pull request: ' . $pull_request_id . ' with commit: ' . $commit . ' and is it forced: ' . $force_rebuild);
if ($queued_deployments->count() > 1) {
$queued_deployments = $queued_deployments->skip(1);
@@ -37,6 +40,9 @@ function queue_application_deployment(int $application_id, string $deployment_uu
if ($running_deployments->count() > 0) {
return;
}
+ if ($all_deployments->count() >= $server->settings->concurrent_builds) {
+ return;
+ }
if ($is_new_deployment) {
dispatch(new ApplicationDeploymentNewJob(
deployment: $deployment,
@@ -51,7 +57,8 @@ function queue_application_deployment(int $application_id, string $deployment_uu
function queue_next_deployment(Application $application, bool $isNew = false)
{
- $next_found = ApplicationDeploymentQueue::where('application_id', $application->id)->where('status', 'queued')->first();
+ $next_found = ApplicationDeploymentQueue::where('status', 'queued')->get()->sortByDesc('created_at')->first();
+ ray('Next found: ' . $next_found);
if ($next_found) {
if ($isNew) {
dispatch(new ApplicationDeploymentNewJob(
diff --git a/database/migrations/2024_01_24_095449_add_concurrent_number_of_builds_per_server.php b/database/migrations/2024_01_24_095449_add_concurrent_number_of_builds_per_server.php
new file mode 100644
index 0000000000..f10d4891f8
--- /dev/null
+++ b/database/migrations/2024_01_24_095449_add_concurrent_number_of_builds_per_server.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('server_settings', function (Blueprint $table) {
+ $table->integer('concurrent_builds')->default(3);
+ });
+ }
+
+ /**
+ * Reverse the migrations.
+ */
+ public function down(): void
+ {
+ Schema::table('server_settings', function (Blueprint $table) {
+ $table->dropColumn('concurrent_builds');
+ });
+ }
+};
diff --git a/resources/views/livewire/server/form.blade.php b/resources/views/livewire/server/form.blade.php
index f801c64447..dd0933e4d9 100644
--- a/resources/views/livewire/server/form.blade.php
+++ b/resources/views/livewire/server/form.blade.php
@@ -86,8 +86,12 @@
@if ($server->isFunctional())
<h3 class="py-4">Settings</h3>
- <x-forms.input id="cleanup_after_percentage" label="Disk Cleanup threshold (%)" required
+ <div class="flex gap-2">
+ <x-forms.input id="cleanup_after_percentage" label="Disk cleanup threshold (%)" required
helper="Disk cleanup job will be executed if disk usage is more than this number." />
+ <x-forms.input id="server.settings.concurrent_builds" label="Number of concurrent builds" required
+ helper="You can define how many concurrent builds processes / deployments should run at the same time." />
+ </div>
@endif
</form>
</div>