diff --git a/app/Filament/Resources/ServerResource/Pages/CreateServer.php b/app/Filament/Resources/ServerResource/Pages/CreateServer.php index c03de3fce..c93efd379 100644 --- a/app/Filament/Resources/ServerResource/Pages/CreateServer.php +++ b/app/Filament/Resources/ServerResource/Pages/CreateServer.php @@ -329,10 +329,10 @@ class CreateServer extends CreateRecord }) ->selectablePlaceholder(false) ->columnSpan([ - 'default' => 2, - 'sm' => 2, - 'md' => 2, - 'lg' => 3, + 'default' => 1, + 'sm' => 1, + 'md' => 1, + 'lg' => 2, ]), Forms\Components\TextInput::make('image') @@ -352,10 +352,21 @@ class CreateServer extends CreateRecord }) ->placeholder('Enter a custom Image') ->columnSpan([ - 'default' => 2, - 'sm' => 2, - 'md' => 2, - 'lg' => 3, + 'default' => 1, + 'sm' => 1, + 'md' => 1, + 'lg' => 2, + ]), + + Forms\Components\TagsInput::make('docker_labels') + ->label('Docker Labels') + ->live() + ->placeholder('Enter custom Docker container labels') + ->columnSpan([ + 'default' => 1, + 'sm' => 1, + 'md' => 1, + 'lg' => 2, ]), Forms\Components\Textarea::make('startup') diff --git a/app/Filament/Resources/ServerResource/Pages/EditServer.php b/app/Filament/Resources/ServerResource/Pages/EditServer.php index 7438782b2..0abc740b2 100644 --- a/app/Filament/Resources/ServerResource/Pages/EditServer.php +++ b/app/Filament/Resources/ServerResource/Pages/EditServer.php @@ -171,10 +171,10 @@ class EditServer extends EditRecord }) ->selectablePlaceholder(false) ->columnSpan([ - 'default' => 2, - 'sm' => 2, - 'md' => 2, - 'lg' => 3, + 'default' => 1, + 'sm' => 1, + 'md' => 1, + 'lg' => 2, ]), Forms\Components\TextInput::make('image') @@ -194,10 +194,21 @@ class EditServer extends EditRecord }) ->placeholder('Enter a custom Image') ->columnSpan([ - 'default' => 2, - 'sm' => 2, - 'md' => 2, - 'lg' => 3, + 'default' => 1, + 'sm' => 1, + 'md' => 1, + 'lg' => 2, + ]), + + Forms\Components\TagsInput::make('docker_labels') + ->label('Docker Labels') + ->live() + ->placeholder('Enter custom Docker container labels') + ->columnSpan([ + 'default' => 1, + 'sm' => 1, + 'md' => 1, + 'lg' => 2, ]), Forms\Components\Textarea::make('startup') diff --git a/app/Models/Server.php b/app/Models/Server.php index 2a60c3822..3c4657343 100644 --- a/app/Models/Server.php +++ b/app/Models/Server.php @@ -184,6 +184,7 @@ class Server extends Model self::UPDATED_AT => 'datetime', 'deleted_at' => 'datetime', 'installed_at' => 'datetime', + 'docker_labels' => 'array', ]; } diff --git a/app/Services/Eggs/EggConfigurationService.php b/app/Services/Eggs/EggConfigurationService.php index 5ae5b6518..5280688ee 100644 --- a/app/Services/Eggs/EggConfigurationService.php +++ b/app/Services/Eggs/EggConfigurationService.php @@ -81,7 +81,7 @@ class EggConfigurationService { // Get the legacy configuration structure for the server so that we // can property map the egg placeholders to values. - $structure = $this->configurationStructureService->handle($server, [], true); + $structure = $this->configurationStructureService->handle($server); $response = []; // Normalize the output of the configuration for the new Daemon to more diff --git a/app/Services/Servers/ServerConfigurationStructureService.php b/app/Services/Servers/ServerConfigurationStructureService.php index 535f4b439..75fae45e0 100644 --- a/app/Services/Servers/ServerConfigurationStructureService.php +++ b/app/Services/Servers/ServerConfigurationStructureService.php @@ -20,7 +20,7 @@ class ServerConfigurationStructureService * DO NOT MODIFY THIS FUNCTION. This powers legacy code handling for the new daemon * daemon, if you modify the structure eggs will break unexpectedly. */ - public function handle(Server $server, array $override = [], bool $legacy = false): array + public function handle(Server $server, array $override = []): array { $clone = $server; // If any overrides have been set on this call make sure to update them on the @@ -32,15 +32,13 @@ class ServerConfigurationStructureService } } - return $legacy - ? $this->returnLegacyFormat($clone) - : $this->returnCurrentFormat($clone); + return $this->returnFormat($clone); } /** - * Returns the new data format used for the daemon. + * Returns the data format used for the daemon. */ - protected function returnCurrentFormat(Server $server): array + protected function returnFormat(Server $server): array { return [ 'uuid' => $server->uuid, @@ -59,13 +57,12 @@ class ServerConfigurationStructureService 'cpu_limit' => $server->cpu, 'threads' => $server->threads, 'disk_space' => $server->disk, - // This field is deprecated — use "oom_killer". - 'oom_disabled' => !$server->oom_killer, 'oom_killer' => $server->oom_killer, ], 'container' => [ 'image' => $server->image, 'requires_rebuild' => false, + 'labels' => $server->docker_labels, ], 'allocations' => [ 'force_outgoing_ip' => $server->egg->force_outgoing_ip, @@ -88,41 +85,4 @@ class ServerConfigurationStructureService ], ]; } - - /** - * Returns the legacy server data format to continue support for old egg configurations - * that have not yet been updated. - * - * @deprecated - */ - protected function returnLegacyFormat(Server $server): array - { - return [ - 'uuid' => $server->uuid, - 'build' => [ - 'default' => [ - 'ip' => $server->allocation->ip, - 'port' => $server->allocation->port, - ], - 'ports' => $server->allocations->groupBy('ip')->map(function ($item) { - return $item->pluck('port'); - })->toArray(), - 'env' => $this->environment->handle($server), - 'oom_disabled' => !$server->oom_killer, - 'memory' => (int) $server->memory, - 'swap' => (int) $server->swap, - 'io' => (int) $server->io, - 'cpu' => (int) $server->cpu, - 'threads' => $server->threads, - 'disk' => (int) $server->disk, - 'image' => $server->image, - ], - 'service' => [ - 'egg' => $server->egg->uuid, - 'skip_scripts' => $server->skip_scripts, - ], - 'rebuild' => false, - 'suspended' => $server->isSuspended() ? 1 : 0, - ]; - } } diff --git a/database/migrations/2024_05_20_002841_add_docker_container_label.php b/database/migrations/2024_05_20_002841_add_docker_container_label.php new file mode 100644 index 000000000..eea5f02b4 --- /dev/null +++ b/database/migrations/2024_05_20_002841_add_docker_container_label.php @@ -0,0 +1,28 @@ +text('docker_labels')->default('[]'); + }); + } + + /** + * Reverse the migrations. + */ + public function down(): void + { + Schema::table('servers', function (Blueprint $table) { + $table->dropColumn('docker_labels'); + }); + } +};