wip: services

This commit is contained in:
Andras Bacsai 2023-09-22 20:39:56 +02:00
parent 0c30b6222d
commit 3fc78bc760
3 changed files with 7 additions and 13 deletions

View File

@ -12,6 +12,7 @@ class StartService
{ {
$workdir = service_configuration_dir() . "/{$service->uuid}"; $workdir = service_configuration_dir() . "/{$service->uuid}";
$commands[] = "echo '####### Starting service {$service->name} on {$service->server->name}.'"; $commands[] = "echo '####### Starting service {$service->name} on {$service->server->name}.'";
$commands[] = "echo '####### Pulling images.'";
$commands[] = "mkdir -p $workdir"; $commands[] = "mkdir -p $workdir";
$commands[] = "cd $workdir"; $commands[] = "cd $workdir";
@ -22,7 +23,6 @@ class StartService
foreach ($envs as $env) { foreach ($envs as $env) {
$commands[] = "echo '{$env->key}={$env->value}' >> .env"; $commands[] = "echo '{$env->key}={$env->value}' >> .env";
} }
$commands[] = "echo '####### Pulling images.'";
$commands[] = "docker compose pull --quiet"; $commands[] = "docker compose pull --quiet";
$commands[] = "echo '####### Starting containers.'"; $commands[] = "echo '####### Starting containers.'";
$commands[] = "docker compose up -d >/dev/null 2>&1"; $commands[] = "docker compose up -d >/dev/null 2>&1";

View File

@ -157,7 +157,7 @@ class ContainerStatusJob implements ShouldQueue, ShouldBeEncrypted
$foundServices[] = "$foundService->id-$serviceName"; $foundServices[] = "$foundService->id-$serviceName";
$statusFromDb = $foundService->status; $statusFromDb = $foundService->status;
if ($statusFromDb !== $containerStatus) { if ($statusFromDb !== $containerStatus) {
ray('Updating status: ' . $containerStatus); // ray('Updating status: ' . $containerStatus);
$foundService->update(['status' => $containerStatus]); $foundService->update(['status' => $containerStatus]);
} }
} }
@ -169,14 +169,14 @@ class ContainerStatusJob implements ShouldQueue, ShouldBeEncrypted
$apps = $service->applications()->get(); $apps = $service->applications()->get();
$dbs = $service->databases()->get(); $dbs = $service->databases()->get();
foreach ($apps as $app) { foreach ($apps as $app) {
if (in_array("$service->id-$app->name", $foundServices)) { if (in_array("$app->id-$app->name", $foundServices)) {
continue; continue;
} else { } else {
$exitedServices->push($app); $exitedServices->push($app);
} }
} }
foreach ($dbs as $db) { foreach ($dbs as $db) {
if (in_array("$service->id-$db->name", $foundServices)) { if (in_array("$db->id-$db->name", $foundServices)) {
continue; continue;
} else { } else {
$exitedServices->push($db); $exitedServices->push($db);

View File

@ -117,15 +117,10 @@ class Service extends BaseModel
'service_id' => $this->id 'service_id' => $this->id
]); ]);
} else { } else {
if (Str::of($serviceVariables)->contains('SERVICE_FQDN') || Str::of($serviceVariables)->contains('SERVICE_URL')) { $defaultUsableFqdn = "http://$serviceName-{$this->uuid}.{$this->server->ip}.sslip.io";
$defaultUsableFqdn = "http://$serviceName-{$this->uuid}.{$this->server->ip}.sslip.io"; if (isDev()) {
if (isDev()) { $defaultUsableFqdn = "http://$serviceName-{$this->uuid}.127.0.0.1.sslip.io";
$defaultUsableFqdn = "http://$serviceName-{$this->uuid}.127.0.0.1.sslip.io";
}
} else {
$defaultUsableFqdn = null;
} }
$savedService = ServiceApplication::create([ $savedService = ServiceApplication::create([
'name' => $serviceName, 'name' => $serviceName,
'fqdn' => $defaultUsableFqdn, 'fqdn' => $defaultUsableFqdn,
@ -155,7 +150,6 @@ class Service extends BaseModel
if ($fqdns) { if ($fqdns) {
$fqdns = collect(Str::of($fqdns)->explode(',')); $fqdns = collect(Str::of($fqdns)->explode(','));
} }
ray($fqdns);
// Collect ports // Collect ports
$servicePorts = collect(data_get($service, 'ports', [])); $servicePorts = collect(data_get($service, 'ports', []));
$ports->put($serviceName, $servicePorts); $ports->put($serviceName, $servicePorts);