コード例 #1
0
ファイル: DeployPush.php プロジェクト: stonedz/pff2
 /**
  * Publish a site using
  *
  * @param InputInterface $input
  * @param OutputInterface $output
  * @param string $profile_name
  */
 protected function publish(InputInterface $input, OutputInterface $output, $profile_name)
 {
     $output->writeln('<info>Publishing to ' . $profile_name . '...</info>');
     $parser = new Parser();
     $profile_config = $parser->parse(file_get_contents('deployement/publish_' . $profile_name . '.yml'));
     if (!CommandUtils::checkCommand('rsync')) {
         $output->writeln('<error>rsync not installed, please install it. Exiting now...</error>');
         return 1;
     }
     if ($profile_config['use_pem']) {
         $command = 'rsync -rltDvze "ssh -i ' . $profile_config['pem_path'] . '" ';
     } else {
         $command = 'rsync -rltDvz ';
     }
     foreach ($profile_config['exclude'] as $exclude) {
         $command .= '--exclude \'' . $exclude . '\' ';
     }
     if (substr($profile_config['remote_dir'], -1, 1) != '/') {
         $profile_config['remote_dir'] .= '/';
     }
     $command .= '. ' . $profile_config['username'] . '@' . $profile_config['host'] . ':' . $profile_config['remote_dir'];
     $chmod = array('chown -R ' . $profile_config['username'] . ':' . $profile_config['remote_group'] . ' ' . $profile_config['remote_dir'], 'chmod -R 750 ' . $profile_config['remote_dir'], 'chmod -R 770 ' . $profile_config['remote_dir'] . 'app/logs', 'chmod -R 770 ' . $profile_config['remote_dir'] . 'app/proxies', 'chmod -R 770 ' . $profile_config['remote_dir'] . 'app/public', 'chmod -R 770 ' . $profile_config['remote_dir'] . 'app/tmp');
     $permissions_commands = 'ssh ' . ($profile_config['use_pem'] ? '-i ' . $profile_config['pem_path'] : '') . ' ' . $profile_config['username'] . '@' . $profile_config['host'] . ' ' . ($profile_config['use_sudo'] ? 'sudo' : '') . ' \'';
     foreach ($chmod as $c) {
         $permissions_commands .= $c . ' && ';
     }
     $permissions_commands = substr($permissions_commands, 0, -3);
     $permissions_commands .= '\'';
     // PUBLISH
     $dump_commands = $input->getOption('dump-commands');
     if ($dump_commands) {
         $output->writeln($command);
     } else {
         $output->writeln('Publishing with rsync, please wait (it may take a while)...');
         passthru($command);
         $output->writeln('<info>PUBLISH DONE</info>');
     }
     // OPTIMIZE
     $run_optimize = $profile_config['always_run_optimize'];
     if ($run_optimize) {
         $output->writeln('Run optimizations...');
         $command = 'ssh ' . ($profile_config['use_pem'] ? '-i ' . $profile_config['pem_path'] : '') . ' ' . $profile_config['username'] . '@' . $profile_config['host'] . ' ' . '\'cd ' . $profile_config['remote_dir'] . ' && vendor/bin/pff deploy:optimize\'';
         if ($dump_commands) {
             $output->writeln($command);
         } else {
             passthru($command);
         }
         $output->writeln('<info>OPTIMIZE DONE</info>');
     }
     // PERMISSIONS
     $output->writeln('Setting permissions...');
     if ($dump_commands) {
         $output->writeln($permissions_commands);
     } else {
         passthru($permissions_commands);
     }
     $output->writeln('<info>PERMISSIONS DONE</info>');
 }
コード例 #2
0
ファイル: BackupDatabase.php プロジェクト: stonedz/pff2
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $questionHelper = $this->getHelper('question');
     if (!CommandUtils::checkCommand('mysqldump')) {
         $output->writeln('<error>Mysql client not found. Please install it!</error>');
         return;
     }
     require 'app/config/config.user.php';
     $mysql_port = $input->getOption('port');
     $dev = $pffConfig['development_environment'];
     if ($dev) {
         $dbUser = $pffConfig['databaseConfigDev']['user'];
         $dbHost = $pffConfig['databaseConfigDev']['host'];
         $dbName = $pffConfig['databaseConfigDev']['dbname'];
         $dbPass = $pffConfig['databaseConfigDev']['password'];
         if ($mysql_port !== 0) {
             $dbPort = $mysql_port;
         } elseif (isset($pffConfig['databaseConfigDev']['port'])) {
             $dbPort = $pffConfig['databaseConfigDev']['port'];
         } else {
             $dbPort = 3306;
         }
     } else {
         $dbUser = $pffConfig['databaseConfig']['user'];
         $dbHost = $pffConfig['databaseConfig']['host'];
         $dbName = $pffConfig['databaseConfig']['dbname'];
         $dbPass = $pffConfig['databaseConfig']['password'];
         if ($mysql_port !== 0) {
             $dbPort = $mysql_port;
         } elseif (isset($pffConfig['databaseConfig']['port'])) {
             $dbPort = $pffConfig['databaseConfig']['port'];
         } else {
             $dbPort = 3306;
         }
     }
     $backup_prefix = $dbName . '-BKP-';
     $backup_name = $backup_prefix . date("dmY-Hi") . '.sql';
     $backup_dir = $input->getOption('backup-dir');
     $output->writeln('Checking for backup dir...');
     if (!file_exists($backup_dir)) {
         $question = new ConfirmationQuestion('<question>Backup dir ' . $backup_dir . ' does not exists, create?</question>', 'n');
         if ($questionHelper->ask($input, $output, $question)) {
             if (mkdir($backup_dir, 0755, true)) {
                 $output->writeln('<info>DONE</info>');
             } else {
                 $output->writeln('<error>ERROR</error>');
                 exit(1);
             }
         } else {
             $output->writeln('<error>ERROR</error>');
             exit(1);
         }
     }
     if (substr($backup_dir, -1) != '/') {
         $backup_dir .= '/';
     }
     $command = "mysqldump -u{$dbUser} -p{$dbPass} -h{$dbHost} -P{$dbPort} {$dbName} > {$backup_dir}{$backup_name}";
     $output->write('Generating db backup for $dbName...');
     exec($command, $res, $ret);
     if (0 == $ret) {
         $output->writeln('<info>DONE</info>');
         $output->writeln('<info>Backup written in ' . $backup_dir . '' . $backup_name . '</info>');
     } else {
         $output->writeln('<error>ERROR</error>');
         foreach ($res as $line) {
             $output->writeln($line);
         }
     }
     $this->cleanOldBkp($input, $output, $backup_dir, $backup_prefix);
 }
コード例 #3
0
ファイル: DeployCreate.php プロジェクト: stonedz/pff2
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     /** @var QuestionHelper $questionHelper */
     $questionHelper = $this->getHelper('question');
     $possible_users = array('www-data', 'apache', 'ubuntu', 'root');
     $question = new Question('<question>Username:</question> ');
     $question->setAutocompleterValues($possible_users);
     $username = $questionHelper->ask($input, $output, $question);
     if (!$username) {
         $output->writeln('you need to enter a username!');
         return 1;
     }
     $question = new Question('<question>Host:</question> ');
     $host = $questionHelper->ask($input, $output, $question);
     if (!$host) {
         $output->writeln('you need to enter a host!');
         return 1;
     }
     $question = new Question('<question>Remote path:</question> ');
     $path = $questionHelper->ask($input, $output, $question);
     if (!$path) {
         $output->writeln('you need to enter a path!');
         return 1;
     }
     $question = new ConfirmationQuestion('<question>Always run deploy:optimize after publish? (y/n)</question> ', false);
     $optimize = $questionHelper->ask($input, $output, $question);
     $question = new ConfirmationQuestion('<question>Use sudo to change file permission on remote server? (y/n)</question> ', false);
     $use_sudo = $questionHelper->ask($input, $output, $question);
     $possible_groups = array('www-data', 'apache', 'httpd');
     $question = new Question('<question>Remote group:</question> ', 'www-data');
     $question->setAutocompleterValues($possible_groups);
     $remote_group = $questionHelper->ask($input, $output, $question);
     $question = new ConfirmationQuestion('<question>Ue a .pem file to publish? (y/n)</question> ', false);
     $use_pem = $questionHelper->ask($input, $output, $question);
     if ($use_pem) {
         $question = new Question('<question>.pem file path (absolute or relative):</question> ');
         $pem_path = $questionHelper->ask($input, $output, $question);
     } else {
         $pem_path = false;
     }
     $custom_excludes = $input->getOption('exclude');
     $standard_excludes = array(".git*", 'app/public/files/*', 'app/config/config.user.php', '.htaccess', 'backups', 'app/views/smarty/compiled_templates/*', 'app/proxies/*', 'app/public/admin/include/dbcommon.php', 'app/public/admin/connections/ConnectionManager.php', '*.pem');
     $excludes = array_merge($custom_excludes, $standard_excludes);
     $yamlDumper = new Dumper();
     $toDump = array('username' => $username, 'host' => $host, 'remote_dir' => $path, 'always_run_optimize' => $optimize, 'remote_group' => $remote_group, 'use_sudo' => $use_sudo, 'exclude' => $excludes, 'use_pem' => $use_pem, 'pem_path' => $pem_path);
     $yaml = $yamlDumper->dump($toDump, 2);
     $profile_name = $input->getArgument('profile-name');
     CommandUtils::checkDeployement();
     while (file_exists('deployement/publish_' . $profile_name . '.yml')) {
         $question = new ConfirmationQuestion('<question>deployement/publish_' . $profile_name . '.yml already exists, overwrite it?', false);
         $answer = $questionHelper->ask($input, $output, $question);
         if (!$answer) {
             $question = new Question('<question>New porfile name:</question> ');
             $profile_name = $questionHelper->ask($input, $output, $question);
         } else {
             break;
         }
     }
     if (file_put_contents('deployement/publish_' . $profile_name . '.yml', $yaml)) {
         $output->writeln('<info>Publish profile created at deployement/publish_' . $profile_name . '.yml</info>');
     } else {
         $output->writeln('<error>Error while writing output file!</error>');
     }
 }
コード例 #4
0
ファイル: GenerateFigFiles.php プロジェクト: stonedz/pff2
 protected function create_db_volume_data(InputInterface $input, OutputInterface $output, $container_name, QuestionHelper $question_helper)
 {
     if (CommandUtils::checkCommand('docker')) {
         $command = 'docker';
     } elseif (CommandUtils::checkCommand('docker.io')) {
         $command = 'docker.io';
     } else {
         $output->writeln('<error>Can\'t find docker executable.</error>');
         return;
     }
     $question = new ConfirmationQuestion('<question>Do you want to use sudo? </question>', 'n');
     if ($question_helper->ask($input, $output, $question)) {
         $command = 'sudo ' . $command;
     }
     $comman_create = $command . ' run -v /var/lib/mysql --name ' . $container_name . ' busybox true';
     exec($comman_create, $res, $ret);
     if (0 == $ret) {
         $output->writeln('<info>Db data volume container created.</info>');
     } else {
         $output->writeln('<error>Cannot create db data volume container using the following command: </error>');
         $output->writeln('<error>' . $comman_create . '</error>');
     }
 }