/** * Executes this task * * @param \TYPO3\Deploy\Domain\Model\Node $node * @param \TYPO3\Deploy\Domain\Model\Application $application * @param \TYPO3\Deploy\Domain\Model\Deployment $deployment * @param array $options * @return void */ public function execute(Node $node, Application $application, Deployment $deployment, array $options = array()) { $releaseIdentifier = $deployment->getReleaseIdentifier(); $releasesPath = $application->getDeploymentPath() . '/releases'; $commands = array("mkdir -p {$releasesPath}/{$releaseIdentifier}/Data", "cd {$releasesPath}/{$releaseIdentifier}", "ln -sf ../../../shared/Data/Logs ./Data/Logs", "ln -sf ../../../shared/Data/Persistent ./Data/Persistent"); $this->shell->executeOrSimulate($commands, $node, $deployment); }
/** * Execute this task * * @param \TYPO3\Deploy\Domain\Model\Node $node * @param \TYPO3\Deploy\Domain\Model\Application $application * @param \TYPO3\Deploy\Domain\Model\Deployment $deployment * @param array $options * @return void */ public function execute(Node $node, Application $application, Deployment $deployment, array $options = array()) { if (!$application->hasOption('sitePackageKey')) { throw new \Exception('Missing site package key.', 1312312646); } $targetPath = $deployment->getApplicationReleasePath($application); $sitePackageKey = $application->getOption('sitePackageKey'); $this->shell->executeOrSimulate('cd ' . $targetPath . ' && FLOW3_CONTEXT=Production ./flow3 typo3.typo3:site:import --package-key ' . $sitePackageKey, $node, $deployment); }
/** * Executes this task * * @param \TYPO3\Deploy\Domain\Model\Node $node * @param \TYPO3\Deploy\Domain\Model\Application $application * @param \TYPO3\Deploy\Domain\Model\Deployment $deployment * @param array $options * @return void */ public function execute(Node $node, Application $application, Deployment $deployment, array $options = array()) { $deploymentPath = $application->getDeploymentPath(); $sharedPath = $application->getSharedPath(); $result = $this->shell->execute('test -d ' . $deploymentPath, $node, $deployment, TRUE); if ($result === FALSE) { throw new \Exception('Deployment directory "' . $deploymentPath . '" does not exist on ' . $node->getName(), 1311003253); } $this->shell->executeOrSimulate('mkdir -p ' . $deploymentPath . '/releases;mkdir -p ' . $sharedPath, $node, $deployment); }
/** * Rollback this task * * @param \TYPO3\Deploy\Domain\Model\Node $node * @param \TYPO3\Deploy\Domain\Model\Application $application * @param \TYPO3\Deploy\Domain\Model\Deployment $deployment * @param array $options * @return void */ public function rollback(Node $node, Application $application, Deployment $deployment, array $options = array()) { $deploymentPath = $application->getDeploymentPath(); $sharedPath = $application->getSharedPath(); $releasePath = $deployment->getApplicationReleasePath($application); $currentPath = $application->getDeploymentPath() . '/releases/current'; $previousPath = $application->getDeploymentPath() . '/releases/previous'; if (!isset($options['rollbackCommand'])) { return; } $command = $options['rollbackCommand']; $command = str_replace(array('{deploymentPath}', '{sharedPath}', '{releasePath}', '{currentPath}', '{previousPath}'), array($deploymentPath, $sharedPath, $releasePath, $currentPath, $previousPath), $command); $this->shell->execute($command, $node, $deployment, TRUE); }
/** * Cleanup old releases by listing all releases and keeping a configurable * number of old releases (application option "keepReleases"). The current * and previous release (if one exists) are protected from removal. * * Example configuration: * * $application->setOption('keepReleases', 2); * * Note: There is no rollback for this cleanup, so we have to be sure not to delete any * live or referenced releases. * * @param \TYPO3\Deploy\Domain\Model\Node $node * @param \TYPO3\Deploy\Domain\Model\Application $application * @param \TYPO3\Deploy\Domain\Model\Deployment $deployment * @param array $options * @return void */ public function execute(Node $node, Application $application, Deployment $deployment, array $options = array()) { if (!$application->hasOption('keepReleases')) { $deployment->getLogger()->log(($deployment->isDryRun() ? 'Would keep' : 'Keeping') . ' all releases for "' . $application->getName() . '"', LOG_DEBUG); return; } $keepReleases = $application->getOption('keepReleases'); $releasesPath = $application->getDeploymentPath() . '/releases'; $currentReleaseIdentifier = $deployment->getReleaseIdentifier(); $previousReleasePath = $application->getDeploymentPath() . '/releases/previous'; $previousReleaseIdentifier = trim($this->shell->execute("if [ -h {$previousReleasePath} ]; then basename `readlink {$previousReleasePath}` ; fi", $node, $deployment)); $allReleasesList = $this->shell->execute("find {$releasesPath}/. -maxdepth 1 -type d -exec basename {} \\;", $node, $deployment); $allReleases = preg_split('/\\s+/', $allReleasesList, -1, PREG_SPLIT_NO_EMPTY); $removableReleases = array(); foreach ($allReleases as $release) { if ($release !== '.' && $release !== $currentReleaseIdentifier && $release !== $previousReleaseIdentifier && $release !== 'current' && $release !== 'previous') { $removableReleases[] = trim($release); } } sort($removableReleases); $removeReleases = array_slice($removableReleases, 0, count($removableReleases) - $keepReleases); $removeCommand = ''; foreach ($removeReleases as $removeRelease) { $removeCommand .= "rm -rf {$releasesPath}/{$removeRelease};rm -f {$releasesPath}/{$removeRelease}REVISION;"; } if (count($removeReleases) > 0) { $deployment->getLogger()->log(($deployment->isDryRun() ? 'Would remove' : 'Removing') . ' releases ' . implode(', ', $removeReleases)); $this->shell->executeOrSimulate($removeCommand, $node, $deployment); } else { $deployment->getLogger()->log('No releases to remove', LOG_DEBUG); } }
/** * Register tasks for this application * * @param \TYPO3\Deploy\Domain\Model\Workflow $workflow * @param \TYPO3\Deploy\Domain\Model\Deployment $deployment * @return void */ public function registerTasks(Workflow $workflow, Deployment $deployment) { parent::registerTasks($workflow, $deployment); $this->checkIfMandatoryOptionsExist(); $this->buildConfiguration(); $this->defineTasks($workflow, $deployment); $workflow->forApplication($this, 'initialize', array('typo3.deploy:flow3:createdirectories')); if ($this->getOption('enableTests') !== FALSE) { $workflow->forApplication($this, 'test', array('typo3.deploy:flow3:unittest'))->forApplication($this, 'test', array('typo3.deploy:flow3:functionaltest')); } $workflow->forApplication($this, 'cleanup', array('createZipDistribution', 'createTarGzDistribution', 'createTarBz2Distribution')); if ($this->hasOption('enableSourceforgeUpload') && $this->getOption('enableSourceforgeUpload') === TRUE) { $workflow->forApplication($this, 'cleanup', array('typo3.deploy:sourceforgeupload')); } if ($this->hasOption('createTags') && $this->getOption('createTags') === TRUE) { $workflow->forApplication($this, 'cleanup', array('typo3.deploy:git:tag')); } }
/** * Rollback this task * * @param \TYPO3\Deploy\Domain\Model\Node $node * @param \TYPO3\Deploy\Domain\Model\Application $application * @param \TYPO3\Deploy\Domain\Model\Deployment $deployment * @param array $options * @return void */ public function rollback(Node $node, Application $application, Deployment $deployment, array $options = array()) { $releasesPath = $application->getDeploymentPath() . '/releases'; $this->shell->execute('cd ' . $releasesPath . ' && rm -f ./current && mv ./previous ./current', $node, $deployment, TRUE); }
/** * Register tasks for this application * * @param \TYPO3\Deploy\Domain\Model\Workflow $workflow * @param \TYPO3\Deploy\Domain\Model\Deployment $deployment * @return void */ public function registerTasks(Workflow $workflow, Deployment $deployment) { parent::registerTasks($workflow, $deployment); $workflow->forApplication($this, 'initialize', array('typo3.deploy:flow3:createdirectories'))->afterTask('typo3.deploy:gitcheckout', array('typo3.deploy:flow3:symlinkdata', 'typo3.deploy:flow3:symlinkconfiguration'), $this)->afterTask('typo3.deploy:gitcheckout', array('typo3.deploy:flow3:setfilepermissions'), $this)->forApplication($this, 'migrate', array('typo3.deploy:flow3:migrate')); }
/** * Execute a task and consider configured before / after "hooks" * * Will also execute tasks that are registered to run before or after this task. * * @param string $task * @param \TYPO3\Deploy\Domain\Model\Node $node * @param \TYPO3\Deploy\Domain\Model\Application $application * @param \TYPO3\Deploy\Domain\Model\Deployment $deployment * @param array $callstack * @return void */ protected function executeTask($task, Node $node, Application $application, Deployment $deployment, array &$callstack = array()) { foreach (array('_', $application->getName()) as $applicationName) { if (isset($this->tasks['before'][$applicationName][$task])) { foreach ($this->tasks['before'][$applicationName][$task] as $beforeTask) { $deployment->getLogger()->log('Task "' . $beforeTask . '" before "' . $task, LOG_DEBUG); $this->executeTask($beforeTask, $node, $application, $deployment, $callstack); } } } if (isset($callstack[$task])) { throw new \Exception('Cycle for task "' . $task . '" detected, aborting.'); } $deployment->getLogger()->log('Execute task "' . $task . '" on "' . $node->getName() . '" for application "' . $application->getName() . '"', LOG_DEBUG); if (isset($this->tasks['defined'][$task])) { $this->taskManager->execute($this->tasks['defined'][$task]['task'], $node, $application, $deployment, $this->tasks['defined'][$task]['options']); } else { $this->taskManager->execute($task, $node, $application, $deployment); } $callstack[$task] = TRUE; foreach (array('_', $application->getName()) as $applicationName) { $label = $applicationName === '_' ? 'for all' : 'for application ' . $applicationName; if (isset($this->tasks['after'][$applicationName][$task])) { foreach ($this->tasks['after'][$applicationName][$task] as $beforeTask) { $deployment->getLogger()->log('Task "' . $beforeTask . '" after "' . $task . '" ' . $label, LOG_DEBUG); $this->executeTask($beforeTask, $node, $application, $deployment, $callstack); } } } }
/** * Execute this task * * @param \TYPO3\Deploy\Domain\Model\Node $node * @param \TYPO3\Deploy\Domain\Model\Application $application * @param \TYPO3\Deploy\Domain\Model\Deployment $deployment * @param array $options * @return void */ public function execute(Node $node, Application $application, Deployment $deployment, array $options = array()) { $deploymentPath = $application->getDeploymentPath(); $this->shell->executeOrSimulate(array('mkdir -p ' . $deploymentPath . '/shared/Data/Logs', 'mkdir -p ' . $deploymentPath . '/shared/Data/Persistent', 'mkdir -p ' . $deploymentPath . '/shared/Configuration'), $node, $deployment); }
/** * Add an application * * @param \TYPO3\Deploy\Domain\Model\Application $application * @return void */ public function addApplication(Application $application) { $this->applications[$application->getName()] = $application; }