refactor(remoteProcess): remove redundant file transfer functions for improved clarity
This commit is contained in:
@@ -84,64 +84,6 @@ function instant_scp(string $source, string $dest, Server $server, $throwError =
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
function transfer_file_to_container(string $content, string $container_path, string $deployment_uuid, Server $server, bool $throwError = true): ?string
|
|
||||||
{
|
|
||||||
$temp_file = tempnam(sys_get_temp_dir(), 'coolify_env_');
|
|
||||||
|
|
||||||
try {
|
|
||||||
// Write content to temporary file
|
|
||||||
file_put_contents($temp_file, $content);
|
|
||||||
|
|
||||||
// Generate unique filename for server transfer
|
|
||||||
$server_temp_file = '/tmp/coolify_env_'.uniqid().'_'.$deployment_uuid;
|
|
||||||
|
|
||||||
// Transfer file to server
|
|
||||||
instant_scp($temp_file, $server_temp_file, $server, $throwError);
|
|
||||||
|
|
||||||
// Ensure parent directory exists in container, then copy file
|
|
||||||
$parent_dir = dirname($container_path);
|
|
||||||
$commands = [];
|
|
||||||
if ($parent_dir !== '.' && $parent_dir !== '/') {
|
|
||||||
$commands[] = executeInDocker($deployment_uuid, "mkdir -p \"$parent_dir\"");
|
|
||||||
}
|
|
||||||
$commands[] = "docker cp $server_temp_file $deployment_uuid:$container_path";
|
|
||||||
$commands[] = "rm -f $server_temp_file"; // Cleanup server temp file
|
|
||||||
|
|
||||||
return instant_remote_process_with_timeout($commands, $server, $throwError);
|
|
||||||
|
|
||||||
} finally {
|
|
||||||
// Always cleanup local temp file
|
|
||||||
if (file_exists($temp_file)) {
|
|
||||||
unlink($temp_file);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
function transfer_file_to_server(string $content, string $server_path, Server $server, bool $throwError = true): ?string
|
|
||||||
{
|
|
||||||
$temp_file = tempnam(sys_get_temp_dir(), 'coolify_env_');
|
|
||||||
|
|
||||||
try {
|
|
||||||
// Write content to temporary file
|
|
||||||
file_put_contents($temp_file, $content);
|
|
||||||
|
|
||||||
// Ensure parent directory exists on server
|
|
||||||
$parent_dir = dirname($server_path);
|
|
||||||
if ($parent_dir !== '.' && $parent_dir !== '/') {
|
|
||||||
instant_remote_process_with_timeout(["mkdir -p \"$parent_dir\""], $server, $throwError);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Transfer file directly to server destination
|
|
||||||
return instant_scp($temp_file, $server_path, $server, $throwError);
|
|
||||||
|
|
||||||
} finally {
|
|
||||||
// Always cleanup local temp file
|
|
||||||
if (file_exists($temp_file)) {
|
|
||||||
unlink($temp_file);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
function instant_remote_process_with_timeout(Collection|array $command, Server $server, bool $throwError = true, bool $no_sudo = false): ?string
|
function instant_remote_process_with_timeout(Collection|array $command, Server $server, bool $throwError = true, bool $no_sudo = false): ?string
|
||||||
{
|
{
|
||||||
$command = $command instanceof Collection ? $command->toArray() : $command;
|
$command = $command instanceof Collection ? $command->toArray() : $command;
|
||||||
|
Reference in New Issue
Block a user