diff --git a/app/Jobs/ApplicationDeploymentJob.php b/app/Jobs/ApplicationDeploymentJob.php index d6c4b5ccf..eeabb185f 100644 --- a/app/Jobs/ApplicationDeploymentJob.php +++ b/app/Jobs/ApplicationDeploymentJob.php @@ -97,7 +97,7 @@ class ApplicationDeploymentJob implements ShouldQueue, ShouldBeEncrypted if ($this->pull_request_id !== 0) { $this->preview = ApplicationPreview::findPreviewByApplicationAndPullId($this->application->id, $this->pull_request_id); if ($this->application->fqdn) { - $preview_fqdn = getOnlyFqdn(data_get($this->preview, 'fqdn')); + $preview_fqdn = getFqdnWithoutPort(data_get($this->preview, 'fqdn')); $template = $this->application->preview_url_template; $url = Url::fromString($this->application->fqdn); $host = $url->getHost(); @@ -284,9 +284,20 @@ class ApplicationDeploymentJob implements ShouldQueue, ShouldBeEncrypted private function rolling_update() { - $this->start_by_compose_file(); - $this->health_check(); - $this->stop_running_container(); + if (count($this->application->ports_mappings_array) > 0){ + $this->execute_remote_command( + ["echo -n 'Application has ports mapped to the host system, rolling update is not supported. Stopping current container.'"], + ); + $this->stop_running_container(force: true); + $this->start_by_compose_file(); + } else { + $this->execute_remote_command( + ["echo -n 'Rolling update started.'"], + ); + $this->start_by_compose_file(); + $this->health_check(); + $this->stop_running_container(); + } } private function health_check() { @@ -529,7 +540,7 @@ class ApplicationDeploymentJob implements ShouldQueue, ShouldBeEncrypted 'restart' => RESTART_MODE, 'environment' => $environment_variables, 'labels' => generateLabelsApplication($this->application, $this->preview), - // 'expose' => $ports, + 'expose' => $ports, 'networks' => [ $this->destination->network, ], @@ -704,10 +715,10 @@ COPY ./nginx.conf /etc/nginx/conf.d/default.conf"); } } - private function stop_running_container() + private function stop_running_container(bool $force = false) { if ($this->currently_running_container_name) { - if ($this->newVersionIsHealthy) { + if ($this->newVersionIsHealthy || $force) { $this->execute_remote_command( ["echo -n 'Removing old version of your application.'"], [executeInDocker($this->deployment_uuid, "docker rm -f $this->currently_running_container_name >/dev/null 2>&1"), "hidden" => true], @@ -724,7 +735,7 @@ COPY ./nginx.conf /etc/nginx/conf.d/default.conf"); private function start_by_compose_file() { $this->execute_remote_command( - ["echo -n 'Rolling update started.'"], + ["echo -n 'Starting application (could take a while).'"], [executeInDocker($this->deployment_uuid, "docker compose --project-directory {$this->workdir} up -d >/dev/null"), "hidden" => true], ); } diff --git a/app/Models/Service.php b/app/Models/Service.php index 4b66fdf19..ae590f13f 100644 --- a/app/Models/Service.php +++ b/app/Models/Service.php @@ -377,7 +377,7 @@ class Service extends BaseModel } else { $number = 0; } - $fqdn = getOnlyFqdn(data_get($fqdns, $number, $fqdns->first())); + $fqdn = getFqdnWithoutPort(data_get($fqdns, $number, $fqdns->first())); $environments = collect(data_get($service, 'environment')); $environments = $environments->map(function ($envValue) use ($value, $fqdn) { $envValue = Str::of($envValue)->replace($value, $fqdn); @@ -393,7 +393,7 @@ class Service extends BaseModel } else { $number = 0; } - $fqdn = getOnlyFqdn(data_get($fqdns, $number, $fqdns->first())); + $fqdn = getFqdnWithoutPort(data_get($fqdns, $number, $fqdns->first())); $url = Url::fromString($fqdn)->getHost(); $environments = collect(data_get($service, 'environment')); $environments = $environments->map(function ($envValue) use ($value, $url) { diff --git a/app/View/Components/Services/Links.php b/app/View/Components/Services/Links.php index 69fefa7a2..b2cc8618d 100644 --- a/app/View/Components/Services/Links.php +++ b/app/View/Components/Services/Links.php @@ -19,7 +19,7 @@ class Links extends Component if ($application->fqdn) { $fqdns = collect(Str::of($application->fqdn)->explode(',')); $fqdns->map(function ($fqdn) { - $this->links->push(getOnlyFqdn($fqdn)); + $this->links->push(getFqdnWithoutPort($fqdn)); }); } if ($application->ports) { diff --git a/bootstrap/helpers/docker.php b/bootstrap/helpers/docker.php index 6d8e2e024..27fa96fb8 100644 --- a/bootstrap/helpers/docker.php +++ b/bootstrap/helpers/docker.php @@ -147,7 +147,7 @@ function fqdnLabelsForTraefik(Collection $domains, $container_name, $is_force_ht { $labels = collect([]); $labels->push('traefik.enable=true'); - foreach($domains as $domain) { + foreach ($domains as $domain) { $url = Url::fromString($domain); $host = $url->getHost(); $path = $url->getPath(); @@ -216,9 +216,8 @@ function generateLabelsApplication(Application $application, ?ApplicationPreview } else { $domains = Str::of(data_get($application, 'fqdn'))->explode(','); } - if ($application->destination->server->proxy->type === ProxyTypes::TRAEFIK_V2->value) { - $labels = $labels->merge(fqdnLabelsForTraefik($domains, $container_name, $application->settings->is_force_https_enabled)); - } + // Add Traefik labels no matter which proxy is selected + $labels = $labels->merge(fqdnLabelsForTraefik($domains, $container_name, $application->settings->is_force_https_enabled)); } return $labels->all(); } diff --git a/bootstrap/helpers/remoteProcess.php b/bootstrap/helpers/remoteProcess.php index 0d76d46ea..e5a2a5863 100644 --- a/bootstrap/helpers/remoteProcess.php +++ b/bootstrap/helpers/remoteProcess.php @@ -189,7 +189,7 @@ function validateServer(Server $server, bool $throwError = false) ]; } $server->settings->is_reachable = true; - + instant_remote_process(["docker ps"], $server, $throwError); $dockerVersion = instant_remote_process(["docker version|head -2|grep -i version| awk '{print $2}'"], $server, $throwError); if (!$dockerVersion) { $dockerVersion = null; diff --git a/bootstrap/helpers/shared.php b/bootstrap/helpers/shared.php index cb1a758a9..63f7fb8b1 100644 --- a/bootstrap/helpers/shared.php +++ b/bootstrap/helpers/shared.php @@ -100,7 +100,8 @@ function handleError(?Throwable $error = null, ?Livewire\Component $livewire = n return "Too many requests. Please try again in {$error->secondsUntilAvailable} seconds."; } if (isset($livewire)) { - return $livewire->emit('error', $message); + $livewire->emit('error', $message); + throw new RuntimeException($message); } throw new RuntimeException($message); @@ -240,11 +241,13 @@ function base_ip(): string } return "localhost"; } -function getOnlyFqdn(String $fqdn) { +function getFqdnWithoutPort(String $fqdn) +{ $url = Url::fromString($fqdn); $host = $url->getHost(); $scheme = $url->getScheme(); - return "$scheme://$host"; + $path = $url->getPath(); + return "$scheme://$host$path"; } /** * If fqdn is set, return it, otherwise return public ip. diff --git a/config/sentry.php b/config/sentry.php index 39c920a43..3a1955646 100644 --- a/config/sentry.php +++ b/config/sentry.php @@ -7,7 +7,7 @@ return [ // The release version of your application // Example with dynamic git hash: trim(exec('git --git-dir ' . base_path('.git') . ' log --pretty="%h" -n1 HEAD')) - 'release' => '4.0.0-beta.44', + 'release' => '4.0.0-beta.45', // When left empty or `null` the Laravel environment will be used 'environment' => config('app.env'), diff --git a/config/version.php b/config/version.php index 34ed5e7bd..462d9f013 100644 --- a/config/version.php +++ b/config/version.php @@ -1,3 +1,3 @@ explode(',') as $fqdn)