From e40f397cc74ea1d5e71a3843dac08d212ec4bc01 Mon Sep 17 00:00:00 2001 From: Andras Bacsai Date: Sat, 11 Nov 2023 21:32:41 +0100 Subject: [PATCH] fix: service updates --- .../Livewire/Project/Service/StackForm.php | 7 ++++ app/Models/Service.php | 24 ++++++++++--- bootstrap/helpers/services.php | 30 ++++++++-------- config/sentry.php | 2 +- config/version.php | 2 +- .../project/service/stack-form.blade.php | 8 +++-- templates/compose/minio.yaml | 34 +++++++++++++++---- templates/service-templates.json | 12 +++++++ versions.json | 2 +- 9 files changed, 92 insertions(+), 29 deletions(-) diff --git a/app/Http/Livewire/Project/Service/StackForm.php b/app/Http/Livewire/Project/Service/StackForm.php index 2c1fa5495..30a3e7380 100644 --- a/app/Http/Livewire/Project/Service/StackForm.php +++ b/app/Http/Livewire/Project/Service/StackForm.php @@ -7,6 +7,7 @@ use Livewire\Component; class StackForm extends Component { public $service; + public $isConfigurationRequired = false; protected $listeners = ["saveCompose"]; protected $rules = [ 'service.docker_compose_raw' => 'required', @@ -14,8 +15,14 @@ class StackForm extends Component 'service.name' => 'required', 'service.description' => 'nullable', ]; + public function mount () { + if ($this->service->applications->filter(fn($app) => str($app->image)->contains('minio/minio'))->count() > 0) { + $this->isConfigurationRequired = true; + } + } public function saveCompose($raw) { + $this->service->docker_compose_raw = $raw; $this->submit(); } diff --git a/app/Models/Service.php b/app/Models/Service.php index a1fa4b4ba..14084f282 100644 --- a/app/Models/Service.php +++ b/app/Models/Service.php @@ -453,15 +453,31 @@ class Service extends BaseModel 'service_id' => $this->id, ])->first(); if ($value->startsWith('SERVICE_')) { - $command = $value->after('SERVICE_')->beforeLast('_'); - $forService = $value->afterLast('_'); - $generatedValue = null; + // Count _ in $value + $count = substr_count($value->value(), '_'); + if ($count === 2) { + // SERVICE_FQDN_UMAMI + $command = $value->after('SERVICE_')->beforeLast('_'); + $forService = $value->afterLast('_'); + $generatedValue = null; + $port = null; + } + if ($count === 3) { + // SERVICE_FQDN_UMAMI_1000 + $command = $value->after('SERVICE_')->before('_'); + $forService = $value->after('SERVICE_')->after('_')->before('_'); + $generatedValue = null; + $port = $value->afterLast('_'); + } if ($command->value() === 'FQDN' || $command->value() === 'URL') { if (Str::lower($forService) === $serviceName) { $fqdn = generateFqdn($this->server, $containerName); } else { $fqdn = generateFqdn($this->server, Str::lower($forService) . '-' . $this->uuid); } + if ($port) { + $fqdn = "$fqdn:$port"; + } if ($foundEnv) { $fqdn = data_get($foundEnv, 'value'); } else { @@ -477,7 +493,7 @@ class Service extends BaseModel ]); } if (!$isDatabase) { - if ($command->value() === 'FQDN') { + if ($command->value() === 'FQDN' && is_null($savedService->fqdn)) { $savedService->fqdn = $fqdn; $savedService->save(); } diff --git a/bootstrap/helpers/services.php b/bootstrap/helpers/services.php index 762b83563..b9a305a42 100644 --- a/bootstrap/helpers/services.php +++ b/bootstrap/helpers/services.php @@ -85,7 +85,6 @@ function getFilesystemVolumesFromServer(ServiceApplication|ServiceDatabase $oneS } else { $fileLocation = $path; } - ray($path,$fileLocation); // Exists and is a file $isFile = instant_remote_process(["test -f $fileLocation && echo OK || echo NOK"], $server); // Exists and is a directory @@ -127,6 +126,7 @@ function getFilesystemVolumesFromServer(ServiceApplication|ServiceDatabase $oneS function updateCompose($resource) { try { + ray($resource); $name = data_get($resource, 'name'); $dockerComposeRaw = data_get($resource, 'service.docker_compose_raw'); $dockerCompose = Yaml::parse($dockerComposeRaw); @@ -135,19 +135,21 @@ function updateCompose($resource) $image = data_get($resource, 'image'); data_set($dockerCompose, "services.{$name}.image", $image); - // Update FQDN - $variableName = "SERVICE_FQDN_" . Str::of($resource->name)->upper(); - $generatedEnv = EnvironmentVariable::where('service_id', $resource->service_id)->where('key', $variableName)->first(); - if ($generatedEnv) { - $generatedEnv->value = $resource->fqdn; - $generatedEnv->save(); - } - $variableName = "SERVICE_URL_" . Str::of($resource->name)->upper(); - $generatedEnv = EnvironmentVariable::where('service_id', $resource->service_id)->where('key', $variableName)->first(); - if ($generatedEnv) { - $url = Str::of($resource->fqdn)->after('://'); - $generatedEnv->value = $url; - $generatedEnv->save(); + if (!str($resource->fqdn)->contains(',')) { + // Update FQDN + $variableName = "SERVICE_FQDN_" . Str::of($resource->name)->upper(); + $generatedEnv = EnvironmentVariable::where('service_id', $resource->service_id)->where('key', $variableName)->first(); + if ($generatedEnv) { + $generatedEnv->value = $resource->fqdn; + $generatedEnv->save(); + } + $variableName = "SERVICE_URL_" . Str::of($resource->name)->upper(); + $generatedEnv = EnvironmentVariable::where('service_id', $resource->service_id)->where('key', $variableName)->first(); + if ($generatedEnv) { + $url = Str::of($resource->fqdn)->after('://'); + $generatedEnv->value = $url; + $generatedEnv->save(); + } } $dockerComposeRaw = Yaml::dump($dockerCompose, 10, 2); diff --git a/config/sentry.php b/config/sentry.php index 3a9aa3df6..c889afb12 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.122', + 'release' => '4.0.0-beta.123', // 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 5a47704b8..f31b19ca0 100644 --- a/config/version.php +++ b/config/version.php @@ -1,3 +1,3 @@
- +
+ @if ($isConfigurationRequired) +
This service requires additional confiugration. Please check our documentation for further information. +
+ @endif diff --git a/templates/compose/minio.yaml b/templates/compose/minio.yaml index fb1e12710..569172ca0 100644 --- a/templates/compose/minio.yaml +++ b/templates/compose/minio.yaml @@ -1,4 +1,3 @@ -# ignore: true # documentation: https://docs.min.io/docs/minio-docker-quickstart-guide.html # slogan: MinIO is a high performance object storage server compatible with Amazon S3 APIs. # tags: object, storage, server, s3, api @@ -8,12 +7,35 @@ services: image: quay.io/minio/minio:latest command: server /data --console-address ":9001" environment: - - SERVICE_FQDN_MINIO_9000 - - SERVICE_FQDN_CONSOLE_9001 - - MINIO_DOMAIN=$SERVICE_URL_MINIO_9000 - - MINIO_SERVER_URL=$SERVICE_FQDN_MINIO_9000 - - MINIO_BROWSER_REDIRECT_URL=$SERVICE_FQDN_CONSOLE_9001 + - MINIO_SERVER_URL=$MINIO_SERVER_URL + - MINIO_BROWSER_REDIRECT_URL=$MINIO_BROWSER_REDIRECT_URL - MINIO_ROOT_USER=$SERVICE_USER_MINIO - MINIO_ROOT_PASSWORD=$SERVICE_PASSWORD_MINIO volumes: - minio-data:/data + +# services: +# minio: +# image: minio/minio +# command: server /data --address ":9000" --console-address ":9001" +# networks: +# - coolify +# environment: +# - MINIO_SERVER_URL=http://minio.65.21.189.27.sslip.io +# - MINIO_BROWSER_REDIRECT_URL=http://console.65.21.189.27.sslip.io +# - MINIO_BROWSER=on +# - MINIO_ROOT_USER=asd +# - MINIO_ROOT_PASSWORD=asdasdasd +# labels: +# - "traefik.enable=true" +# - "traefik.http.routers.minio-console.rule=Host(`console.65.21.189.27.sslip.io`)" +# - "traefik.http.routers.minio-console.entrypoints=http" +# - "traefik.http.routers.minio-console.service=minio-console" +# - "traefik.http.services.minio-console.loadbalancer.server.port=9001" +# - "traefik.http.routers.minio.rule=Host(`minio.65.21.189.27.sslip.io`)" +# - "traefik.http.routers.minio.entrypoints=http" +# - "traefik.http.routers.minio.service=minio" +# - "traefik.http.services.minio.loadbalancer.server.port=9000" +# networks: +# coolify: +# external: true diff --git a/templates/service-templates.json b/templates/service-templates.json index 13b79ed8e..34bf51787 100644 --- a/templates/service-templates.json +++ b/templates/service-templates.json @@ -300,6 +300,18 @@ "playlist" ] }, + "minio": { + "documentation": "https:\/\/docs.min.io\/docs\/minio-docker-quickstart-guide.html", + "slogan": "MinIO is a high performance object storage server compatible with Amazon S3 APIs.", + "compose": "c2VydmljZXM6CiAgbWluaW86CiAgICBpbWFnZTogJ3F1YXkuaW8vbWluaW8vbWluaW86bGF0ZXN0JwogICAgY29tbWFuZDogJ3NlcnZlciAvZGF0YSAtLWNvbnNvbGUtYWRkcmVzcyAiOjkwMDEiJwogICAgZW52aXJvbm1lbnQ6CiAgICAgIC0gTUlOSU9fU0VSVkVSX1VSTD0kTUlOSU9fU0VSVkVSX1VSTAogICAgICAtIE1JTklPX0JST1dTRVJfUkVESVJFQ1RfVVJMPSRNSU5JT19CUk9XU0VSX1JFRElSRUNUX1VSTAogICAgICAtIE1JTklPX1JPT1RfVVNFUj0kU0VSVklDRV9VU0VSX01JTklPCiAgICAgIC0gTUlOSU9fUk9PVF9QQVNTV09SRD0kU0VSVklDRV9QQVNTV09SRF9NSU5JTwogICAgdm9sdW1lczoKICAgICAgLSAnbWluaW8tZGF0YTovZGF0YScK", + "tags": [ + "object", + "storage", + "server", + "s3", + "api" + ] + }, "moodle": { "documentation": "https:\/\/moodle.org", "slogan": "Moodle is the world\u2019s most customisable and trusted eLearning solution that empowers educators to improve our world.", diff --git a/versions.json b/versions.json index 21fa4227d..c62fd27f5 100644 --- a/versions.json +++ b/versions.json @@ -4,7 +4,7 @@ "version": "3.12.36" }, "v4": { - "version": "4.0.0-beta.122" + "version": "4.0.0-beta.123" } } }