/** * 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>'); }
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); }
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>'); } }