/**
  * Constructs a new Workspace instance and sets the Workspace on the event.
  *
  * @param WorkspaceEvent           $event
  * @param string                   $eventName
  * @param EventDispatcherInterface $eventDispatcher
  */
 public function onPrepareWorkspaceConstructWorkspaceInstance(WorkspaceEvent $event, $eventName, EventDispatcherInterface $eventDispatcher)
 {
     $eventDispatcher->dispatch(AccompliEvents::LOG, new LogEvent(LogLevel::NOTICE, 'Creating Workspace.', $eventName, $this, array('event.task.action' => TaskInterface::ACTION_IN_PROGRESS)));
     $workspace = new Workspace($event->getHost());
     $workspace->setReleasesDirectory($this->releasesDirectory);
     $workspace->setDataDirectory($this->dataDirectory);
     $workspace->setCacheDirectory($this->cacheDirectory);
     $workspace->setOtherDirectories($this->otherDirectories);
     $event->setWorkspace($workspace);
     $eventDispatcher->dispatch(AccompliEvents::LOG, new LogEvent(LogLevel::NOTICE, 'Created Workspace.', $eventName, $this, array('event.task.action' => TaskInterface::ACTION_COMPLETED, 'output.resetLine' => true)));
 }
Exemplo n.º 2
0
 /**
  * Adds an SSH key to the initialized SSH agent.
  *
  * @param Workspace                  $workspace
  * @param ConnectionAdapterInterface $connection
  * @param string                     $key
  * @param string                     $eventName
  * @param EventDispatcherInterface   $eventDispatcher
  */
 private function addKeyToSSHAgent(Workspace $workspace, ConnectionAdapterInterface $connection, $key, $eventName, EventDispatcherInterface $eventDispatcher)
 {
     $eventDispatcher->dispatch(AccompliEvents::LOG, new LogEvent(LogLevel::INFO, 'Adding key to SSH agent...', $eventName, $this, array('event.task.action' => TaskInterface::ACTION_IN_PROGRESS)));
     $keyFile = $workspace->getHost()->getPath() . '/tmp.key';
     if ($connection->createFile($keyFile, 0700) && $connection->putContents($keyFile, $key)) {
         $result = $connection->executeCommand('ssh-add', array($keyFile));
         if ($result->isSuccessful()) {
             $eventDispatcher->dispatch(AccompliEvents::LOG, new LogEvent(LogLevel::INFO, 'Added key to SSH agent.', $eventName, $this, array('event.task.action' => TaskInterface::ACTION_COMPLETED, 'output.resetLine' => true)));
         }
         $connection->delete($keyFile);
         if ($result->isSuccessful()) {
             return;
         }
     }
     $eventDispatcher->dispatch(AccompliEvents::LOG, new LogEvent(LogLevel::INFO, 'Failed adding key to SSH agent.', $eventName, $this, array('event.task.action' => TaskInterface::ACTION_FAILED, 'output.resetLine' => true)));
 }