fix: Application cloning

- disable URL auto generation
- clone Application settings as well
- clone tags
- clone scheduled tasks
- clone preview deployment settings
- clone file and directory mounts
This commit is contained in:
peaklabs-dev
2025-01-07 20:27:54 +01:00
parent 91e1220912
commit b77a223ec9

View File

@@ -117,49 +117,102 @@ class CloneMe extends Component
'additional_networks_count', 'additional_networks_count',
])->fill([ ])->fill([
'uuid' => $uuid, 'uuid' => $uuid,
'fqdn' => generateFqdn($this->server, $uuid), // 'fqdn' => generateFqdn($this->server, $uuid), - Proxy labels are also duplicated, so can we duplicate the domain as well?
'status' => 'exited', 'status' => 'exited',
'environment_id' => $environment->id, 'environment_id' => $environment->id,
// This is not correct, but we need to set it to something
'destination_id' => $this->selectedDestination, 'destination_id' => $this->selectedDestination,
]); ]);
$newApplication->save(); $newApplication->save();
$environmentVaribles = $application->environment_variables()->get();
foreach ($environmentVaribles as $environmentVarible) { $newApplication->settings()->delete(); // first delete the automatically created settings and fill in the old ones (to properly clone and avoid duplicates)
$newEnvironmentVariable = $environmentVarible->replicate([ $applicationSettings = $application->settings;
if ($applicationSettings) {
$newApplicationSettings = $applicationSettings->replicate([
'id', 'id',
'created_at', 'created_at',
'updated_at', 'updated_at',
'additional_servers_count',
'additional_networks_count',
])->fill([ ])->fill([
'resourceable_id' => $newApplication->id, 'application_id' => $newApplication->id,
]); ]);
$newEnvironmentVariable->save(); $newApplicationSettings->save();
} }
$tags = $application->tags;
foreach ($tags as $tag) {
$newApplication->tags()->attach($tag->id);
}
$scheduledTasks = $application->scheduled_tasks()->get();
foreach ($scheduledTasks as $task) {
$newTask = $task->replicate([
'id',
'created_at',
'updated_at',
])->fill([
'uuid' => (string) new Cuid2,
'application_id' => $newApplication->id,
'team_id' => currentTeam()->id,
]);
$newTask->save();
}
$applicationPreviews = $application->previews()->get();
foreach ($applicationPreviews as $preview) {
$newPreview = $preview->replicate([
'id',
'created_at',
'updated_at',
])->fill([
'application_id' => $newApplication->id,
'status' => 'exited',
]);
$newPreview->save();
}
$persistentVolumes = $application->persistentStorages()->get(); $persistentVolumes = $application->persistentStorages()->get();
foreach ($persistentVolumes as $volume) { foreach ($persistentVolumes as $volume) {
$newPersistentVolume = $volume->replicate([ $newPersistentVolume = $volume->replicate([
'id', 'id',
'created_at', 'created_at',
'updated_at', 'updated_at',
'additional_servers_count',
'additional_networks_count',
])->fill([ ])->fill([
'name' => $newApplication->uuid.'-'.str($volume->name)->afterLast('-'), 'name' => $newApplication->uuid.'-'.str($volume->name)->afterLast('-'),
'resource_id' => $newApplication->id, 'resource_id' => $newApplication->id,
]); ]);
$newPersistentVolume->save(); $newPersistentVolume->save();
} }
$fileStorages = $application->fileStorages()->get();
foreach ($fileStorages as $storage) {
$newStorage = $storage->replicate([
'id',
'created_at',
'updated_at',
])->fill([
'resource_id' => $newApplication->id,
]);
$newStorage->save();
} }
$environmentVaribles = $application->environment_variables()->get();
foreach ($environmentVaribles as $environmentVarible) {
$newEnvironmentVariable = $environmentVarible->replicate([
'id',
'created_at',
'updated_at',
])->fill([
'resourceable_id' => $newApplication->id,
]);
$newEnvironmentVariable->save();
}
}
foreach ($databases as $database) { foreach ($databases as $database) {
$uuid = (string) new Cuid2; $uuid = (string) new Cuid2;
$newDatabase = $database->replicate([ $newDatabase = $database->replicate([
'id', 'id',
'created_at', 'created_at',
'updated_at', 'updated_at',
'additional_servers_count',
'additional_networks_count',
])->fill([ ])->fill([
'uuid' => $uuid, 'uuid' => $uuid,
'status' => 'exited', 'status' => 'exited',
@@ -177,8 +230,6 @@ class CloneMe extends Component
'id', 'id',
'created_at', 'created_at',
'updated_at', 'updated_at',
'additional_servers_count',
'additional_networks_count',
])->fill($payload); ])->fill($payload);
$newEnvironmentVariable->save(); $newEnvironmentVariable->save();
} }
@@ -189,8 +240,6 @@ class CloneMe extends Component
'id', 'id',
'created_at', 'created_at',
'updated_at', 'updated_at',
'additional_servers_count',
'additional_networks_count',
])->fill([ ])->fill([
'uuid' => $uuid, 'uuid' => $uuid,
'environment_id' => $environment->id, 'environment_id' => $environment->id,