Better tty

This commit is contained in:
Anton Medvedev 2017-03-12 23:04:48 +07:00
parent df21fa16ea
commit ace288978c
2 changed files with 28 additions and 9 deletions

View File

@ -14,6 +14,9 @@ task('deploy:update_code', function () {
$git = get('bin/git'); $git = get('bin/git');
$gitCache = get('git_cache'); $gitCache = get('git_cache');
$depth = $gitCache ? '' : '--depth 1'; $depth = $gitCache ? '' : '--depth 1';
$options = [
'tty' => get('git_tty', false),
];
// If option `branch` is set. // If option `branch` is set.
if (input()->hasOption('branch')) { if (input()->hasOption('branch')) {
@ -49,14 +52,14 @@ task('deploy:update_code', function () {
if ($gitCache && isset($releases[1])) { if ($gitCache && isset($releases[1])) {
try { try {
run("$git clone $at --recursive -q --reference {{deploy_path}}/releases/{$releases[1]} --dissociate $repository {{release_path}} 2>&1"); run("$git clone $at --recursive -q --reference {{deploy_path}}/releases/{$releases[1]} --dissociate $repository {{release_path}} 2>&1", $options);
} catch (\RuntimeException $exc) { } catch (\RuntimeException $exc) {
// If {{deploy_path}}/releases/{$releases[1]} has a failed git clone, is empty, shallow etc, git would throw error and give up. So we're forcing it to act without reference in this situation // If {{deploy_path}}/releases/{$releases[1]} has a failed git clone, is empty, shallow etc, git would throw error and give up. So we're forcing it to act without reference in this situation
run("$git clone $at --recursive -q $repository {{release_path}} 2>&1"); run("$git clone $at --recursive -q $repository {{release_path}} 2>&1", $options);
} }
} else { } else {
// if we're using git cache this would be identical to above code in catch - full clone. If not, it would create shallow clone. // if we're using git cache this would be identical to above code in catch - full clone. If not, it would create shallow clone.
run("$git clone $at $depth --recursive -q $repository {{release_path}} 2>&1"); run("$git clone $at $depth --recursive -q $repository {{release_path}} 2>&1", $options);
} }
if (!empty($revision)) { if (!empty($revision)) {

View File

@ -47,12 +47,24 @@ class Client
$options = $host->sshOptions(); $options = $host->sshOptions();
if ($host->isMultiplexing()) { // When tty need to be allocated, don't use multiplexing,
$options = $this->initMultiplexing($host); // and pass command without bash allocation on remote host.
}
if ($config['tty']) { if ($config['tty']) {
$options .= ' -tt'; $options .= ' -tt';
$command = escapeshellarg($command);
$ssh = "ssh $options $host $command";
$process = new Process($ssh);
$process
->setTimeout($config['timeout'])
->setTty(true)
->mustRun();
return $process->getOutput();
}
if ($host->isMultiplexing()) {
$options = $this->initMultiplexing($host);
} }
$ssh = "ssh $options $host 'bash -s; printf \"[exit_code:%s]\" $?;'"; $ssh = "ssh $options $host 'bash -s; printf \"[exit_code:%s]\" $?;'";
@ -112,13 +124,17 @@ class Client
private function filterOutput($output) private function filterOutput($output)
{ {
return preg_replace('/\[exit_code:(.*?)\]$/', '', $output); return preg_replace('/\[exit_code:(.*?)\]/', '', $output);
} }
private function parseExitStatus(Process $process) private function parseExitStatus(Process $process)
{ {
$output = $process->getOutput(); $output = $process->getOutput();
preg_match('/\[exit_code:(.*?)\]$/', $output, $match); preg_match('/\[exit_code:(.*?)\]/', $output, $match);
if (!isset($match[1])) {
return -1;
}
$exitCode = (int)$match[1]; $exitCode = (int)$match[1];
return $exitCode; return $exitCode;