Simplifying deployment utils and making them more robust

This commit is contained in:
Pavel Shevaev 2023-10-24 19:53:48 +03:00
parent 101ae6a960
commit 8dbd283a8a
1 changed files with 3 additions and 15 deletions

View File

@ -59,20 +59,6 @@ function deploy_declare_node($name, array $props)
throw new Exception("Declaration '$name' already exists"); throw new Exception("Declaration '$name' already exists");
$decl = new DeployNode($name, $props); $decl = new DeployNode($name, $props);
$deploy_dir = '/home/' . $decl->get('user') . '/' . $decl->get('dir');
//for convenience
$decl->set("deploy_dir", $deploy_dir);
//checking deploy_dir conflicts
foreach($DEPLOY_NODES as $other_name => $other_decl)
{
foreach($other_decl->get('hosts') as $other_host)
{
foreach($decl->get('hosts') as $host)
if($host == $other_host && $other_decl->get('deploy_dir') === $deploy_dir)
throw new Exception("Deploy directory '$deploy_dir' conflicts on nodes '$other_name' and '$name' for host '$host'");
}
}
$DEPLOY_NODES[$name] = $decl; $DEPLOY_NODES[$name] = $decl;
} }
@ -288,6 +274,7 @@ function deploy_put_file($name, $path, $contents, $opts = 0)
function deploy_scp_put_file($name, $local_path, $remote_path, $opts = 0) function deploy_scp_put_file($name, $local_path, $remote_path, $opts = 0)
{ {
$decl = deploy_get_node($name); $decl = deploy_get_node($name);
$remote_path = deploy_str($decl, $remote_path);
$user = $decl->get('user'); $user = $decl->get('user');
@ -420,13 +407,14 @@ function deploy_get_file($name, $path, $opts = 0)
$decl = deploy_get_node($name); $decl = deploy_get_node($name);
foreach($decl->get('hosts') as $host) foreach($decl->get('hosts') as $host)
{ {
$path = deploy_str($decl, $path);
if(($opts & DEPLOY_OPT_SILENT) == 0) if(($opts & DEPLOY_OPT_SILENT) == 0)
echo "[GET] $host: $path\n"; echo "[GET] $host: $path\n";
if($host !== "localhost") if($host !== "localhost")
{ {
$ssh = deploy_get_ssh($decl, $host); $ssh = deploy_get_ssh($decl, $host);
$path = deploy_str($decl, $path);
$scp = new SCP($ssh); $scp = new SCP($ssh);
$files[$host] = $scp->get($path); $files[$host] = $scp->get($path);
} }