/** * * {@inheritDoc} * */ public function doDeploy(ServerInterface $server, array $options, $dryRun) { if (PHP_OS != "WIN32" && PHP_OS != "WINNT" && PHP_OS != "Windows") { throw new \Exception("This deployer running only Windows OS. This OS is " . PHP_OS); } $xcopyOptions = isset($options['xcopy_options']) ? $options['xcopy_options'] : '/D /E /F /K /Y /I'; // Exclude file $excludeFile = null; if (isset($options['xcopy_exclude'])) { $excludeOption = $options['xcopy_exclude']; } else { $excludeOption = $options['rsync_exclude']; } if (isset($excludeOption)) { $excludeFile = $excludeOption; if (false === file_exists($excludeFile)) { throw new \InvalidArgumentException(sprintf('The exclude file "%s" does not exist.', $excludeFile)); } $excludeFile = realpath($excludeFile); } $exclude = ''; if (null !== $excludeFile) { $exclude = sprintf('/EXCLUDE:%s', $excludeFile); } $target = trim($server->getDir()); $target = substr($server->getDir(), 0, strlen($server->getDir()) - 1); $command = sprintf('xcopy %s %s %s %s', ".", $target, $xcopyOptions, $exclude); print_r($command); print "\n"; $result = system($command); print $result; print "\n"; $commands = isset($options['commands']) ? $options['commands'] : array(); $this->execCommands($server, $commands); }
/** * {@inheritDoc} */ public function deploy(ServerInterface $server, array $options = array()) { $options = array_merge($options, $server->getOptions()); $dryRun = false; if (isset($options['dry_run']) && $options['dry_run']) { $dryRun = true; } return $this->doDeploy($server, $options, $dryRun); }
/** * Open the SSH connection * * @param Plum\Server\ServerInterface $server */ protected function connect(ServerInterface $server) { if (false === function_exists('ssh2_connect')) { throw new \RuntimeException('The "ssh2_connect" function does not exist.'); } $con = ssh2_connect($server->getHost(), $server->getPort()); if (false === $con) { throw new SshException(sprintf('Cannot connect to server "%s"', $server->getHost())); } if (false === ssh2_auth_password($con, $server->getUser(), $server->getPassword())) { throw new SshException(sprintf('Authorization failed for user "%s"', $server->getUser())); } $this->con = $con; }
/** * {@inheritDoc} */ public function doDeploy(ServerInterface $server, array $options, $dryRun) { $rsyncOptions = isset($options['rsync_options']) ? $options['rsync_options'] : '-azC --force --delete --progress'; // Exclude file $excludeFile = null; if (isset($options['rsync_exclude'])) { $excludeFile = $options['rsync_exclude']; if (false === file_exists($excludeFile)) { throw new \InvalidArgumentException(sprintf('The exclude file "%s" does not exist.', $excludeFile)); } $excludeFile = realpath($excludeFile); } $exclude = ''; if (null !== $excludeFile) { $exclude = sprintf('--exclude-from \'%s\'', $excludeFile); } $ssh = ''; if (22 !== $server->getPort()) { $ssh = sprintf('-e "ssh -p%d"', $server->getPort()); } $login = sprintf('%s@%s:%s', $server->getUser(), $server->getHost(), $server->getDir()); $command = sprintf('rsync %s %s %s ./ %s %s', $dryRun ? "--dry-run" : "", $rsyncOptions, $ssh, $login, $exclude); system($command); }