/**
  * Executes this task
  *
  * @param \TYPO3\Surf\Domain\Model\Node $node
  * @param \TYPO3\Surf\Domain\Model\Application $application
  * @param \TYPO3\Surf\Domain\Model\Deployment $deployment
  * @param array $options
  * @throws \TYPO3\Surf\Exception\TaskExecutionException
  * @throws \TYPO3\Surf\Exception\InvalidConfigurationException
  */
 public function execute(Node $node, Application $application, Deployment $deployment, array $options = array())
 {
     $options['username'] = isset($options['username']) ? $options['username'] . '@' : '';
     $targetReleasePath = $deployment->getApplicationReleasePath($application);
     $configurationPath = $deployment->getDeploymentConfigurationPath() . '/';
     if (!is_dir($configurationPath)) {
         return;
     }
     $encryptedConfiguration = glob($configurationPath . '*.yaml.encrypted');
     if (count($encryptedConfiguration) > 0) {
         throw new \TYPO3\Surf\Exception\TaskExecutionException('You have sealed configuration files, please open the configuration for "' . $deployment->getName() . '"', 1317229449);
     }
     $configurations = glob($configurationPath . '*.yaml');
     $commands = array();
     foreach ($configurations as $configuration) {
         $targetConfigurationPath = dirname(str_replace($configurationPath, '', $configuration));
         if ($node->isLocalhost()) {
             $commands[] = "mkdir -p '{$targetReleasePath}/Configuration/{$targetConfigurationPath}/'";
             $commands[] = "cp {$configuration} {$targetReleasePath}/Configuration/{$targetConfigurationPath}/";
         } else {
             $username = $options['username'];
             $hostname = $node->getHostname();
             $sshPort = $node->hasOption('port') ? '-p ' . escapeshellarg($node->getOption('port')) : '';
             $scpPort = $node->hasOption('port') ? '-P ' . escapeshellarg($node->getOption('port')) : '';
             $commands[] = "ssh {$sshPort} {$username}{$hostname} 'mkdir -p {$targetReleasePath}/Configuration/{$targetConfigurationPath}/'";
             $commands[] = "scp {$scpPort} {$configuration} {$username}{$hostname}:{$targetReleasePath}/Configuration/{$targetConfigurationPath}/";
         }
     }
     $localhost = new Node('localhost');
     $localhost->setHostname('localhost');
     $this->shell->executeOrSimulate($commands, $localhost, $deployment);
 }
Esempio n. 2
0
 /**
  * Executes this task
  *
  * @param \TYPO3\Surf\Domain\Model\Node $node
  * @param \TYPO3\Surf\Domain\Model\Application $application
  * @param \TYPO3\Surf\Domain\Model\Deployment $deployment
  * @param array $options
  * @throws \TYPO3\Surf\Exception\TaskExecutionException
  * @throws \TYPO3\Surf\Exception\InvalidConfigurationException
  */
 public function execute(Node $node, Application $application, Deployment $deployment, array $options = array())
 {
     $configurationFileExtension = isset($options['configurationFileExtension']) ? $options['configurationFileExtension'] : 'yaml';
     $targetReleasePath = $deployment->getApplicationReleasePath($application);
     $configurationPath = $deployment->getDeploymentConfigurationPath();
     if (!is_dir($configurationPath)) {
         return;
     }
     $encryptedConfigurationFiles = Files::readDirectoryRecursively($configurationPath, $configurationFileExtension . '.encrypted');
     if (count($encryptedConfigurationFiles) > 0) {
         throw new \TYPO3\Surf\Exception\TaskExecutionException('You have sealed configuration files, please open the configuration for "' . $deployment->getName() . '"', 1317229449);
     }
     $commands = array();
     $configurationFiles = Files::readDirectoryRecursively($configurationPath, $configurationFileExtension);
     foreach ($configurationFiles as $configuration) {
         $targetConfigurationPath = dirname(str_replace($configurationPath, '', $configuration));
         $escapedSourcePath = escapeshellarg($configuration);
         $escapedTargetPath = escapeshellarg(Files::concatenatePaths(array($targetReleasePath, 'Configuration', $targetConfigurationPath)) . '/');
         if ($node->isLocalhost()) {
             $commands[] = 'mkdir -p ' . $escapedTargetPath;
             $commands[] = 'cp ' . $escapedSourcePath . ' ' . $escapedTargetPath;
         } else {
             $username = isset($options['username']) ? $options['username'] . '@' : '';
             $hostname = $node->getHostname();
             $sshPort = isset($options['port']) ? '-p ' . escapeshellarg($options['port']) . ' ' : '';
             $scpPort = isset($options['port']) ? '-P ' . escapeshellarg($options['port']) . ' ' : '';
             $createDirectoryCommand = '"mkdir -p ' . $escapedTargetPath . '"';
             $commands[] = "ssh {$sshPort}{$username}{$hostname} {$createDirectoryCommand}";
             $commands[] = "scp {$scpPort}{$escapedSourcePath} {$username}{$hostname}:\"{$escapedTargetPath}\"";
         }
     }
     $localhost = new Node('localhost');
     $localhost->setHostname('localhost');
     $this->shell->executeOrSimulate($commands, $localhost, $deployment);
 }
Esempio n. 3
0
 /**
  * Executes this task
  *
  * @param \TYPO3\Surf\Domain\Model\Node $node
  * @param \TYPO3\Surf\Domain\Model\Application $application
  * @param \TYPO3\Surf\Domain\Model\Deployment $deployment
  * @param array $options
  * @return void
  * @throws TaskExecutionException
  */
 public function execute(Node $node, Application $application, Deployment $deployment, array $options = array())
 {
     $targetPath = isset($options['deploymentLogTargetPath']) ? $options['deploymentLogTargetPath'] : '.';
     $fileName = !empty($options['deploymentLogFileName']) ? $options['deploymentLogFileName'] : 'deployment.log';
     $optionsToLog = !empty($options['deploymentLogOptions']) ? $options['deploymentLogOptions'] : array('tag', 'branch', 'sha1');
     $logContent = array(date('Y-m-d H:i:s (D)'), 'Application: ' . $application->getName(), 'Deployment: ' . $deployment->getName(), 'Status: ' . $deployment->getStatus());
     foreach ($optionsToLog as $key) {
         if (!empty($options[$key])) {
             $logContent[] = $key . ' = ' . $options[$key];
         }
     }
     $commands = array('cd ' . escapeshellarg($application->getReleasesPath()), 'echo ' . escapeshellarg(implode(' | ', $logContent)) . ' >> ' . rtrim($targetPath, '/') . '/' . $fileName);
     $this->shell->executeOrSimulate($commands, $node, $deployment);
 }
Esempio n. 4
0
 /**
  * Replace placeholders in option values and set default values
  *
  * @param array $options
  * @param \TYPO3\Surf\Domain\Model\Deployment $deployment
  * @return array
  */
 protected function processOptions(array $options, Deployment $deployment)
 {
     foreach (array('tagName', 'description') as $optionName) {
         $options[$optionName] = str_replace(array('{releaseIdentifier}', '{deploymentName}'), array($deployment->getReleaseIdentifier(), $deployment->getName()), $options[$optionName]);
     }
     if (!isset($options['submoduleTagNamePrefix'])) {
         $options['submoduleTagNamePrefix'] = '';
     }
     if (!isset($options['remote'])) {
         $options['remote'] = 'origin';
         return $options;
     }
     return $options;
 }
 /**
  * @param \TYPO3\Surf\Domain\Model\Deployment $deployment
  *
  * @return void
  *
  * @throws TaskExecutionException
  */
 protected function setApplication(Deployment $deployment)
 {
     $applications = $deployment->getApplications();
     if (count($applications) < 1) {
         throw new TaskExecutionException("There is no application set for the deployment '{$deployment->getName()}'. Please check your TYPO3/Surf configuration.");
     }
     $this->application = array_shift($applications);
 }