/** * Take a set of rsync options, build the command then run it * @param RsyncOptions $rsync */ public static function sync(RsyncOptions $rsync) { $remoteHost = $rsync->getRemoteHost(); if (empty($rsync->identityFilePath) && !IS_CLI) { // No CLI and no identity means one must be generated temporarily SshTask::GenerateTemporaryKeyPair($remoteHost); } $command = self::getRsyncCommand($rsync); // Adjust the command if we are using expect if (IS_CLI && !empty($remoteHost)) { // IS_CLI && $cmdTemplate = self::getExpectCommandTemplate(); $command = sprintf($cmdTemplate, addslashes($command), addslashes($remoteHost->account->password)); } else { self::log($command . "\n\n"); } self::runCmd($command); self::log("\n\n"); }
$changesText = ViewTask::getLogEntriesText($logEntries); $changesHtml = ViewTask::getLogEntriesHtml($logEntries); // Load the email templates with the changes $emailText = ViewTask::load('views/template-release-text.php', array('changes' => $changesText), TRUE); $emailHtml = ViewTask::load('views/template-release-html.php', array('changes' => $changesHtml), TRUE); // Create the emails as files $emailFileBaseName = "release-prod-r{$workingCopy->info->commitRevision}"; EmailTask::createEmailFiles($emailFileBaseName, $emailHtml, $emailText); // ******************** // *** Deploy intermediate // // Sync files from the working copy to the temporary prod directory FileSyncTask::sync($rsyncOptions1); // Task::log("- Syncing intermediate directory {$syncDestinationDir1->path} with {$syncDestinationDir2->path}\n\n"); // $rsyncCommand = FileSyncTask::getRsyncCommand($rsyncOptions2); SshTask::exec($syncDestinationDir2->getHost(), $rsyncCommand); Task::log("\n"); // ******************** // *** Tag release // if ($build === 'prod') { SvnTask::tagRelease($maoTag, $workingCopy->dir->path, "Release to production - Revision: {$workingCopy->info->commitRevision}"); } // ******************** // *** Notify // $maoReleaseEmail->bodyHtml = $emailHtml; $maoReleaseEmail->bodyText = $emailText; EmailTask::sendEmail($emailConnector, $maoReleaseEmail);
// Script arguments // ******************************* if (!isset($argv[1]) || $argv[1] !== 'dev' && $argv[1] !== 'uat' && $argv[1] !== 'prod') { echo "Usage: php " . $argv[0] . " dev|uat|prod\n"; exit(1); } // ******************************* // Script configuration // ******************************* $host = $maoDevHost; if ($argv[1] == 'uat') { $host = $maoUatHost; } else { if ($argv[1] == 'prod') { $host = $maoProdHost; } } // ******************************* // Start the build script // ******************************* // *** // Initial output Task::log("\n---------------------------------------\n"); Task::log("-------- Clear memcached on " . $host->getHostname() . " ({$argv[1]})\n\n"); // *** // Prompt for user password, if it's not hardcoded CliTask::promptAccountPassword($cogecoAccount); // *** $command = "php /var/www/scripts/memcached-clear.php"; SshTask::exec($host, $command); Task::log("- Clearing memcached completed\n");
/** * Execute a one-off command on a remote host * @param \Cogeco\Build\Entity\Host $host The host to run the command on * @param string $command The actual command to execute * @param bool $printOutput Whether or not to display the output from the command * @throws \Cogeco\Build\Exception */ public static function exec(Host $host, $command, $printOutput = TRUE) { // Make sure there is a connection open $ssh = self::connect($host); // log the command //self::log("{$host->account->username}@{$host->hostname}: $command\n"); // Execute the command if ($printOutput) { $ssh->exec($command, function ($str) { SshTask::log($str); }); self::log("\n"); } else { $ssh->exec($command); } self::checkCmdExceptions($ssh); }
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); SvnTask::createManifestFile($workingCopy); // ******************** // *** Activate maintenance mode // // Upload the maintenance route file SshTask::uploadFile($maintenanceFileSource, $maintenanceFileDestination); // ******************** // *** Deploy files // // Sync files from the deployer working copy to the temporary prod directory FileSyncTask::sync($rsyncOptions1); // Sync files from the intermediate prod dir to the live prod directory Task::log("- Syncing intermediate directory {$syncDestinationDir1->path} with {$syncDestinationDir2->path}\n\n"); $rsyncCommand = FileSyncTask::getRsyncCommand($rsyncOptions2); SshTask::exec($syncDestinationDir2->getHost(), $rsyncCommand); Task::log("\n"); // *** // Activate the .htaccess maintenance mode and allow users from the Cogeco network to see the app $command = "php /var/www/scripts/maintenance.php on {$server}"; SshTask::exec($syncDestinationDir2->getHost(), $command); // Delete the production/routes.php SshTask::deleteFile($maintenanceFileDestination); // And let the sanity checking begin...
// Convert log entries into text and html $changesText = ViewTask::getLogEntriesText($logEntries); $changesHtml = ViewTask::getLogEntriesHtml($logEntries); // Load the email templates with the changes $emailText = ViewTask::load('views/template-release-text.php', array('changes' => $changesText), TRUE); $emailHtml = ViewTask::load('views/template-release-html.php', array('changes' => $changesHtml), TRUE); // Create the emails as files $emailFileBaseName = "release-prod-r{$workingCopy->info->commitRevision}"; EmailTask::createEmailFiles($emailFileBaseName, $emailHtml, $emailText); // ******************** // *** Tag release // if ($build === 'prod') { SvnTask::tagRelease($maoTag, $workingCopy->dir->path, "Release to production - Revision: {$workingCopy->info->commitRevision}\n"); } // ******************** // *** Notify // $maoReleaseEmail->bodyHtml = $emailHtml; $maoReleaseEmail->bodyText = $emailText; try { EmailTask::sendEmail($emailConnector, $maoReleaseEmail); } catch (\Exception $e) { Task::log($e->getMessage()); } // ******************** // *** Deactivate maintenance mode // $command = "php /var/www/scripts/maintenance-mode.php off prod"; SshTask::exec($remoteHost, $command);
// ******************************* // Start the build script // ******************************* Config::enableLogging(); // ******************** // *** Initial output // Task::log("\n---------------------------------------\n"); Task::log("- Move cogeco.ca orders.log to secured shared drive\n\n"); // Prompt for user password, if it's not hardcoded CliTask::promptAccountPassword($cogecoAccount); // ******************** // *** Move the file to the shared drive // // Firstly, move it on the remote server SshTask::moveFile($remoteFileOld, $remoteFileNew->getPath()); //SshTask::copyFile($remoteFileOld, $remoteFileNew->getPath()); // Sync from the remote server to the shared drive FileSyncTask::sync($rsyncOptions); // Verify that the file was created on the shared drive and then delete it on the remote server if it exists if (!is_file($destinationFile->getPath())) { throw new \Exception('File was not successfully copied to the shared drive!'); } //If the file was successfully transferred, delete it on the remote host //SshTask::deleteFile($remoteFileNew); // ******************** // *** Notify // $pathsHtml = <<<HTML <p> \t<a href="file:{$sharedDestinationDir}">