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.

Merge branch 'next' into php-codestyle

Andras Bacsai7ad2e1ca056e
diff --cc app/Livewire/Project/Application/General.php
index a82c0c4281,b993542e26..fde85755d1
--- a/app/Livewire/Project/Application/General.php
+++ b/app/Livewire/Project/Application/General.php
@@@ -91,8 -77,8 +91,9 @@@ class General extends Componen
'application.settings.is_build_server_enabled' => 'boolean|required',
'application.settings.is_container_label_escape_enabled' => 'boolean|required',
'application.watch_paths' => 'nullable',
+ 'application.redirect' => 'string|required',
];
+
protected $validationAttributes = [
'application.name' => 'name',
'application.description' => 'description',
@@@ -128,8 -114,8 +129,9 @@@
'application.settings.is_build_server_enabled' => 'Is build server enabled',
'application.settings.is_container_label_escape_enabled' => 'Is container label escape enabled',
'application.watch_paths' => 'Watch paths',
+ 'application.redirect' => 'Redirect',
];
+
public function mount()
{
try {
@@@ -150,8 -135,8 +152,8 @@@
$this->ports_exposes = $this->application->ports_exposes;
$this->is_container_label_escape_enabled = $this->application->settings->is_container_label_escape_enabled;
$this->customLabels = $this->application->parseContainerLabels();
- if (!$this->customLabels && $this->application->destination->server->proxyType() !== 'NONE') {
+ if (! $this->customLabels && $this->application->destination->server->proxyType() !== 'NONE') {
- $this->customLabels = str(implode('|', generateLabelsApplication($this->application)))->replace('|', "\n");
+ $this->customLabels = str(implode("|coolify|", generateLabelsApplication($this->application)))->replace("|coolify|", "\n");
$this->application->custom_labels = base64_encode($this->customLabels);
$this->application->save();
}
@@@ -295,10 -270,9 +297,10 @@@
$this->dispatch('success', 'Wildcard domain generated.');
}
}
+
public function resetDefaultLabels()
{
- $this->customLabels = str(implode('|', generateLabelsApplication($this->application)))->replace('|', "\n");
+ $this->customLabels = str(implode("|coolify|", generateLabelsApplication($this->application)))->replace("|coolify|", "\n");
$this->ports_exposes = $this->application->ports_exposes;
$this->is_container_label_escape_enabled = $this->application->settings->is_container_label_escape_enabled;
$this->application->custom_labels = base64_encode($this->customLabels);
@@@ -323,7 -298,21 +326,22 @@@
$this->application->fqdn = $domains->implode(',');
}
}
+ public function set_redirect()
+ {
+ try {
+ $has_www = collect($this->application->fqdns)->filter(fn ($fqdn) => str($fqdn)->contains('www.'))->count();
+ if ($has_www === 0 && $this->application->redirect === 'www') {
+ $this->dispatch('error', 'You want to redirect to www, but you do not have a www domain set.<br><br>Please add www to your domain list and as an A DNS record (if applicable).');
+ return;
+ }
+ $this->application->save();
+ $this->resetDefaultLabels();
+ $this->dispatch('success', 'Redirect updated.');
+ } catch (\Throwable $e) {
+ return handleError($e, $this);
+ }
+ }
+
public function submit($showToaster = true)
{
try {
@@@ -338,8 -328,8 +357,8 @@@
$this->application->save();
- if (!$this->customLabels && $this->application->destination->server->proxyType() !== 'NONE') {
+ if (! $this->customLabels && $this->application->destination->server->proxyType() !== 'NONE') {
- $this->customLabels = str(implode('|', generateLabelsApplication($this->application)))->replace('|', "\n");
+ $this->customLabels = str(implode("|coolify|", generateLabelsApplication($this->application)))->replace("|coolify|", "\n");
$this->application->custom_labels = base64_encode($this->customLabels);
$this->application->save();
}
diff --cc app/Models/Application.php
index c28e8aefa8,63d24decb7..dae1a520bd
--- a/app/Models/Application.php
+++ b/app/Models/Application.php
@@@ -629,10 -563,9 +629,10 @@@ class Application extends BaseMode
{
return data_get($this, 'settings.is_log_drain_enabled', false);
}
+
public function isConfigurationChanged(bool $save = false)
{
- $newConfigHash = $this->fqdn.$this->git_repository.$this->git_branch.$this->git_commit_sha.$this->build_pack.$this->static_image.$this->install_command.$this->build_command.$this->start_command.$this->ports_exposes.$this->ports_mappings.$this->base_directory.$this->publish_directory.$this->dockerfile.$this->dockerfile_location.$this->custom_labels.$this->custom_docker_run_options.$this->dockerfile_target_build;
+ $newConfigHash = $this->fqdn . $this->git_repository . $this->git_branch . $this->git_commit_sha . $this->build_pack . $this->static_image . $this->install_command . $this->build_command . $this->start_command . $this->ports_exposes . $this->ports_mappings . $this->base_directory . $this->publish_directory . $this->dockerfile . $this->dockerfile_location . $this->custom_labels . $this->custom_docker_run_options . $this->dockerfile_target_build . $this->redirect;
if ($this->pull_request_id === 0 || $this->pull_request_id === null) {
$newConfigHash .= json_encode($this->environment_variables()->get('value')->sort());
} else {
diff --cc bootstrap/helpers/docker.php
index 902c287f30,895573b58b..6ccf841659
--- a/bootstrap/helpers/docker.php
+++ b/bootstrap/helpers/docker.php
@@@ -243,10 -232,9 +243,10 @@@ function generateServiceSpecificFqdns(S
]);
break;
}
+
return $payload;
}
- function fqdnLabelsForCaddy(string $network, string $uuid, Collection $domains, bool $is_force_https_enabled = false, $onlyPort = null, ?Collection $serviceLabels = null, ?bool $is_gzip_enabled = true, ?bool $is_stripprefix_enabled = true, ?string $service_name = null, ?string $image = null)
+ function fqdnLabelsForCaddy(string $network, string $uuid, Collection $domains, bool $is_force_https_enabled = false, $onlyPort = null, ?Collection $serviceLabels = null, ?bool $is_gzip_enabled = true, ?bool $is_stripprefix_enabled = true, ?string $service_name = null, ?string $image = null, string $redirect_direction = 'both')
{
$labels = collect([]);
if ($serviceLabels) {
@@@ -259,10 -247,10 +259,10 @@@
$url = Url::fromString($domain);
$host = $url->getHost();
$path = $url->getPath();
-
+ $host_without_www = str($host)->replace('www.', '');
$schema = $url->getScheme();
$port = $url->getPort();
- if (is_null($port) && !is_null($onlyPort)) {
+ if (is_null($port) && ! is_null($onlyPort)) {
$port = $onlyPort;
}
$labels->push("caddy_{$loop}={$schema}://{$host}");
@@@ -282,10 -276,9 +288,10 @@@
// $labels->push("caddy_{$loop}.tls=internal");
}
}
+
return $labels->sort();
}
- function fqdnLabelsForTraefik(string $uuid, Collection $domains, bool $is_force_https_enabled = false, $onlyPort = null, ?Collection $serviceLabels = null, ?bool $is_gzip_enabled = true, ?bool $is_stripprefix_enabled = true, ?string $service_name = null, bool $generate_unique_uuid = false, ?string $image = null)
+ function fqdnLabelsForTraefik(string $uuid, Collection $domains, bool $is_force_https_enabled = false, $onlyPort = null, ?Collection $serviceLabels = null, ?bool $is_gzip_enabled = true, ?bool $is_stripprefix_enabled = true, ?string $service_name = null, bool $generate_unique_uuid = false, ?string $image = null, string $redirect_direction = 'both')
{
$labels = collect([]);
$labels->push('traefik.enable=true');
@@@ -345,8 -341,21 +354,21 @@@
}
if (str($image)->contains('ghost')) {
$labels->push("traefik.http.middlewares.redir-ghost.redirectregex.regex=^{$path}/(.*)");
- $labels->push("traefik.http.middlewares.redir-ghost.redirectregex.replacement=/$1");
+ $labels->push('traefik.http.middlewares.redir-ghost.redirectregex.replacement=/$1');
}
+
+ $to_www_name = "{$loop}-{$uuid}-to-www";
+ $to_non_www_name = "{$loop}-{$uuid}-to-non-www";
+ $redirect_to_non_www = [
+ "traefik.http.middlewares.{$to_non_www_name}.redirectregex.regex=^(http|https)://www\.(.+)",
+ "traefik.http.middlewares.{$to_non_www_name}.redirectregex.replacement=\${1}://\${2}",
+ "traefik.http.middlewares.{$to_non_www_name}.redirectregex.permanent=false"
+ ];
+ $redirect_to_www = [
+ "traefik.http.middlewares.{$to_www_name}.redirectregex.regex=^(http|https)://(?:www\.)?(.+)",
+ "traefik.http.middlewares.{$to_www_name}.redirectregex.replacement=\${1}://www.\${2}",
+ "traefik.http.middlewares.{$to_www_name}.redirectregex.permanent=false"
+ ];
if ($schema === 'https') {
// Set labels for https
$labels->push("traefik.http.routers.{$https_label}.rule=Host(`{$host}`) && PathPrefix(`{$path}`)");