Add docker_labels

This commit is contained in:
notCharles 2024-05-19 20:55:37 -04:00
parent 0c61a63191
commit 4c43fd1683
6 changed files with 73 additions and 62 deletions

View File

@ -329,10 +329,10 @@ class CreateServer extends CreateRecord
}) })
->selectablePlaceholder(false) ->selectablePlaceholder(false)
->columnSpan([ ->columnSpan([
'default' => 2, 'default' => 1,
'sm' => 2, 'sm' => 1,
'md' => 2, 'md' => 1,
'lg' => 3, 'lg' => 2,
]), ]),
Forms\Components\TextInput::make('image') Forms\Components\TextInput::make('image')
@ -352,10 +352,21 @@ class CreateServer extends CreateRecord
}) })
->placeholder('Enter a custom Image') ->placeholder('Enter a custom Image')
->columnSpan([ ->columnSpan([
'default' => 2, 'default' => 1,
'sm' => 2, 'sm' => 1,
'md' => 2, 'md' => 1,
'lg' => 3, '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') Forms\Components\Textarea::make('startup')

View File

@ -171,10 +171,10 @@ class EditServer extends EditRecord
}) })
->selectablePlaceholder(false) ->selectablePlaceholder(false)
->columnSpan([ ->columnSpan([
'default' => 2, 'default' => 1,
'sm' => 2, 'sm' => 1,
'md' => 2, 'md' => 1,
'lg' => 3, 'lg' => 2,
]), ]),
Forms\Components\TextInput::make('image') Forms\Components\TextInput::make('image')
@ -194,10 +194,21 @@ class EditServer extends EditRecord
}) })
->placeholder('Enter a custom Image') ->placeholder('Enter a custom Image')
->columnSpan([ ->columnSpan([
'default' => 2, 'default' => 1,
'sm' => 2, 'sm' => 1,
'md' => 2, 'md' => 1,
'lg' => 3, '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') Forms\Components\Textarea::make('startup')

View File

@ -184,6 +184,7 @@ class Server extends Model
self::UPDATED_AT => 'datetime', self::UPDATED_AT => 'datetime',
'deleted_at' => 'datetime', 'deleted_at' => 'datetime',
'installed_at' => 'datetime', 'installed_at' => 'datetime',
'docker_labels' => 'array',
]; ];
} }

View File

@ -81,7 +81,7 @@ class EggConfigurationService
{ {
// Get the legacy configuration structure for the server so that we // Get the legacy configuration structure for the server so that we
// can property map the egg placeholders to values. // can property map the egg placeholders to values.
$structure = $this->configurationStructureService->handle($server, [], true); $structure = $this->configurationStructureService->handle($server);
$response = []; $response = [];
// Normalize the output of the configuration for the new Daemon to more // Normalize the output of the configuration for the new Daemon to more

View File

@ -20,7 +20,7 @@ class ServerConfigurationStructureService
* DO NOT MODIFY THIS FUNCTION. This powers legacy code handling for the new daemon * DO NOT MODIFY THIS FUNCTION. This powers legacy code handling for the new daemon
* daemon, if you modify the structure eggs will break unexpectedly. * 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; $clone = $server;
// If any overrides have been set on this call make sure to update them on the // If any overrides have been set on this call make sure to update them on the
@ -32,15 +32,13 @@ class ServerConfigurationStructureService
} }
} }
return $legacy return $this->returnFormat($clone);
? $this->returnLegacyFormat($clone)
: $this->returnCurrentFormat($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 [ return [
'uuid' => $server->uuid, 'uuid' => $server->uuid,
@ -59,13 +57,12 @@ class ServerConfigurationStructureService
'cpu_limit' => $server->cpu, 'cpu_limit' => $server->cpu,
'threads' => $server->threads, 'threads' => $server->threads,
'disk_space' => $server->disk, 'disk_space' => $server->disk,
// This field is deprecated — use "oom_killer".
'oom_disabled' => !$server->oom_killer,
'oom_killer' => $server->oom_killer, 'oom_killer' => $server->oom_killer,
], ],
'container' => [ 'container' => [
'image' => $server->image, 'image' => $server->image,
'requires_rebuild' => false, 'requires_rebuild' => false,
'labels' => $server->docker_labels,
], ],
'allocations' => [ 'allocations' => [
'force_outgoing_ip' => $server->egg->force_outgoing_ip, '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,
];
}
} }

View File

@ -0,0 +1,28 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
/**
* Run the migrations.
*/
public function up(): void
{
Schema::table('servers', function (Blueprint $table) {
$table->text('docker_labels')->default('[]');
});
}
/**
* Reverse the migrations.
*/
public function down(): void
{
Schema::table('servers', function (Blueprint $table) {
$table->dropColumn('docker_labels');
});
}
};