/** * Saves a YAML configuration file to a path within the release. * * @param InstallReleaseEvent $event * @param string $eventName * @param EventDispatcherInterface $eventDispatcher */ public function onInstallReleaseCreateOrUpdateConfiguration(InstallReleaseEvent $event, $eventName, EventDispatcherInterface $eventDispatcher) { $release = $event->getRelease(); $this->gatherEnvironmentVariables($release); $connection = $this->ensureConnection($release->getWorkspace()->getHost()); $configurationFile = $release->getPath() . $this->configurationFile; $configurationDistributionFile = $configurationFile . '.dist'; $context = array('action' => 'Creating', 'configurationFile' => $configurationFile, 'event.task.action' => TaskInterface::ACTION_IN_PROGRESS); if ($connection->isFile($configurationFile)) { $context['action'] = 'Updating'; } $eventDispatcher->dispatch(AccompliEvents::LOG, new LogEvent(LogLevel::NOTICE, '{action} configuration file "{configurationFile}"...', $eventName, $this, $context)); $yamlConfiguration = $this->getYamlConfiguration($connection, $release->getWorkspace()->getHost()->getStage(), $configurationFile, $configurationDistributionFile); if ($connection->putContents($configurationFile, $yamlConfiguration)) { $context['event.task.action'] = TaskInterface::ACTION_COMPLETED; if ($context['action'] === 'Creating') { $context['action'] = 'Created'; } else { $context['action'] = 'Updated'; } $eventDispatcher->dispatch(AccompliEvents::LOG, new LogEvent(LogLevel::NOTICE, '{action} configuration file "{configurationFile}".', $eventName, $this, $context)); } else { $context['event.task.action'] = TaskInterface::ACTION_FAILED; $context['action'] = strtolower($context['action']); $eventDispatcher->dispatch(AccompliEvents::LOG, new LogEvent(LogLevel::WARNING, 'Failed {action} configuration file "{configurationFile}".', $eventName, $this, $context)); } }
/** * Sets the correct permissions and group for the configured path. * * @param InstallReleaseEvent $event * @param string $eventName * @param EventDispatcherInterface $eventDispatcher * * @throws TaskRuntimeException */ public function onInstallReleaseUpdateFilePermissions(InstallReleaseEvent $event, $eventName, EventDispatcherInterface $eventDispatcher) { $host = $event->getRelease()->getWorkspace()->getHost(); $connection = $this->ensureConnection($host); $eventDispatcher->dispatch(AccompliEvents::LOG, new LogEvent(LogLevel::NOTICE, 'Updating permissions for the configured paths...', $eventName, $this, array('event.task.action' => TaskInterface::ACTION_IN_PROGRESS))); $releasePath = $event->getRelease()->getPath(); $result = true; foreach ($this->paths as $path => $pathSettings) { $result = $result && $this->updateFilePermissions($connection, $releasePath, $path, $pathSettings); } if ($result === true) { $eventDispatcher->dispatch(AccompliEvents::LOG, new LogEvent(LogLevel::NOTICE, 'Updated permissions for the configured paths.', $eventName, $this, array('event.task.action' => TaskInterface::ACTION_COMPLETED, 'output.resetLine' => true))); } else { throw new TaskRuntimeException('Failed updating the permissions for the configured paths.', $this); } }
/** * Runs the Composer install command to install the dependencies for the release. * * @param InstallReleaseEvent $event * @param string $eventName * @param EventDispatcherInterface $eventDispatcher * * @throws TaskRuntimeException */ public function onInstallReleaseExecuteComposerInstall(InstallReleaseEvent $event, $eventName, EventDispatcherInterface $eventDispatcher) { $release = $event->getRelease(); $host = $release->getWorkspace()->getHost(); $connection = $this->ensureConnection($host); $eventDispatcher->dispatch(AccompliEvents::LOG, new LogEvent(LogLevel::NOTICE, 'Installing Composer dependencies.', $eventName, $this, array('event.task.action' => TaskInterface::ACTION_IN_PROGRESS))); $authenticationFile = $release->getPath() . '/auth.json'; if (empty($this->authentication) === false) { $connection->putContents($authenticationFile, json_encode($this->authentication)); } $connection->changeWorkingDirectory($host->getPath()); $result = $connection->executeCommand(sprintf('php composer.phar install --no-interaction --working-dir="%s" --no-dev --no-scripts --optimize-autoloader', $release->getPath())); if ($connection->isFile($authenticationFile)) { $connection->delete($authenticationFile); } if ($result->isSuccessful()) { $eventDispatcher->dispatch(AccompliEvents::LOG, new LogEvent(LogLevel::NOTICE, 'Installed Composer dependencies.', $eventName, $this, array('event.task.action' => TaskInterface::ACTION_COMPLETED, 'output.resetLine' => true))); $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"))); } else { throw new TaskCommandExecutionException('Failed installing Composer dependencies.', $result, $this); } }