コード例 #1
0
ファイル: MysqlTask.php プロジェクト: primat/deployer-org
 /**
  * @param \Cogeco\Build\Entity\Database $db
  * @param \Cogeco\Build\Entity\File $dumpFile
  * @param $dbName
  * @param array $tables
  * @throws \Cogeco\Build\Exception
  */
 public static function mysqlDump(Database $db, $dbName, array $tables = array(), File $dumpFile)
 {
     if (!is_array($tables) || count($tables) === 0) {
         $tablesParam = '';
     } else {
         $tablesParam = explode(' ', $tables) . ' ';
     }
     // Presentation
     self::log("- Getting dump of {$dbName}");
     if ($db->isRemote()) {
         Task::log(" from {$db->host->hostname}");
     }
     self::log("\n");
     // For use when converting a dump to SQLite
     // --compatible=ansi --skip-extended-insert --compact
     // Build the command
     $cmd = Config::get('mysqldump.bin') . " -vf -P {$db->port}";
     if ($db->isRemote()) {
         $cmd .= " -h {$db->host->hostname}";
     }
     // Create the folder if it doesn't exist already
     FileSystemTask::mkdir($dumpFile->dir->getPath());
     $cmd .= " -u {$db->account->username} -p{$db->account->password} {$dbName} {$tablesParam}| sed '/^\\/\\*\\!50013 DEFINER/d' > {$dumpFile->getPath()}";
     //$cmd .= " --result-file={$dumpFile->getPath()} -u {$db->account->username} -p{$db->account->password} {$dbName} {$tablesParam} 2>&1";
     self::runCmd($cmd);
     self::log("\n");
 }
コード例 #2
0
ファイル: App.php プロジェクト: primat/deployer-org
 /**
  * Initialize the build app
  */
 public static function init()
 {
     // Don't initialize more than once
     if (self::$startTime > 0) {
         return;
     }
     self::$startTime = time();
     //
     /*
      * Path to a directory where temporary files are created during script execution
      */
     define('BUILD_TMP_DIR', BUILD_ROOT_DIR . DIRECTORY_SEPARATOR . 'tmp');
     /*
      * Path to the directory where working copies are cached
      */
     define('BUILD_WORKING_COPY_DIR', BUILD_ROOT_DIR . DIRECTORY_SEPARATOR . 'working_copies');
     //define('BUILD_WORKING_COPY_DIR', BUILD_ROOT_DIR . DIRECTORY_SEPARATOR . self::$projectName . DIRECTORY_SEPARATOR . 'working_copies');
     // Try and figure out the full path to the currently running script
     $path = realpath($_SERVER['SCRIPT_FILENAME']);
     if ($path === false) {
         $path = realpath($_SERVER['SCRIPT_NAME']);
     }
     if ($path === false) {
         throw new \Exception('Unable to determine script path');
     }
     $pathParts = pathinfo($path);
     // Disable output buffering for "streaming" display through HTTP and get the path (parts) to the script
     if (!IS_CLI) {
         self::enableOutputFlush();
     }
     /*
      * Name of the script file that was called (file name without the file extension)
      */
     define('SCRIPT_FILE_BASENAME', $pathParts['filename']);
     /*
      * Path to the location that the script is running in
      */
     define('SCRIPT_DIR', $pathParts['dirname']);
     /*
      * Path to the location that the script is running in
      */
     define('SCRIPT_DB_DIR', SCRIPT_DIR . '/db');
     /*
      * Path to the location where email files are stored
      */
     define('BUILD_EMAILS_DIR', SCRIPT_DIR . "/emails");
     /*
      * Path to the location where log files are stored
      */
     define('BUILD_LOGS_DIR', SCRIPT_DIR . "/logs");
     /*
      * Register some important handlers
      */
     spl_autoload_register(array('self', 'autoload'));
     set_exception_handler(array('\\Cogeco\\Build\\Task', 'exceptionHandler'));
     register_shutdown_function(array('\\Cogeco\\Build\\Task', 'endOfScriptMaintenance'));
     /*
      * Load the default build configuration
      */
     //Config::loadFile(BUILD_ROOT_DIR . '/config-default.php');
     Config::set('datetime.slug', date('Y-m-d_H-i-s'));
 }
コード例 #3
0
ファイル: sync-db.php プロジェクト: primat/deployer-org
// *******************************
Config::enableLogging();
// ********************
// *** Initial output
//
Task::log("\n---------------------------------------\n");
Task::log("-------- Sync database\n\n");
// Prompt for user password, if it's not hardcoded
CliTask::promptAccountPassword($cogecoAccount);
// ********************
// Prompt user input
//
// Prepare a list of possible databases to sync from
$dbList = array($localPublicDb, $localPublicUBCDb, $localPublicPromo, $localPublicGBIncrease, $localDevPhoenixDb, $devPublicDb, $dev2PublicDb, $dev3PublicDb, $dev4PublicDb, $uatPublicDb, $preprodPublicDb);
// Prompt user to input a source database
$sourceDb = CliTask::promptDatabase($dbList, 'Choose a source database:');
Task::log("You chose " . $sourceDb->getDbName() . " on " . $sourceDb->getHost()->getHostname() . "\n\n");
if (($key = array_search($sourceDb, $dbList)) !== false) {
    unset($dbList[$key]);
}
// Prepare a list of possible databases to sync to
$destinationDb = CliTask::promptDatabase($dbList, 'Choose a destination database:');
Task::log("You chose " . $destinationDb->getDbName() . " on " . $destinationDb->getHost()->getHostname() . "\n\n");
CliTask::promptQuit('Continue? [y/n]: ');
// Dump DB to an sql script
$tmpDumpFile = new File(SCRIPT_DB_DIR, $sourceDb->getHost()->getHostname() . '-' . $sourceDb->getDbName() . '-' . Config::get('datetime.slug') . '.sql');
MysqlTask::mysqlDump($sourceDb, $sourceDb->getDbName(), array(), $tmpDumpFile);
// Import DB from the sql script
MysqlTask::importDump($destinationDb, $tmpDumpFile->getPath(), $destinationDb->getDbName());
// Delete the temporary script
//unlink($tmpDumpFile->getPath());
コード例 #4
0
ファイル: sync-repo.php プロジェクト: primat/deployer-org
use Cogeco\Build\Config;
use Cogeco\Build\Task;
use Cogeco\Build\Entity\RsyncOptions;
use Cogeco\Build\Entity\WorkingCopy;
use Cogeco\Build\Task\CliTask;
use Cogeco\Build\Task\FileSyncTask;
use Cogeco\Build\Task\SvnTask;
// Include the build script core
include_once __DIR__ . '/../../bootstrap.php';
// *******************************
// Script configuration
// *******************************
// *******************************
// Start the build script
// *******************************
Config::enableLogging();
// ********************
// *** Initial output
//
Task::log("\n---------------------------------------\n");
Task::log("-------- Sync repository\n\n");
// Prompt for user password, if it's not hardcoded
CliTask::promptAccountPassword($cogecoAccount);
// ********************
// Prompt user input
//
// Prompt user to input a local folder to sync
$workingCopy = CliTask::promptRepo();
Task::log("You chose " . $workingCopy->getRepoUrl() . "\n\n");
// Prompt user to chose a remote folder to sync to
$selectedDir = CliTask::promptDir(array($devDir, $dev2Dir, $uatDir, $uat2Dir, $uat3Dir, $preprodDir));
コード例 #5
0
ファイル: deploy-prod.php プロジェクト: primat/deployer-org
$syncDestinationDir1 = $maoDevTempDir;
$syncDestinationDir2 = $maoDev1Dir;
if ($build === 'prod') {
    // Prod setup
    $syncDestinationDir1 = $maoProdTempDir;
    $syncDestinationDir2 = $maoProdDir;
    $maoReleaseEmail->to = $maoReleaseEmailRecipients;
}
$rsyncOptions1 = new RsyncOptions($maoWcTrunk->dir, $syncDestinationDir1);
$rsyncOptions1->excludesAppend(array('/user_guide/', '/license.txt', 'application/logs/', '/dev/'));
$rsyncOptions2 = new RsyncOptions($syncDestinationDir1, $syncDestinationDir2);
$rsyncOptions2->useSsh(FALSE)->excludesAppend(array('/user_guide/', '/license.txt', 'application/logs/', '/dev/', '/application/config/production/routes.php'));
// *******************************
// Start the build script
// *******************************
Config::enableLogging(TRUE, TRUE);
// ********************
// *** Initial output
//
Task::log("\n---------------------------------------\n");
Task::log("-------- Deploy Prod\n\n");
// Chicken quit
if ($build === 'prod') {
    CliTask::promptQuit('Deploying to production! Continue? [y/n]: ');
}
// Prompt for user password, if it's not hardcoded
CliTask::promptAccountPassword($cogecoAccount);
// ********************
// *** SVN checkout
//
SvnTask::checkoutClean($workingCopy, $revisionToCheckOut);
コード例 #6
0
//	CliTask::promptQuit('Deploying to production! Continue? [y/n]: ');
//}
// Prompt for user password, if it's not hardcoded
CliTask::promptAccountPassword($cogecoAccount);
// ********************
// *** Checkout
//
SvnTask::checkoutClean($workingCopy, $revisionToCheckOut, 0);
SvnTask::createManifestFile($workingCopy, FALSE, TRUE);
// ********************
// *** Dump DB
//
Task::log("\n- Deploy schema {$sourceDbSchema} from {$sourceDb->host->hostname} ");
Task::log("to {$destinationDbSchema} on {$destinationDb->getHost()->hostname}\n\n");
//
$tmpDumpFile = new File(SCRIPT_DIR . '/db', "{$sourceDbSchema}-" . Config::get('datetime.slug') . '.sql');
MysqlTask::mysqlDump($sourceDb, $sourceDbSchema, array(), $tmpDumpFile);
// ********************
// *** Prep sync to intermediate remote location
//
Task::log("- Syncing revision {$workingCopy->info->commitRevision} with {$syncDestinationDir1->getPath()} on {$syncDestinationDir1->getHost()->hostname}\n\n");
//
FileSyncTask::sync($rsyncOptions1);
// ********************
// *** Deploy
//
TimerTask::start();
// Import DB
MysqlTask::importDump($destinationDb, $tmpDumpFile->getPath(), $destinationDbSchema);
//
Task::log("- Syncing intermediate directory {$syncDestinationDir1->path} with {$syncDestinationDir2->path}\n\n");
コード例 #7
0
ファイル: FileSyncTask.php プロジェクト: primat/deployer-org
 /**
  * Gets the Expect command tempalte the rsyn will run in to automate the interactive SSH password
  * @return string
  */
 private static function getExpectCommandTemplate()
 {
     return Config::get('expect.bin') . ' ' . Cygwin::cygPath(BUILD_ROOT_DIR) . '/source/expect/pass.exp "%s" "%s"';
 }
コード例 #8
0
ファイル: Task.php プロジェクト: primat/deployer-org
 /**
  * @param $message
  */
 public static function log($message)
 {
     if (self::$muteOutput || empty($message)) {
         return;
     }
     // Output to console/screen/web page/etc
     if (IS_CLI) {
         echo $message;
     } else {
         echo nl2br($message);
     }
     // Output to log file
     if (Config::get('logging.enabled')) {
         // Init the file handle if not done already
         if (self::$logFileHandle === NULL) {
             self::initLogFile();
         }
         self::writeLog($message);
     }
     flush();
 }
コード例 #9
0
ファイル: SvnTask.php プロジェクト: primat/deployer-org
 /**
  * @param $workingCopy
  * @param int $revision
  * @throws \Cogeco\Build\Exception
  */
 public static function update($workingCopy, $revision = 0)
 {
     $revision = (int) $revision;
     $revisionToUpdate = '';
     if ($revision > 0) {
         $revisionToUpdate = "-r{$revision} ";
     }
     self::log("- Updating to ");
     if ($revision > 0) {
         self::log("revision {$revision}\n");
     } else {
         self::log("head revision\n");
     }
     $cmd = Config::get('svn.bin') . " update {$workingCopy->dir->getPath()} {$revisionToUpdate}" . "--username {$workingCopy->account->username} " . "--password {$workingCopy->account->password} " . "--config-option config:miscellany:use-commit-times=yes " . "--non-interactive --trust-server-cert --no-auth-cache 2>&1";
     self::runCmd($cmd);
     self::log("\n");
 }