Fill startup & image from egg if missing in request (#384)

This commit is contained in:
Boy132 2024-06-13 15:48:36 +02:00 committed by GitHub
parent 0da184c56e
commit 6916b89638
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 16 additions and 4 deletions

View File

@ -28,8 +28,8 @@ class StoreServerRequest extends ApplicationApiRequest
'description' => array_merge(['nullable'], $rules['description']),
'user' => $rules['owner_id'],
'egg' => $rules['egg_id'],
'docker_image' => $rules['image'],
'startup' => $rules['startup'],
'docker_image' => 'sometimes|string',
'startup' => 'sometimes|string',
'environment' => 'present|array',
'skip_scripts' => 'sometimes|boolean',
'oom_killer' => 'sometimes|boolean',

View File

@ -20,10 +20,10 @@ class UpdateServerStartupRequest extends ApplicationApiRequest
$data = Server::getRulesForUpdate($this->parameter('server', Server::class));
return [
'startup' => $data['startup'],
'startup' => 'sometimes|string',
'environment' => 'present|array',
'egg' => $data['egg_id'],
'image' => $data['image'],
'image' => 'sometimes|string',
'skip_scripts' => 'present|boolean',
];
}

View File

@ -17,6 +17,7 @@ use App\Repositories\Daemon\DaemonServerRepository;
use App\Services\Deployment\FindViableNodesService;
use App\Services\Deployment\AllocationSelectionService;
use App\Exceptions\Http\Connection\DaemonConnectionException;
use App\Models\Egg;
class ServerCreationService
{
@ -50,6 +51,13 @@ class ServerCreationService
$data['oom_killer'] = !$data['oom_disabled'];
}
/** @var Egg $egg */
$egg = Egg::query()->findOrFail($data['egg_id']);
// Fill missing fields from egg
$data['image'] = $data['image'] ?? collect($egg->docker_images)->first();
$data['startup'] = $data['startup'] ?? $egg->startup;
// If a deployment object has been passed we need to get the allocation
// that the server should use, and assign the node from that allocation.
if ($deployment instanceof DeploymentObject) {

View File

@ -76,6 +76,10 @@ class StartupModificationService
$server = $server->forceFill([
'egg_id' => $egg->id,
]);
// Fill missing fields from egg
$data['docker_image'] = $data['docker_image'] ?? collect($egg->docker_images)->first();
$data['startup'] = $data['startup'] ?? $egg->startup;
}
$server->fill([