From 728adfe388941908e1db8f117233b0580a3a26c6 Mon Sep 17 00:00:00 2001 From: Matthew Penner Date: Mon, 1 Nov 2021 12:23:06 -0600 Subject: [PATCH] server(startup): make startup nullable; resolves #3721 --- app/Models/Server.php | 3 +- .../ServerConfigurationStructureService.php | 7 +--- .../Servers/StartupCommandService.php | 2 +- ...tartup_field_nullable_on_servers_table.php | 32 +++++++++++++++++++ resources/scripts/api/admin/server.ts | 2 +- .../api/admin/servers/updateServerStartup.ts | 2 +- .../admin/servers/NewServerContainer.tsx | 2 +- .../admin/servers/ServerStartupContainer.tsx | 7 ++-- 8 files changed, 43 insertions(+), 14 deletions(-) create mode 100644 database/migrations/2021_11_01_180130_make_startup_field_nullable_on_servers_table.php diff --git a/app/Models/Server.php b/app/Models/Server.php index 010040f5b..ecc6253c5 100644 --- a/app/Models/Server.php +++ b/app/Models/Server.php @@ -40,6 +40,7 @@ class Server extends Model protected $attributes = [ 'status' => self::STATUS_INSTALLING, 'oom_disabled' => true, + 'startup' => null, ]; /** @@ -80,7 +81,7 @@ class Server extends Model 'allocation_id' => 'required|bail|unique:servers|exists:allocations,id', 'nest_id' => 'required|exists:nests,id', 'egg_id' => 'required|exists:eggs,id', - 'startup' => 'required|string', + 'startup' => 'nullable|string', 'skip_scripts' => 'sometimes|boolean', 'image' => 'required|string|max:191', 'database_limit' => 'present|nullable|integer|min:0', diff --git a/app/Services/Servers/ServerConfigurationStructureService.php b/app/Services/Servers/ServerConfigurationStructureService.php index 8d68d7de8..c675f855e 100644 --- a/app/Services/Servers/ServerConfigurationStructureService.php +++ b/app/Services/Servers/ServerConfigurationStructureService.php @@ -49,7 +49,7 @@ class ServerConfigurationStructureService 'uuid' => $server->uuid, 'suspended' => $server->isSuspended(), 'environment' => $this->environment->handle($server), - 'invocation' => $server->startup, + 'invocation' => !is_null($server->startup) ? $server->startup : $server->egg->startup, 'skip_egg_scripts' => $server->skip_scripts, 'build' => [ 'memory_limit' => $server->memory, @@ -62,11 +62,6 @@ class ServerConfigurationStructureService ], 'container' => [ 'image' => $server->image, - // This field is deprecated — use the value in the "build" block. - // - // TODO: remove this key in V2. - 'oom_disabled' => $server->oom_disabled, - 'requires_rebuild' => false, ], 'allocations' => [ 'default' => [ diff --git a/app/Services/Servers/StartupCommandService.php b/app/Services/Servers/StartupCommandService.php index 62c06c94f..b8e2d210a 100644 --- a/app/Services/Servers/StartupCommandService.php +++ b/app/Services/Servers/StartupCommandService.php @@ -20,6 +20,6 @@ class StartupCommandService $replace[] = ($variable->user_viewable && !$hideAllValues) ? ($variable->server_value ?? $variable->default_value) : '[hidden]'; } - return str_replace($find, $replace, $server->startup); + return str_replace($find, $replace, !is_null($server->startup) ? $server->startup : $server->egg->startup); } } diff --git a/database/migrations/2021_11_01_180130_make_startup_field_nullable_on_servers_table.php b/database/migrations/2021_11_01_180130_make_startup_field_nullable_on_servers_table.php new file mode 100644 index 000000000..7cd0f1002 --- /dev/null +++ b/database/migrations/2021_11_01_180130_make_startup_field_nullable_on_servers_table.php @@ -0,0 +1,32 @@ +text('startup')->default(null)->nullable()->change(); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::table('servers', function (Blueprint $table) { + $table->text('startup')->change(); + }); + } +} diff --git a/resources/scripts/api/admin/server.ts b/resources/scripts/api/admin/server.ts index 3d0cc1524..f32a4fa59 100644 --- a/resources/scripts/api/admin/server.ts +++ b/resources/scripts/api/admin/server.ts @@ -50,7 +50,7 @@ export interface Server extends Model { backups: number; }; container: { - startup: string; + startup: string | null; image: string; environment: Record; }; diff --git a/resources/scripts/api/admin/servers/updateServerStartup.ts b/resources/scripts/api/admin/servers/updateServerStartup.ts index 33f598f1d..7dec26e30 100644 --- a/resources/scripts/api/admin/servers/updateServerStartup.ts +++ b/resources/scripts/api/admin/servers/updateServerStartup.ts @@ -14,7 +14,7 @@ export default (id: number, values: Partial, include: string[] = []): Pr http.patch( `/api/application/servers/${id}/startup`, { - startup: values.startup, + startup: values.startup !== '' ? values.startup : null, environment: values.environment, egg_id: values.eggId, image: values.image, diff --git a/resources/scripts/components/admin/servers/NewServerContainer.tsx b/resources/scripts/components/admin/servers/NewServerContainer.tsx index bdc13728e..d5b37df5b 100644 --- a/resources/scripts/components/admin/servers/NewServerContainer.tsx +++ b/resources/scripts/components/admin/servers/NewServerContainer.tsx @@ -36,7 +36,7 @@ function InternalForm () { } setFieldValue('eggId', egg.id); - setFieldValue('startup', egg.startup); + setFieldValue('startup', ''); setFieldValue('image', egg.dockerImages.length > 0 ? egg.dockerImages[0] : ''); }, [ egg ]); diff --git a/resources/scripts/components/admin/servers/ServerStartupContainer.tsx b/resources/scripts/components/admin/servers/ServerStartupContainer.tsx index 0a5039034..702b21c04 100644 --- a/resources/scripts/components/admin/servers/ServerStartupContainer.tsx +++ b/resources/scripts/components/admin/servers/ServerStartupContainer.tsx @@ -27,12 +27,12 @@ function ServerStartupLineContainer ({ egg, server }: { egg: Egg | null; server: } if (server.eggId === egg.id) { - setFieldValue('startup', server.container.startup); + setFieldValue('startup', server.container.startup || ''); return; } // Whenever the egg is changed, set the server's startup command to the egg's default. - setFieldValue('startup', egg.startup); + setFieldValue('startup', ''); }, [ egg ]); return ( @@ -46,6 +46,7 @@ function ServerStartupLineContainer ({ egg, server }: { egg: Egg | null; server: label={'Startup Command'} type={'text'} description={'Edit your server\'s startup command here. The following variables are available by default: {{SERVER_MEMORY}}, {{SERVER_IP}}, and {{SERVER_PORT}}.'} + placeholder={egg?.startup || ''} /> @@ -212,7 +213,7 @@ export default () => { , image: server.container.image, eggId: server.eggId,