/** * Execute 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 */ public function execute(Node $node, Application $application, Deployment $deployment, array $options = array()) { $localPackagePath = $deployment->getWorkspacePath($application); $releasePath = $deployment->getApplicationReleasePath($application); $remotePath = $application->getDeploymentPath() . '/cache/transfer'; // make sure there is a remote .cache folder $command = 'mkdir -p ' . $remotePath; $this->shell->executeOrSimulate($command, $node, $deployment); $username = $node->hasOption('username') ? $node->getOption('username') . '@' : ''; $hostname = $node->getHostname(); $port = $node->hasOption('port') ? ' -p ' . escapeshellarg($node->getOption('port')) : ''; $key = $node->hasOption('privateKeyFile') ? ' -i ' . escapeshellarg($node->getOption('privateKeyFile')) : ''; $quietFlag = isset($options['verbose']) && $options['verbose'] ? '' : '-q'; $rshFlag = $node->isLocalhost() ? '' : '--rsh="ssh' . $port . $key . '" '; $rsyncFlags = isset($options['rsyncFlags']) ? $options['rsyncFlags'] : "--recursive --times --perms --links --delete --delete-excluded --exclude '.git'"; $destinationArgument = $node->isLocalhost() ? $remotePath : "{$username}{$hostname}:{$remotePath}"; $command = "rsync {$quietFlag} --compress {$rshFlag} {$rsyncFlags} " . escapeshellarg($localPackagePath . '/.') . ' ' . escapeshellarg($destinationArgument); if ($node->hasOption('password')) { $resourcesPath = realpath(__DIR__ . '/../../../Resources'); $passwordSshLoginScriptPathAndFilename = $resourcesPath . '/Private/Scripts/PasswordSshLogin.expect'; $command = sprintf('expect %s %s %s', escapeshellarg($passwordSshLoginScriptPathAndFilename), escapeshellarg($node->getOption('password')), $command); } $localhost = new Node('localhost'); $localhost->setHostname('localhost'); $this->shell->executeOrSimulate($command, $localhost, $deployment); $command = strtr("cp -RPp {$remotePath}/. {$releasePath}", "\t\n", ' '); // TODO Copy revision file (if it exists) for application to deployment path with release identifier $this->shell->executeOrSimulate($command, $node, $deployment); }
/** * Execute 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 Supported options: "scriptBasePath" and "scriptIdentifier" * @return void * @throws \TYPO3\Surf\Exception\InvalidConfigurationException * @throws \TYPO3\Surf\Exception\TaskExecutionException */ public function execute(Node $node, Application $application, Deployment $deployment, array $options = array()) { $workspacePath = $deployment->getWorkspacePath($application); $scriptBasePath = isset($options['scriptBasePath']) ? $options['scriptBasePath'] : Files::concatenatePaths(array($workspacePath, 'Web')); if (!isset($options['scriptIdentifier'])) { // Generate random identifier $factory = new \RandomLib\Factory(); $generator = $factory->getMediumStrengthGenerator(); $scriptIdentifier = $generator->generateString(32, \RandomLib\Generator::CHAR_ALNUM); // Store the script identifier as an application option $application->setOption('TYPO3\\Surf\\Task\\Php\\WebOpcacheResetExecuteTask[scriptIdentifier]', $scriptIdentifier); } else { $scriptIdentifier = $options['scriptIdentifier']; } $localhost = new Node('localhost'); $localhost->setHostname('localhost'); $commands = array('cd ' . escapeshellarg($scriptBasePath), 'rm -f surf-opcache-reset-*'); $this->shell->executeOrSimulate($commands, $localhost, $deployment); if (!$deployment->isDryRun()) { $scriptFilename = $scriptBasePath . '/surf-opcache-reset-' . $scriptIdentifier . '.php'; $result = file_put_contents($scriptFilename, '<?php if (function_exists("opcache_reset")) { opcache_reset(); } @unlink(__FILE__); echo "success"; '); if ($result === false) { throw new \TYPO3\Surf\Exception\TaskExecutionException('Could not write file "' . $scriptFilename . '"', 1421932414); } } }
/** * Execute 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 \TYPO3\Surf\Exception\InvalidConfigurationException * @throws \TYPO3\Surf\Exception\TaskExecutionException */ public function execute(Node $node, Application $application, Deployment $deployment, array $options = array()) { if (!isset($options['repositoryUrl'])) { throw new \TYPO3\Surf\Exception\InvalidConfigurationException(sprintf('Missing "repositoryUrl" option for application "%s"', $application->getName()), 1374074052); } $localCheckoutPath = $deployment->getWorkspacePath($application); $node = $deployment->getNode('localhost'); $sha1 = $this->executeOrSimulateGitCloneOrUpdate($localCheckoutPath, $node, $deployment, $options); $this->executeOrSimulatePostGitCheckoutCommands($localCheckoutPath, $sha1, $node, $deployment, $options); }
/** * @param Deployment $deployment * @param Application $application * @return string */ protected function getWebDir(Deployment $deployment, Application $application) { $webDir = ''; $rootPath = $deployment->getWorkspacePath($application); $composerFile = $rootPath . '/composer.json'; if (file_exists($composerFile) === TRUE) { $json = json_decode(file_get_contents($composerFile), TRUE); if ($json !== NULL && empty($json['extra']['typo3/cms']['web-dir']) === FALSE) { return rtrim($json['extra']['typo3/cms']['web-dir'], '/') . '/'; } } return $webDir; }
/** * Rollback 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 */ public function rollback(Node $node, Application $application, Deployment $deployment, array $options = array()) { $replacePaths = array(); $replacePaths['{workspacePath}'] = escapeshellarg($deployment->getWorkspacePath($application)); if (!isset($options['rollbackCommand'])) { return; } $command = $options['rollbackCommand']; $command = str_replace(array_keys($replacePaths), $replacePaths, $command); $localhost = new Node('localhost'); $localhost->setHostname('localhost'); $this->shell->execute($command, $localhost, $deployment, true); }
/** * @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 * @return void */ public function execute(Node $node, Application $application, Deployment $deployment, array $options = array()) { if ($application->getOption('transferMethod') == 'rsync') { $path = $deployment->getWorkspacePath($application); $node = $deployment->getNode('localhost'); $command = 'beard patch'; } else { $patch = $deployment->getApplicationReleasePath($application); $command = $application->getOption('phpPath') . ' beard.phar patch'; } $command = sprintf('cd %s && %s', escapeshellarg($path), $command); $this->shell->executeOrSimulate($command, $node, $deployment); }
/** * Determines the path to the working directory and the target node by given options * * @param Node $node * @param Application $application * @param Deployment $deployment * @param array $options * @return string */ protected function determineWorkingDirectoryAndTargetNode(Node $node, Application $application, Deployment $deployment, array $options = array()) { if (!isset($this->workingDirectory) || !isset($this->targetNode)) { if (isset($options['useApplicationWorkspace']) && $options['useApplicationWorkspace'] === true) { $targetPath = $deployment->getWorkspacePath($application); $node = $deployment->getNode('localhost'); } else { $targetPath = $deployment->getApplicationReleasePath($application); } $applicationRootDirectory = isset($options['applicationRootDirectory']) ? $options['applicationRootDirectory'] : ''; $this->workingDirectory = $targetPath . '/' . $applicationRootDirectory; $this->targetNode = $node; } }
/** * Executes this task * * @param Node $node * @param Application $application * @param Deployment $deployment * @param array $options * @return void * @throws InvalidConfigurationException */ public function execute(Node $node, Application $application, Deployment $deployment, array $options = array()) { if (isset($options['useApplicationWorkspace']) && $options['useApplicationWorkspace'] === TRUE) { $gitRootPath = $deployment->getWorkspacePath($application); } else { $gitRootPath = $deployment->getApplicationReleasePath($application); } // $quietFlag = (isset($options['verbose']) && $options['verbose']) ? '' : '-q'; if (!empty($options['nodeName'])) { $node = $deployment->getNode($options['nodeName']); if ($node === NULL) { throw new InvalidConfigurationException(sprintf('Node "%s" not found', $options['nodeName']), 1413298085); } } $commands = array('cd ' . escapeshellarg($gitRootPath), 'if [ -d \'.git\' ] && hash git 2>/dev/null; then ' . 'git checkout -- .; ' . 'fi;'); $this->shell->executeOrSimulate($commands, $node, $deployment); }
/** * @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 */ public function execute(Node $node, Application $application, Deployment $deployment, array $options = array()) { if (isset($options['useApplicationWorkspace']) && $options['useApplicationWorkspace'] === true) { $composerRootPath = $deployment->getWorkspacePath($application); } else { $composerRootPath = $deployment->getApplicationReleasePath($application); } if (isset($options['nodeName'])) { $node = $deployment->getNode($options['nodeName']); if ($node === null) { throw new \TYPO3\Surf\Exception\InvalidConfigurationException(sprintf('Node "%s" not found', $options['nodeName']), 1369759412); } } if ($this->composerManifestExists($composerRootPath, $node, $deployment)) { $command = $this->buildComposerInstallCommand($composerRootPath, $options); $this->shell->executeOrSimulate($command, $node, $deployment); } }
/** * Executes this task * * @param Node $node * @param Application $application * @param Deployment $deployment * @param array $options * @return void * @throws TaskExecutionException */ public function execute(Node $node, Application $application, Deployment $deployment, array $options = array()) { if (isset($options['useApplicationWorkspace']) && $options['useApplicationWorkspace'] === TRUE) { $rootPath = $deployment->getWorkspacePath($application); } else { $rootPath = $deployment->getApplicationReleasePath($application); } if (isset($options['relativeRootPath'])) { $rootPath .= $options['relativeRootPath']; } if (!empty($options['nodeName'])) { $node = $deployment->getNode($options['nodeName']); if ($node === NULL) { throw new InvalidConfigurationException(sprintf('Node "%s" not found', $options['nodeName']), 1414781227); } } $commands = array(); $commands[] = 'cd ' . escapeshellarg($rootPath); $commands[] = 'if [ "`which npm`" != "" ] && [ -f "package.json" ]; then ' . 'npm install --loglevel error; ' . 'fi'; $this->shell->executeOrSimulate($commands, $node, $deployment); }
/** * Executes this task * * @param Node $node * @param Application $application * @param Deployment $deployment * @param array $options * @return void * @throws InvalidConfigurationException * @throws TaskExecutionException */ public function execute(Node $node, Application $application, Deployment $deployment, array $options = array()) { if (isset($options['useApplicationWorkspace']) && $options['useApplicationWorkspace'] === TRUE) { $rootPath = $deployment->getWorkspacePath($application); } else { $rootPath = $deployment->getApplicationReleasePath($application); } if (isset($options['relativeRootPath'])) { $rootPath .= $options['relativeRootPath']; } if (!empty($options['nodeName'])) { $node = $deployment->getNode($options['nodeName']); if ($node === NULL) { throw new InvalidConfigurationException(sprintf('Node "%s" not found', $options['nodeName']), 1414781227); } } $commands = array(); $commands[] = 'cd ' . escapeshellarg($rootPath); $commands[] = 'if hash gulp 2>/dev/null && [ -f gulpfile.js ]; then ' . 'gulp build; ' . 'fi;'; $this->shell->executeOrSimulate($commands, $node, $deployment); }
/** * Executes this task * * @param Node $node * @param Application $application * @param Deployment $deployment * @param array $options * @return void * @throws InvalidConfigurationException * @throws TaskExecutionException */ public function execute(Node $node, Application $application, Deployment $deployment, array $options = array()) { if (!empty($options['disableDeploymentTag'])) { return; } if (isset($options['useApplicationWorkspace']) && $options['useApplicationWorkspace'] === TRUE) { $gitRootPath = $deployment->getWorkspacePath($application); } else { $gitRootPath = $deployment->getApplicationReleasePath($application); } $tagPrefix = isset($options['deploymentTagPrefix']) ? $options['deploymentTagPrefix'] : 'server-'; $tagName = preg_replace('/[^a-zA-Z0-9-_\\.]*/', '', $tagPrefix . $node->getName()); $quietFlag = isset($options['verbose']) && $options['verbose'] ? '' : '-q'; if (!empty($options['nodeName'])) { $node = $deployment->getNode($options['nodeName']); if ($node === NULL) { throw new InvalidConfigurationException(sprintf('Node "%s" not found', $options['nodeName']), 1408441582); } } $commands = array('cd ' . escapeshellarg($gitRootPath), 'git tag --force -- ' . escapeshellarg($tagName), 'git push origin --force ' . $quietFlag . ' -- ' . escapeshellarg($tagName)); $this->shell->executeOrSimulate($commands, $node, $deployment); }
/** * Replaces the path placeholders. * * @param string $string * @param Application $application * @param Deployment $deployment * @return string */ protected function replacePathPlaceholders($string, Application $application, Deployment $deployment) { $replacePaths = ['{workspacePath}' => $deployment->getWorkspacePath($application), '{deploymentPath}' => $application->getDeploymentPath(), '{sharedPath}' => $application->getSharedPath(), '{releasePath}' => $deployment->getApplicationReleasePath($application), '{currentPath}' => $application->getReleasesPath() . '/current', '{previousPath}' => $application->getReleasesPath() . '/previous']; return str_replace(array_keys($replacePaths), $replacePaths, $string); }