fix: service updates

This commit is contained in:
Andras Bacsai 2023-11-11 21:32:41 +01:00
parent a94b7ee611
commit e40f397cc7
9 changed files with 92 additions and 29 deletions

View File

@ -7,6 +7,7 @@
class StackForm extends Component class StackForm extends Component
{ {
public $service; public $service;
public $isConfigurationRequired = false;
protected $listeners = ["saveCompose"]; protected $listeners = ["saveCompose"];
protected $rules = [ protected $rules = [
'service.docker_compose_raw' => 'required', 'service.docker_compose_raw' => 'required',
@ -14,8 +15,14 @@ class StackForm extends Component
'service.name' => 'required', 'service.name' => 'required',
'service.description' => 'nullable', '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) public function saveCompose($raw)
{ {
$this->service->docker_compose_raw = $raw; $this->service->docker_compose_raw = $raw;
$this->submit(); $this->submit();
} }

View File

@ -453,15 +453,31 @@ public function parse(bool $isNew = false): Collection
'service_id' => $this->id, 'service_id' => $this->id,
])->first(); ])->first();
if ($value->startsWith('SERVICE_')) { if ($value->startsWith('SERVICE_')) {
$command = $value->after('SERVICE_')->beforeLast('_'); // Count _ in $value
$forService = $value->afterLast('_'); $count = substr_count($value->value(), '_');
$generatedValue = null; 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 ($command->value() === 'FQDN' || $command->value() === 'URL') {
if (Str::lower($forService) === $serviceName) { if (Str::lower($forService) === $serviceName) {
$fqdn = generateFqdn($this->server, $containerName); $fqdn = generateFqdn($this->server, $containerName);
} else { } else {
$fqdn = generateFqdn($this->server, Str::lower($forService) . '-' . $this->uuid); $fqdn = generateFqdn($this->server, Str::lower($forService) . '-' . $this->uuid);
} }
if ($port) {
$fqdn = "$fqdn:$port";
}
if ($foundEnv) { if ($foundEnv) {
$fqdn = data_get($foundEnv, 'value'); $fqdn = data_get($foundEnv, 'value');
} else { } else {
@ -477,7 +493,7 @@ public function parse(bool $isNew = false): Collection
]); ]);
} }
if (!$isDatabase) { if (!$isDatabase) {
if ($command->value() === 'FQDN') { if ($command->value() === 'FQDN' && is_null($savedService->fqdn)) {
$savedService->fqdn = $fqdn; $savedService->fqdn = $fqdn;
$savedService->save(); $savedService->save();
} }

View File

@ -85,7 +85,6 @@ function getFilesystemVolumesFromServer(ServiceApplication|ServiceDatabase $oneS
} else { } else {
$fileLocation = $path; $fileLocation = $path;
} }
ray($path,$fileLocation);
// Exists and is a file // Exists and is a file
$isFile = instant_remote_process(["test -f $fileLocation && echo OK || echo NOK"], $server); $isFile = instant_remote_process(["test -f $fileLocation && echo OK || echo NOK"], $server);
// Exists and is a directory // Exists and is a directory
@ -127,6 +126,7 @@ function getFilesystemVolumesFromServer(ServiceApplication|ServiceDatabase $oneS
function updateCompose($resource) function updateCompose($resource)
{ {
try { try {
ray($resource);
$name = data_get($resource, 'name'); $name = data_get($resource, 'name');
$dockerComposeRaw = data_get($resource, 'service.docker_compose_raw'); $dockerComposeRaw = data_get($resource, 'service.docker_compose_raw');
$dockerCompose = Yaml::parse($dockerComposeRaw); $dockerCompose = Yaml::parse($dockerComposeRaw);
@ -135,19 +135,21 @@ function updateCompose($resource)
$image = data_get($resource, 'image'); $image = data_get($resource, 'image');
data_set($dockerCompose, "services.{$name}.image", $image); data_set($dockerCompose, "services.{$name}.image", $image);
// Update FQDN if (!str($resource->fqdn)->contains(',')) {
$variableName = "SERVICE_FQDN_" . Str::of($resource->name)->upper(); // Update FQDN
$generatedEnv = EnvironmentVariable::where('service_id', $resource->service_id)->where('key', $variableName)->first(); $variableName = "SERVICE_FQDN_" . Str::of($resource->name)->upper();
if ($generatedEnv) { $generatedEnv = EnvironmentVariable::where('service_id', $resource->service_id)->where('key', $variableName)->first();
$generatedEnv->value = $resource->fqdn; if ($generatedEnv) {
$generatedEnv->save(); $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(); $variableName = "SERVICE_URL_" . Str::of($resource->name)->upper();
if ($generatedEnv) { $generatedEnv = EnvironmentVariable::where('service_id', $resource->service_id)->where('key', $variableName)->first();
$url = Str::of($resource->fqdn)->after('://'); if ($generatedEnv) {
$generatedEnv->value = $url; $url = Str::of($resource->fqdn)->after('://');
$generatedEnv->save(); $generatedEnv->value = $url;
$generatedEnv->save();
}
} }
$dockerComposeRaw = Yaml::dump($dockerCompose, 10, 2); $dockerComposeRaw = Yaml::dump($dockerCompose, 10, 2);

View File

@ -7,7 +7,7 @@
// The release version of your application // The release version of your application
// Example with dynamic git hash: trim(exec('git --git-dir ' . base_path('.git') . ' log --pretty="%h" -n1 HEAD')) // 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 // When left empty or `null` the Laravel environment will be used
'environment' => config('app.env'), 'environment' => config('app.env'),

View File

@ -1,3 +1,3 @@
<?php <?php
return '4.0.0-beta.122'; return '4.0.0-beta.123';

View File

@ -9,8 +9,12 @@
File</x-forms.button> File</x-forms.button>
</div> </div>
<div class="flex gap-2"> <div class="flex gap-2">
<x-forms.input id="service.name" required label="Service Name" <x-forms.input id="service.name" required label="Service Name" placeholder="My super wordpress site" />
placeholder="My super wordpress site" />
<x-forms.input id="service.description" label="Description" /> <x-forms.input id="service.description" label="Description" />
</div> </div>
@if ($isConfigurationRequired)
<div class="text-warning">This service requires additional confiugration. Please check our <a
href="https://coolify.io/docs" class="text-white underline">documentation</a> for further information.
</div>
@endif
</form> </form>

View File

@ -1,4 +1,3 @@
# ignore: true
# documentation: https://docs.min.io/docs/minio-docker-quickstart-guide.html # 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. # slogan: MinIO is a high performance object storage server compatible with Amazon S3 APIs.
# tags: object, storage, server, s3, api # tags: object, storage, server, s3, api
@ -8,12 +7,35 @@ services:
image: quay.io/minio/minio:latest image: quay.io/minio/minio:latest
command: server /data --console-address ":9001" command: server /data --console-address ":9001"
environment: environment:
- SERVICE_FQDN_MINIO_9000 - MINIO_SERVER_URL=$MINIO_SERVER_URL
- SERVICE_FQDN_CONSOLE_9001 - MINIO_BROWSER_REDIRECT_URL=$MINIO_BROWSER_REDIRECT_URL
- MINIO_DOMAIN=$SERVICE_URL_MINIO_9000
- MINIO_SERVER_URL=$SERVICE_FQDN_MINIO_9000
- MINIO_BROWSER_REDIRECT_URL=$SERVICE_FQDN_CONSOLE_9001
- MINIO_ROOT_USER=$SERVICE_USER_MINIO - MINIO_ROOT_USER=$SERVICE_USER_MINIO
- MINIO_ROOT_PASSWORD=$SERVICE_PASSWORD_MINIO - MINIO_ROOT_PASSWORD=$SERVICE_PASSWORD_MINIO
volumes: volumes:
- minio-data:/data - 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

View File

@ -300,6 +300,18 @@
"playlist" "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": { "moodle": {
"documentation": "https:\/\/moodle.org", "documentation": "https:\/\/moodle.org",
"slogan": "Moodle is the world\u2019s most customisable and trusted eLearning solution that empowers educators to improve our world.", "slogan": "Moodle is the world\u2019s most customisable and trusted eLearning solution that empowers educators to improve our world.",

View File

@ -4,7 +4,7 @@
"version": "3.12.36" "version": "3.12.36"
}, },
"v4": { "v4": {
"version": "4.0.0-beta.122" "version": "4.0.0-beta.123"
} }
} }
} }