/**
  * Installs or updates the Composer binary.
  *
  * @param WorkspaceEvent           $event
  * @param string                   $eventName
  * @param EventDispatcherInterface $eventDispatcher
  *
  * @throws TaskRuntimeException when installing the Composer binary has failed.
  * @throws TaskRuntimeException when the workspace hasn't been created.
  */
 public function onPrepareWorkspaceInstallComposer(WorkspaceEvent $event, $eventName, EventDispatcherInterface $eventDispatcher)
 {
     $host = $event->getHost();
     $connection = $this->ensureConnection($host);
     $workspace = $event->getWorkspace();
     if ($workspace instanceof Workspace === false) {
         throw new TaskRuntimeException('The workspace of the host has not been created.', $this);
     }
     if ($connection->isFile($host->getPath() . '/composer.phar') === false) {
         $eventDispatcher->dispatch(AccompliEvents::LOG, new LogEvent(LogLevel::INFO, 'Installing the Composer binary...', $eventName, $this, array('event.task.action' => TaskInterface::ACTION_IN_PROGRESS)));
         $connection->changeWorkingDirectory($host->getPath());
         $connection->putFile(__DIR__ . '/../Resources/Composer/composer.phar', $host->getPath() . '/composer.phar');
         if ($connection->isFile($host->getPath() . '/composer.phar')) {
             $eventDispatcher->dispatch(AccompliEvents::LOG, new LogEvent(LogLevel::INFO, 'Installed the Composer binary.', $eventName, $this, array('event.task.action' => TaskInterface::ACTION_COMPLETED, 'output.resetLine' => true)));
         } else {
             throw new TaskRuntimeException('Failed installing the Composer binary.', $this);
         }
     }
     $eventDispatcher->dispatch(AccompliEvents::LOG, new LogEvent(LogLevel::INFO, 'Updating the Composer binary.', $eventName, $this, array('event.task.action' => TaskInterface::ACTION_IN_PROGRESS)));
     $connection->changeWorkingDirectory($host->getPath());
     $result = $connection->executeCommand('php composer.phar self-update');
     if ($result->isSuccessful()) {
         $eventDispatcher->dispatch(AccompliEvents::LOG, new LogEvent(LogLevel::INFO, 'Updated the Composer binary.', $eventName, $this, array('event.task.action' => TaskInterface::ACTION_COMPLETED, 'output.resetLine' => true)));
     } else {
         $eventDispatcher->dispatch(AccompliEvents::LOG, new LogEvent(LogLevel::WARNING, 'Failed updating the Composer binary.', $eventName, $this, array('event.task.action' => TaskInterface::ACTION_FAILED)));
     }
     $eventDispatcher->dispatch(AccompliEvents::LOG, new LogEvent(LogLevel::DEBUG, "{separator} Command output:{separator}\n{command.result}{separator}", $eventName, $this, array('command.result' => $result->getOutput(), 'separator' => "\n=================\n")));
 }
 /**
  * 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)));
 }
Пример #3
0
 /**
  * Initializes the SSH agent and adds the configured keys.
  *
  * @param WorkspaceEvent           $event
  * @param string                   $eventName
  * @param EventDispatcherInterface $eventDispatcher
  */
 public function onPrepareWorkspaceInitializeSSHAgent(WorkspaceEvent $event, $eventName, EventDispatcherInterface $eventDispatcher)
 {
     $this->host = $event->getHost();
     $connection = $this->ensureConnection($this->host);
     $eventDispatcher->dispatch(AccompliEvents::LOG, new LogEvent(LogLevel::NOTICE, 'Initializing SSH agent...', $eventName, $this, array('event.task.action' => TaskInterface::ACTION_IN_PROGRESS)));
     $result = $connection->executeCommand('eval $(ssh-agent)');
     if ($result->isSuccessful()) {
         $eventDispatcher->dispatch(AccompliEvents::LOG, new LogEvent(LogLevel::NOTICE, 'Initialized SSH agent. {output}', $eventName, $this, array('output' => trim($result->getOutput()), 'event.task.action' => TaskInterface::ACTION_COMPLETED, 'output.resetLine' => true)));
         foreach ($this->keys as $key) {
             $this->addKeyToSSHAgent($event->getWorkspace(), $connection, $key, $eventName, $eventDispatcher);
         }
     } else {
         $eventDispatcher->dispatch(AccompliEvents::LOG, new LogEvent(LogLevel::WARNING, 'Failed initializing SSH agent.', $eventName, $this, array('event.task.action' => TaskInterface::ACTION_FAILED, 'output.resetLine' => true)));
     }
 }