public function execute(Context $context) { if ($this->io) { $this->io->write(sprintf('Wring remote info file')); } $version = $context->getVersion(); $versionFile = FilePath::join($this->transporter->getPath(), $context->getStrategy()->getUploadPath($context->getVersion()), $this->remoteInfoFile); $this->transporter->putContent($version->getUID(), $versionFile); }
protected function removeFiles(array $files, Context $context) { $total = count($files); foreach ($files as $t => $file) { $src = FilePath::join($context->getBuilddir(), $file); $dest = FilePath::join($this->getDestinationPath($context->getStrategy(), $context->getVersion()), $file); $this->transporter->remove($dest, true); if ($this->io && true === $this->showProgress) { $this->io->overwrite(sprintf('Progress: <comment>%d%%</comment>', ($t + 1) * 100 / $total), false); } } }
public function execute(Context $context) { $this->io->write(sprintf('Comparing <info>%s</info> (<comment>%s</comment>) with <info>%s</info> (<comment>%s</comment>)', $context->getVersion()->getName(), $context->getVersion()->getBuild(), $context->getRemoteVersion()->getName(), $context->getRemoteVersion()->getBuild())); $result = $this->repository->diff($context->getRemoteVersion(), $context->getVersion()); if ($result) { foreach ($result as $fileinfo) { switch ($fileinfo->getStatus()) { case Status::ADDED: $symbol = '+'; $color = 'info'; break; case Status::MODIFIED: $symbol = '*'; $color = 'comment'; break; case Status::DELETED: $symbol = '-'; $color = 'error'; break; } $this->io->write(sprintf(' <%s>%-2s %s</%s>', $color, $symbol, $fileinfo->getPathname(), $color)); } } else { $this->io->write('No changes between versions'); } }
public function execute(Context $context) { // this was filled by the builder $filesModified = $context->getFilesModified(); $filesDeleted = $context->getFilesDeleted(); if (false === $context->isFullDeploy()) { $diff = $this->repository->diff($context->getRemoteVersion(), $context->getVersion()); $subselectionModified = new FileCollection($context->getBuilddir()); foreach ($diff as $fileinfo) { if (Status::ADDED === $fileinfo->getStatus()) { $subselectionModified[] = $fileinfo->getPathname(); } elseif (Status::MODIFIED === $fileinfo->getStatus()) { $subselectionModified[] = $fileinfo->getPathname(); } elseif (Status::DELETED === $fileinfo->getStatus()) { $filesDeleted->add($fileinfo->getPathname(), true); } else { // @todo handle other cases if they actually exist } } foreach ($this->derivedFiles as $derivable) { $source = $derivable['source']; $derived = $derivable['derived']; if ($subselectionModified->has($source)) { $subselectionModified->add($derived); } } // only keep files that are changed $filesModified->intersect($subselectionModified); // if (0 === count($filesAdded) && count($subselectionAdded) > 0) { // // hmm.. so files have changed but nothing to deploy // // it looks like we forgot to specify some derived files // // @todo inform the user about this? // } // @todo we could also check here if all files are accounted for (maybe // some files were deleted and not told to us by setting it in // the `removes` config?) in other words: file_exists on all files? } else { foreach ($this->derivedFiles as $derivable) { $source = $derivable['source']; $derived = $derivable['derived']; if ($filesModified->has($source)) { $filesModified->add($derived); } } } // never upload the conveyor configuration! $filesModified->remove('conveyor.yml'); // validate result, throw exception when we have nothing to deploy if (0 === count($filesModified) && 0 === count($filesDeleted)) { throw new EmptyChangesetException(); } $context->setFilesModified($filesModified); $context->setFilesDeleted($filesDeleted); }
protected function applyResultToFilelist(ExecuteResult $result) { $filesModified = $this->context->getFilesModified(); foreach ($result->getDerived() as $pattern) { $filesModified->add($pattern); } foreach ($result->getRemoved() as $pattern) { $filesModified->remove($pattern); } }
protected function executeTaskrunner(Context $context) { $this->io->write(''); if (true === $context->isSimulate()) { $this->io->write(sprintf('Simulating tasks before deploy')); } else { $this->io->write(sprintf('Running tasks before deploy')); } $this->io->increaseIndention(1); if (true === $context->isSimulate()) { $this->taskRunner->simulate($context->getTarget(), $context->getVersion()); } else { $this->taskRunner->execute($context->getTarget(), $context->getVersion()); } $this->io->decreaseIndention(1); }
public function execute(Context $context) { if (true !== $this->validateBuildDir($context->isForce())) { return false; } $this->io->write(''); $this->io->write(sprintf('Building <info>%s</info> (<comment>%s</comment>) to <info>%s</info>', $context->getVersion()->getName(), $context->getTarget(), $context->getBuilddir())); $this->io->increaseIndention(1); $this->builder->setContext($context); $this->builder->build($context->getTarget(), $context->getVersion()); $this->io->decreaseIndention(1); return true; }
protected function compareRemoteVersionBuild(Context $context) { if ($context->isFullDeploy()) { return true; } if ($context->getVersion()->equals($context->getRemoteVersion())) { $this->io->write('Remote version is already up-to-date.', true); return false; } elseif (1 === $this->repository->versionCompare($context->getRemoteVersion(), $context->getVersion())) { if ($context->isForce()) { $answer = true; } else { $answer = $this->io->askConfirmation(sprintf('Remote version (%s) is newer than the selected version (%s). ' . 'Would you like to continue as full deploy? (Y/n): ', $context->getRemoteVersion()->getBuild(), $context->getVersion()->getBuild()), 'Y'); } if ($answer) { $context->setFullDeploy(true); } else { return false; } } return true; }
/** * Simulates a deploy * * @param string $target * @param string $version * @param array $options */ protected function doSimulate($target, $version, array $options = array()) { $version = $this->getRepository()->getVersion($version); $options += array('full_deploy' => false, 'force' => false); $this->assertTargetExists($target, $this->getConfig()->getConfig()); $this->setConfigParametersForTarget($target); $transporter = $this->getTransporter($target); $readOnlyTransporter = $this->container->get('transporter.readonly'); $readOnlyTransporter->setInnerTransporter($transporter); $config = $this->getConfig()->getConfig(); $derived = $config['build']['derived']; $builder = $this->getBuilder(); $repository = $this->getRepository(); $io = $this->getIO(); $dispatcher = $this->container->get('dispatcher'); $trDeployBefore = $this->container->get('deploy.taskrunner.before'); $trDeployAfter = $this->container->get('deploy.taskrunner.after'); $trDeployFinal = $this->container->get('deploy.taskrunner.final'); $remoteInfoFile = $this->container->getParameter('conveyor.remoteinfofile'); $strategy = $this->getStrategy($readOnlyTransporter); $trDeployBefore->setTransporter($readOnlyTransporter); $trDeployAfter->setTransporter($readOnlyTransporter); $trDeployFinal->setTransporter($readOnlyTransporter); $context = new Context(); $context->setFullDeploy($options['full_deploy'])->setForce($options['force'])->setSimulate(true)->setBuilddir($this->getBuilder()->getBuildDir())->setVersion($version)->setTarget($target)->setStrategy($strategy); if ($transporter instanceof TransactionalTransporterInterface) { $transporter->begin(); } $manager = new StageManager($context, $dispatcher); $manager->addStage('validate.remote', new Stage\ValidateRemoteStage($readOnlyTransporter, $io, $remoteInfoFile))->addStage('get.remote.version', new Stage\RetrieveRemoteVersionInfoStage($readOnlyTransporter, $repository, $io, $remoteInfoFile))->addStage('build', new Stage\BuildStage($builder, $io))->addStage('filelist', new Stage\BuildFilelistStage($repository, $derived))->addStage('deploy.before', new Stage\DeployBeforeStage($trDeployBefore, $io))->addStage('transfer', new Stage\TransferStage($readOnlyTransporter, $io))->addStage('set.remote.version', new Stage\WriteRemoteInfoFileStage($readOnlyTransporter, $remoteInfoFile, $io))->addStage('deploy.after', new Stage\DeployAfterStage($trDeployAfter, $io))->addStage('deploy.final', new Stage\DeployFinalStage($trDeployFinal, $io)); if ($transporter instanceof TransactionalTransporterInterface) { $dispatcher->addListener(StageEvents::STAGE_PRE_EXECUTE, function (StageEvent $event) use($transporter) { if ('deploy.after' === $event->getStageName()) { $transporter->commit(); } }); } try { $result = $manager->execute(); } catch (EmptyChangesetException $e) { $this->getIO()->write('Nothing to deploy: no files have been changed or removed. Use --full to deploy anyway.', true); $result = true; // trigger a cleanup } if ($result === true) { // cleanup $builddir = $this->getBuilder()->getBuildDir(); if (is_dir($builddir)) { $filesystem = new Filesystem(); $filesystem->remove($builddir); } } }
protected function validateRemoteVersionFile(Context $context) { if ($context->isFullDeploy()) { return; } $versionFile = FilePath::join($this->transporter->getPath(), $context->getStrategy()->getCurrentReleasePath(), $this->remoteInfoFile); if (false == $this->transporter->exists($versionFile)) { if ($context->isForce()) { $answer = true; } else { $answer = $this->io->askConfirmation(sprintf('Remote version information not found. Would you like to do a full deploy? (Y/n): '), 'Y'); } if ($answer) { $context->setFullDeploy(true); } else { return false; } } return true; }
/** * Execute a single task * * @param Context $context * * @return void */ protected function executeTaskrunner(Context $context) { $this->io->write(''); $this->io->increaseIndention(1); $this->taskRunner->execute($context->getTarget(), $context->getVersion()); $this->io->decreaseIndention(1); }
/** * Creates shared files and folders */ protected function prepareSharedFilesAndFolders(Context $context) { $basepath = $this->transporter->getPath(); $sharedPath = $basepath . '/shared'; $shared = (array) $this->options['shared']; // add some white space to the output if (count($shared) > 0) { $this->io->write(''); } foreach ($shared as $fileOrFolder) { $sharedFilepath = $sharedPath . '/' . $fileOrFolder; $localFilepath = $context->getBuilddir() . '/' . $fileOrFolder; if (false === $this->transporter->exists($sharedFilepath)) { // Hmm, the shared entity doesn't exist // is it a directory? if (is_dir($localFilepath) || '/' === substr($sharedFilepath, -1)) { $this->transporter->mkdir($sharedFilepath); } else { $parentDir = dirname($sharedFilepath); if (false === $this->transporter->exists($parentDir) && $parentDir != $sharedPath) { $this->transporter->mkdir($parentDir); } $this->transporter->putContent('', $sharedFilepath); // make a dummy file } } } }