fix: sslip for localhost

This commit is contained in:
Andras Bacsai 2023-09-28 10:53:00 +02:00
parent 199881c596
commit b046a3e9f7
6 changed files with 24 additions and 50 deletions

View File

@ -144,10 +144,8 @@ public function submit()
$application->settings->is_static = $this->is_static;
$application->settings->save();
$application->fqdn = "http://{$application->uuid}.{$destination->server->ip}.sslip.io";
if (isDev()) {
$application->fqdn = "http://{$application->uuid}.127.0.0.1.sslip.io";
}
$sslip = sslip($destination->server);
$application->fqdn = "http://{$application->uuid}.$sslip";
$application->name = generate_application_name($this->selected_repository_owner . '/' . $this->selected_repository_repo, $this->selected_branch_name, $application->uuid);
$application->save();

View File

@ -112,10 +112,8 @@ public function submit()
$application->settings->is_static = $this->is_static;
$application->settings->save();
$application->fqdn = "http://{$application->uuid}.{$destination->server->ip}.sslip.io";
if (isDev()) {
$application->fqdn = "http://{$application->uuid}.127.0.0.1.sslip.io";
}
$sslip = sslip($destination->server);
$application->fqdn = "http://{$application->uuid}.$sslip";
$application->name = generate_random_name($application->uuid);
$application->save();

View File

@ -156,10 +156,8 @@ public function submit()
$application->settings->is_static = $this->is_static;
$application->settings->save();
$application->fqdn = "http://{$application->uuid}.{$destination->server->ip}.sslip.io";
if (isDev()) {
$application->fqdn = "http://{$application->uuid}.127.0.0.1.sslip.io";
}
$sslip = sslip($destination->server);
$application->fqdn = "http://{$application->uuid}.$sslip";
$application->name = generate_application_name($this->git_repository, $this->git_branch, $application->uuid);
$application->save();

View File

@ -60,13 +60,10 @@ public function submit()
'source_type' => GithubApp::class
]);
$fqdn = "http://{$application->uuid}.{$destination->server->ip}.sslip.io";
if (isDev()) {
$fqdn = "http://{$application->uuid}.127.0.0.1.sslip.io";
}
$sslip = sslip($destination->server);
$application->update([
'name' => 'dockerfile-' . $application->uuid,
'fqdn' => $fqdn
'fqdn' => "http://{$application->uuid}.$sslip"
]);
redirect()->route('project.application.configuration', [

View File

@ -109,37 +109,7 @@ public function saveComposeConfigs()
}
instant_remote_process($commands, $this->server);
}
private function sslip(Server $server)
{
if (isDev()) {
return "127.0.0.1.sslip.io";
}
return "{$server->ip}.sslip.io";
}
// private function generateFqdn($serviceVariables, $serviceName, Collection $configuration)
// {
// // Add sslip.io to the service
// $defaultUsableFqdn = null;
// $sslip = $this->sslip($this->server);
// if (Str::of($serviceVariables)->contains('SERVICE_FQDN') || Str::of($serviceVariables)->contains('SERVICE_URL')) {
// $defaultUsableFqdn = "http://$serviceName-{$this->uuid}.{$sslip}";
// }
// if ($configuration->count() > 0) {
// foreach ($configuration as $requiredFqdn) {
// $requiredFqdn = (array)$requiredFqdn;
// $name = data_get($requiredFqdn, 'name');
// $path = data_get($requiredFqdn, 'path');
// $customFqdn = data_get($requiredFqdn, 'customFqdn');
// if ($serviceName === $name) {
// $defaultUsableFqdn = "http://$serviceName-{$this->uuid}.{$sslip}{$path}";
// if ($customFqdn) {
// $defaultUsableFqdn = "http://$customFqdn-{$this->uuid}.{$sslip}{$path}";
// }
// }
// }
// }
// return $defaultUsableFqdn ?? null;
// }
public function parse(bool $isNew = false): Collection
{
// ray()->clearAll();
@ -374,7 +344,7 @@ public function parse(bool $isNew = false): Collection
}
if ($key->startsWith('SERVICE_FQDN')) {
if (is_null(data_get($savedService, 'fqdn'))) {
$sslip = $this->sslip($this->server);
$sslip = sslip($this->server);
$fqdn = "http://$containerName.$sslip";
if (substr_count($key->value(), '_') === 2 && $key->contains("=")) {
$path = $value->value();
@ -409,7 +379,7 @@ public function parse(bool $isNew = false): Collection
$forService = $value->afterLast('_');
$generatedValue = null;
if ($command->value() === 'FQDN' || $command->value() === 'URL') {
$sslip = $this->sslip($this->server);
$sslip = sslip($this->server);
$fqdn = "http://$containerName.$sslip";
if ($foundEnv) {
$fqdn = data_get($foundEnv, 'value');

View File

@ -1,6 +1,7 @@
<?php
use App\Models\InstanceSettings;
use App\Models\Server;
use App\Models\Team;
use App\Models\User;
use App\Notifications\Channels\DiscordChannel;
@ -393,3 +394,15 @@ function data_get_str($data, $key, $default = null): Stringable
$str = data_get($data, $key, $default) ?? $default;
return Str::of($str);
}
function sslip(Server $server)
{
if (isDev()) {
return "127.0.0.1.sslip.io";
}
if ($server->ip === 'host.docker.internal') {
$baseIp = base_ip();
return "$baseIp.sslip.io";
}
return "{$server->ip}.sslip.io";
}