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.

refactor(application): streamline healthcheck parsing from Dockerfile

Andras Bacsai806d892031b1
diff --git a/app/Jobs/ApplicationDeploymentJob.php b/app/Jobs/ApplicationDeploymentJob.php
index 5301363785..92186953b7 100644
--- a/app/Jobs/ApplicationDeploymentJob.php
+++ b/app/Jobs/ApplicationDeploymentJob.php
@@ -1211,7 +1211,7 @@ class ApplicationDeploymentJob implements ShouldBeEncrypted, ShouldQueue
if ($this->container_name) {
$counter = 1;
$this->application_deployment_queue->addLogEntry('Waiting for healthcheck to pass on the new container.');
- if ($this->full_healthcheck_url) {
+ if ($this->full_healthcheck_url && ! $this->application->custom_healthcheck_found) {
$this->application_deployment_queue->addLogEntry("Healthcheck URL (inside the container): {$this->full_healthcheck_url}");
}
$this->application_deployment_queue->addLogEntry("Waiting for the start period ({$this->application->health_check_start_period} seconds) before starting healthcheck.");
@@ -1718,8 +1718,7 @@ class ApplicationDeploymentJob implements ShouldBeEncrypted, ShouldQueue
'save' => 'dockerfile_from_repo',
'ignore_errors' => true,
]);
- $dockerfile = collect(str($this->saved_outputs->get('dockerfile_from_repo'))->trim()->explode("\n"));
- $this->application->parseHealthcheckFromDockerfile($dockerfile);
+ $this->application->parseHealthcheckFromDockerfile($this->saved_outputs->get('dockerfile_from_repo'));
}
$docker_compose = [
'services' => [
diff --git a/app/Livewire/Project/Application/General.php b/app/Livewire/Project/Application/General.php
index 08fff38c61..1d58ed33ad 100644
--- a/app/Livewire/Project/Application/General.php
+++ b/app/Livewire/Project/Application/General.php
@@ -369,6 +369,9 @@ class General extends Component
if ($this->application->isDirty('redirect')) {
$this->setRedirect();
}
+ if ($this->application->isDirty('dockerfile')) {
+ $this->application->parseHealthcheckFromDockerfile($this->application->dockerfile);
+ }
$this->checkFqdns();
diff --git a/app/Livewire/Project/New/SimpleDockerfile.php b/app/Livewire/Project/New/SimpleDockerfile.php
index c3ed6039a0..ebc9878dcf 100644
--- a/app/Livewire/Project/New/SimpleDockerfile.php
+++ b/app/Livewire/Project/New/SimpleDockerfile.php
@@ -74,7 +74,7 @@ CMD ["nginx", "-g", "daemon off;"]
'fqdn' => $fqdn,
]);
- $application->parseHealthcheckFromDockerfile(dockerfile: collect(str($this->dockerfile)->trim()->explode("\n")), isInit: true);
+ $application->parseHealthcheckFromDockerfile(dockerfile: $this->dockerfile, isInit: true);
return redirect()->route('project.application.configuration', [
'application_uuid' => $application->uuid,
diff --git a/app/Models/Application.php b/app/Models/Application.php
index ad688c93f0..57a69423d0 100644
--- a/app/Models/Application.php
+++ b/app/Models/Application.php
@@ -1507,6 +1507,7 @@ class Application extends BaseModel
public function parseHealthcheckFromDockerfile($dockerfile, bool $isInit = false)
{
+ $dockerfile = str($dockerfile)->trim()->explode("\n");
if (str($dockerfile)->contains('HEALTHCHECK') && ($this->isHealthcheckDisabled() || $isInit)) {
$healthcheckCommand = null;
$lines = $dockerfile->toArray();
@@ -1526,23 +1527,24 @@ class Application extends BaseModel
}
}
if (str($healthcheckCommand)->isNotEmpty()) {
- $interval = str($healthcheckCommand)->match('/--interval=(\d+)/');
- $timeout = str($healthcheckCommand)->match('/--timeout=(\d+)/');
- $start_period = str($healthcheckCommand)->match('/--start-period=(\d+)/');
- $start_interval = str($healthcheckCommand)->match('/--start-interval=(\d+)/');
+ $interval = str($healthcheckCommand)->match('/--interval=([0-9]+[a-zµ]*)/');
+ $timeout = str($healthcheckCommand)->match('/--timeout=([0-9]+[a-zµ]*)/');
+ $start_period = str($healthcheckCommand)->match('/--start-period=([0-9]+[a-zµ]*)/');
+ $start_interval = str($healthcheckCommand)->match('/--start-interval=([0-9]+[a-zµ]*)/');
$retries = str($healthcheckCommand)->match('/--retries=(\d+)/');
+
if ($interval->isNotEmpty()) {
- $this->health_check_interval = $interval->toInteger();
+ $this->health_check_interval = parseDockerfileInterval($interval);
}
if ($timeout->isNotEmpty()) {
- $this->health_check_timeout = $timeout->toInteger();
+ $this->health_check_timeout = parseDockerfileInterval($timeout);
}
if ($start_period->isNotEmpty()) {
- $this->health_check_start_period = $start_period->toInteger();
+ $this->health_check_start_period = parseDockerfileInterval($start_period);
+ }
+ if ($start_interval->isNotEmpty()) {
+ $this->health_check_start_interval = parseDockerfileInterval($start_interval);
}
- // if ($start_interval) {
- // $this->health_check_start_interval = $start_interval->value();
- // }
if ($retries->isNotEmpty()) {
$this->health_check_retries = $retries->toInteger();
}
diff --git a/bootstrap/helpers/shared.php b/bootstrap/helpers/shared.php
index db3085649a..60e71cd9c0 100644
--- a/bootstrap/helpers/shared.php
+++ b/bootstrap/helpers/shared.php
@@ -4137,3 +4137,35 @@ function getJobStatus(?string $jobId = null)
return $jobFound->first()->status;
}
+
+function parseDockerfileInterval(string $something)
+{
+ $value = preg_replace('/[^0-9]/', '', $something);
+ $unit = preg_replace('/[0-9]/', '', $something);
+
+ // Default to seconds if no unit specified
+ $unit = $unit ?: 's';
+
+ // Convert to seconds based on unit
+ $seconds = (int) $value;
+ switch ($unit) {
+ case 'ns':
+ $seconds = (int) ($value / 1000000000);
+ break;
+ case 'us':
+ case 'µs':
+ $seconds = (int) ($value / 1000000);
+ break;
+ case 'ms':
+ $seconds = (int) ($value / 1000);
+ break;
+ case 'm':
+ $seconds = (int) ($value * 60);
+ break;
+ case 'h':
+ $seconds = (int) ($value * 3600);
+ break;
+ }
+
+ return $seconds;
+}