Skip to content

Commit 10ca408

Browse files
committed
fix: is_static settings through API
fix: validation rules
1 parent d031911 commit 10ca408

File tree

3 files changed

+58
-31
lines changed

3 files changed

+58
-31
lines changed

app/Enums/StaticImageTypes.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<?php
2+
3+
namespace App\Enums;
4+
5+
enum StaticImageTypes: string
6+
{
7+
case NGINX_ALPINE = 'nginx:alpine';
8+
}

app/Http/Controllers/Api/ApplicationsController.php

Lines changed: 47 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,7 @@ public function applications(Request $request)
132132
'docker_registry_image_name' => ['type' => 'string', 'description' => 'The docker registry image name.'],
133133
'docker_registry_image_tag' => ['type' => 'string', 'description' => 'The docker registry image tag.'],
134134
'is_static' => ['type' => 'boolean', 'description' => 'The flag to indicate if the application is static.'],
135+
'static_image' => ['type' => 'string', 'enum' => ['nginx:alpine'], 'description' => 'The static image.'],
135136
'install_command' => ['type' => 'string', 'description' => 'The install command.'],
136137
'build_command' => ['type' => 'string', 'description' => 'The build command.'],
137138
'start_command' => ['type' => 'string', 'description' => 'The start command.'],
@@ -236,6 +237,7 @@ public function create_public_application(Request $request)
236237
'docker_registry_image_name' => ['type' => 'string', 'description' => 'The docker registry image name.'],
237238
'docker_registry_image_tag' => ['type' => 'string', 'description' => 'The docker registry image tag.'],
238239
'is_static' => ['type' => 'boolean', 'description' => 'The flag to indicate if the application is static.'],
240+
'static_image' => ['type' => 'string', 'enum' => ['nginx:alpine'], 'description' => 'The static image.'],
239241
'install_command' => ['type' => 'string', 'description' => 'The install command.'],
240242
'build_command' => ['type' => 'string', 'description' => 'The build command.'],
241243
'start_command' => ['type' => 'string', 'description' => 'The start command.'],
@@ -339,6 +341,7 @@ public function create_private_gh_app_application(Request $request)
339341
'docker_registry_image_name' => ['type' => 'string', 'description' => 'The docker registry image name.'],
340342
'docker_registry_image_tag' => ['type' => 'string', 'description' => 'The docker registry image tag.'],
341343
'is_static' => ['type' => 'boolean', 'description' => 'The flag to indicate if the application is static.'],
344+
'static_image' => ['type' => 'string', 'enum' => ['nginx:alpine'], 'description' => 'The static image.'],
342345
'install_command' => ['type' => 'string', 'description' => 'The install command.'],
343346
'build_command' => ['type' => 'string', 'description' => 'The build command.'],
344347
'start_command' => ['type' => 'string', 'description' => 'The start command.'],
@@ -633,7 +636,7 @@ public function create_dockercompose_application(Request $request)
633636

634637
private function create_application(Request $request, $type)
635638
{
636-
$allowedFields = ['project_uuid', 'environment_name', 'server_uuid', 'destination_uuid', 'type', 'name', 'description', 'is_static', 'domains', 'git_repository', 'git_branch', 'git_commit_sha', 'private_key_uuid', 'docker_registry_image_name', 'docker_registry_image_tag', 'build_pack', 'install_command', 'build_command', 'start_command', 'ports_exposes', 'ports_mappings', 'base_directory', 'publish_directory', 'health_check_enabled', 'health_check_path', 'health_check_port', 'health_check_host', 'health_check_method', 'health_check_return_code', 'health_check_scheme', 'health_check_response_text', 'health_check_interval', 'health_check_timeout', 'health_check_retries', 'health_check_start_period', 'limits_memory', 'limits_memory_swap', 'limits_memory_swappiness', 'limits_memory_reservation', 'limits_cpus', 'limits_cpuset', 'limits_cpu_shares', 'custom_labels', 'custom_docker_run_options', 'post_deployment_command', 'post_deployment_command_container', 'pre_deployment_command', 'pre_deployment_command_container', 'manual_webhook_secret_github', 'manual_webhook_secret_gitlab', 'manual_webhook_secret_bitbucket', 'manual_webhook_secret_gitea', 'redirect', 'github_app_uuid', 'instant_deploy', 'dockerfile', 'docker_compose_location', 'docker_compose_raw', 'docker_compose_custom_start_command', 'docker_compose_custom_build_command', 'docker_compose_domains', 'watch_paths', 'use_build_server'];
639+
$allowedFields = ['project_uuid', 'environment_name', 'server_uuid', 'destination_uuid', 'type', 'name', 'description', 'is_static', 'domains', 'git_repository', 'git_branch', 'git_commit_sha', 'private_key_uuid', 'docker_registry_image_name', 'docker_registry_image_tag', 'build_pack', 'install_command', 'build_command', 'start_command', 'ports_exposes', 'ports_mappings', 'base_directory', 'publish_directory', 'health_check_enabled', 'health_check_path', 'health_check_port', 'health_check_host', 'health_check_method', 'health_check_return_code', 'health_check_scheme', 'health_check_response_text', 'health_check_interval', 'health_check_timeout', 'health_check_retries', 'health_check_start_period', 'limits_memory', 'limits_memory_swap', 'limits_memory_swappiness', 'limits_memory_reservation', 'limits_cpus', 'limits_cpuset', 'limits_cpu_shares', 'custom_labels', 'custom_docker_run_options', 'post_deployment_command', 'post_deployment_command_container', 'pre_deployment_command', 'pre_deployment_command_container', 'manual_webhook_secret_github', 'manual_webhook_secret_gitlab', 'manual_webhook_secret_bitbucket', 'manual_webhook_secret_gitea', 'redirect', 'github_app_uuid', 'instant_deploy', 'dockerfile', 'docker_compose_location', 'docker_compose_raw', 'docker_compose_custom_start_command', 'docker_compose_custom_build_command', 'docker_compose_domains', 'watch_paths', 'use_build_server', 'static_image'];
637640
$teamId = getTeamIdFromToken();
638641
if (is_null($teamId)) {
639642
return invalidTokenResponse();
@@ -672,6 +675,7 @@ private function create_application(Request $request, $type)
672675
$instantDeploy = $request->instant_deploy;
673676
$githubAppUuid = $request->github_app_uuid;
674677
$useBuildServer = $request->use_build_server;
678+
$isStatic = $request->is_static;
675679

676680
$project = Project::whereTeamId($teamId)->whereUuid($request->project_uuid)->first();
677681
if (! $project) {
@@ -700,28 +704,29 @@ private function create_application(Request $request, $type)
700704
if ($request->build_pack === 'dockercompose') {
701705
$request->offsetSet('ports_exposes', '80');
702706
}
703-
$validator = customApiValidator($request->all(), [
704-
sharedDataApplications(),
707+
$validationRules = [
705708
'git_repository' => 'string|required',
706709
'git_branch' => 'string|required',
707710
'build_pack' => ['required', Rule::enum(BuildPackTypes::class)],
708711
'ports_exposes' => 'string|regex:/^(\d+)(,\d+)*$/|required',
709712
'docker_compose_location' => 'string',
710713
'docker_compose_raw' => 'string|nullable',
711714
'docker_compose_domains' => 'array|nullable',
712-
'docker_compose_custom_start_command' => 'string|nullable',
713-
'docker_compose_custom_build_command' => 'string|nullable',
714-
]);
715+
];
716+
$validationRules = array_merge($validationRules, sharedDataApplications());
717+
$validator = customApiValidator($request->all(), $validationRules);
715718
if ($validator->fails()) {
716719
return response()->json([
717720
'message' => 'Validation failed.',
718721
'errors' => $validator->errors(),
719722
], 422);
720723
}
724+
721725
$return = $this->validateDataApplications($request, $server);
722726
if ($return instanceof \Illuminate\Http\JsonResponse) {
723727
return $return;
724728
}
729+
725730
$application = new Application;
726731
removeUnnecessaryFieldsFromRequest($request);
727732

@@ -744,11 +749,15 @@ private function create_application(Request $request, $type)
744749
$application->destination_id = $destination->id;
745750
$application->destination_type = $destination->getMorphClass();
746751
$application->environment_id = $environment->id;
752+
$application->save();
753+
if (isset($isStatic)) {
754+
$application->settings->is_static = $isStatic;
755+
$application->settings->save();
756+
}
747757
if (isset($useBuildServer)) {
748758
$application->settings->is_build_server_enabled = $useBuildServer;
749759
$application->settings->save();
750760
}
751-
$application->save();
752761
$application->refresh();
753762
if (! $application->settings->is_container_label_readonly_enabled) {
754763
$application->custom_labels = str(implode('|coolify|', generateLabelsApplication($application)))->replace('|coolify|', "\n");
@@ -782,8 +791,7 @@ private function create_application(Request $request, $type)
782791
if ($request->build_pack === 'dockercompose') {
783792
$request->offsetSet('ports_exposes', '80');
784793
}
785-
$validator = customApiValidator($request->all(), [
786-
sharedDataApplications(),
794+
$validationRules = [
787795
'git_repository' => 'string|required',
788796
'git_branch' => 'string|required',
789797
'build_pack' => ['required', Rule::enum(BuildPackTypes::class)],
@@ -792,10 +800,10 @@ private function create_application(Request $request, $type)
792800
'watch_paths' => 'string|nullable',
793801
'docker_compose_location' => 'string',
794802
'docker_compose_raw' => 'string|nullable',
795-
'docker_compose_domains' => 'array|nullable',
796-
'docker_compose_custom_start_command' => 'string|nullable',
797-
'docker_compose_custom_build_command' => 'string|nullable',
798-
]);
803+
];
804+
$validationRules = array_merge($validationRules, sharedDataApplications());
805+
806+
$validator = customApiValidator($request->all(), $validationRules);
799807
if ($validator->fails()) {
800808
return response()->json([
801809
'message' => 'Validation failed.',
@@ -882,8 +890,8 @@ private function create_application(Request $request, $type)
882890
if ($request->build_pack === 'dockercompose') {
883891
$request->offsetSet('ports_exposes', '80');
884892
}
885-
$validator = customApiValidator($request->all(), [
886-
sharedDataApplications(),
893+
894+
$validationRules = [
887895
'git_repository' => 'string|required',
888896
'git_branch' => 'string|required',
889897
'build_pack' => ['required', Rule::enum(BuildPackTypes::class)],
@@ -892,10 +900,10 @@ private function create_application(Request $request, $type)
892900
'watch_paths' => 'string|nullable',
893901
'docker_compose_location' => 'string',
894902
'docker_compose_raw' => 'string|nullable',
895-
'docker_compose_domains' => 'array|nullable',
896-
'docker_compose_custom_start_command' => 'string|nullable',
897-
'docker_compose_custom_build_command' => 'string|nullable',
898-
]);
903+
];
904+
905+
$validationRules = array_merge($validationRules, sharedDataApplications());
906+
$validator = customApiValidator($request->all(), $validationRules);
899907

900908
if ($validator->fails()) {
901909
return response()->json([
@@ -975,10 +983,13 @@ private function create_application(Request $request, $type)
975983
if (! $request->has('name')) {
976984
$request->offsetSet('name', 'dockerfile-'.new Cuid2);
977985
}
978-
$validator = customApiValidator($request->all(), [
979-
sharedDataApplications(),
986+
987+
$validationRules = [
980988
'dockerfile' => 'string|required',
981-
]);
989+
];
990+
$validationRules = array_merge($validationRules, sharedDataApplications());
991+
$validator = customApiValidator($request->all(), $validationRules);
992+
982993
if ($validator->fails()) {
983994
return response()->json([
984995
'message' => 'Validation failed.',
@@ -1057,12 +1068,14 @@ private function create_application(Request $request, $type)
10571068
if (! $request->has('name')) {
10581069
$request->offsetSet('name', 'docker-image-'.new Cuid2);
10591070
}
1060-
$validator = customApiValidator($request->all(), [
1061-
sharedDataApplications(),
1071+
$validationRules = [
10621072
'docker_registry_image_name' => 'string|required',
10631073
'docker_registry_image_tag' => 'string',
10641074
'ports_exposes' => 'string|regex:/^(\d+)(,\d+)*$/|required',
1065-
]);
1075+
];
1076+
$validationRules = array_merge($validationRules, sharedDataApplications());
1077+
$validator = customApiValidator($request->all(), $validationRules);
1078+
10661079
if ($validator->fails()) {
10671080
return response()->json([
10681081
'message' => 'Validation failed.',
@@ -1135,10 +1148,12 @@ private function create_application(Request $request, $type)
11351148
if (! $request->has('name')) {
11361149
$request->offsetSet('name', 'service'.new Cuid2);
11371150
}
1138-
$validator = customApiValidator($request->all(), [
1139-
sharedDataApplications(),
1151+
$validationRules = [
11401152
'docker_compose_raw' => 'string|required',
1141-
]);
1153+
];
1154+
$validationRules = array_merge($validationRules, sharedDataApplications());
1155+
$validator = customApiValidator($request->all(), $validationRules);
1156+
11421157
if ($validator->fails()) {
11431158
return response()->json([
11441159
'message' => 'Validation failed.',
@@ -1488,8 +1503,7 @@ public function update_by_uuid(Request $request)
14881503
$server = $application->destination->server;
14891504
$allowedFields = ['name', 'description', 'is_static', 'domains', 'git_repository', 'git_branch', 'git_commit_sha', 'docker_registry_image_name', 'docker_registry_image_tag', 'build_pack', 'static_image', 'install_command', 'build_command', 'start_command', 'ports_exposes', 'ports_mappings', 'base_directory', 'publish_directory', 'health_check_enabled', 'health_check_path', 'health_check_port', 'health_check_host', 'health_check_method', 'health_check_return_code', 'health_check_scheme', 'health_check_response_text', 'health_check_interval', 'health_check_timeout', 'health_check_retries', 'health_check_start_period', 'limits_memory', 'limits_memory_swap', 'limits_memory_swappiness', 'limits_memory_reservation', 'limits_cpus', 'limits_cpuset', 'limits_cpu_shares', 'custom_labels', 'custom_docker_run_options', 'post_deployment_command', 'post_deployment_command_container', 'pre_deployment_command', 'pre_deployment_command_container', 'watch_paths', 'manual_webhook_secret_github', 'manual_webhook_secret_gitlab', 'manual_webhook_secret_bitbucket', 'manual_webhook_secret_gitea', 'docker_compose_location', 'docker_compose_raw', 'docker_compose_custom_start_command', 'docker_compose_custom_build_command', 'docker_compose_domains', 'redirect', 'instant_deploy', 'use_build_server'];
14901505

1491-
$validator = customApiValidator($request->all(), [
1492-
sharedDataApplications(),
1506+
$validationRules = [
14931507
'name' => 'string|max:255',
14941508
'description' => 'string|nullable',
14951509
'static_image' => 'string',
@@ -1499,7 +1513,9 @@ public function update_by_uuid(Request $request)
14991513
'docker_compose_domains' => 'array|nullable',
15001514
'docker_compose_custom_start_command' => 'string|nullable',
15011515
'docker_compose_custom_build_command' => 'string|nullable',
1502-
]);
1516+
];
1517+
$validationRules = array_merge($validationRules, sharedDataApplications());
1518+
$validator = customApiValidator($request->all(), $validationRules);
15031519

15041520
// Validate ports_exposes
15051521
if ($request->has('ports_exposes')) {

bootstrap/helpers/api.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
use App\Enums\BuildPackTypes;
44
use App\Enums\RedirectTypes;
5+
use App\Enums\StaticImageTypes;
56
use Illuminate\Database\Eloquent\Collection;
67
use Illuminate\Http\Request;
78
use Illuminate\Validation\Rule;
@@ -89,6 +90,7 @@ function sharedDataApplications()
8990
'git_branch' => 'string',
9091
'build_pack' => Rule::enum(BuildPackTypes::class),
9192
'is_static' => 'boolean',
93+
'static_image' => Rule::enum(StaticImageTypes::class),
9294
'domains' => 'string',
9395
'redirect' => Rule::enum(RedirectTypes::class),
9496
'git_commit_sha' => 'string',
@@ -176,4 +178,5 @@ function removeUnnecessaryFieldsFromRequest(Request $request)
176178
$request->offsetUnset('github_app_uuid');
177179
$request->offsetUnset('private_key_uuid');
178180
$request->offsetUnset('use_build_server');
181+
$request->offsetUnset('is_static');
179182
}

0 commit comments

Comments
 (0)