Convox recently started redirecting http to https but allows you to keep this behaviour by setting the apps param RedirectHttps=No
. This script automates redeploying all applications in your current rack and lets you apply the RedirectHttps
parameter to certain apps. (UPGRADE_HTTP_APPS
)
Save as upgrade.php
and run using php upgrade.php
. (Authenticated Convox CLI is required)
<?php
define('RACK', 'org/rack');
define('UPGRADE_HTTP_APPS', ['my-http-app', 'my-second-http-app']);
exec('convox switch ' . RACK, $ret);
$appsCommandResult = [];
exec('convox apps', $appsCommandResult);
$apps = [];
// Get list of apps
foreach($appsCommandResult as $result) {
$matches = null;
preg_match('/([\w-_]*).*/', $result, $matches);
if(isset($matches[1]) && $matches[1] !== 'APP') {
$apps[$matches[1]] = '';
}
}
// For each app, find active release
foreach($apps as $app => $release) {
$releasesCommandResult = [];
exec('convox releases -a ' . $app, $releasesCommandResult);
foreach($releasesCommandResult as $result) {
$matches = null;
preg_match('/([\w-_]*).*active.*/', $result, $matches);
if(isset($matches[1])) {
$apps[$app] = $matches[1];
}
}
}
foreach($apps as $app => $release) {
//Promote each app
$promoteCommand = "convox releases promote {$release} -a {$app} --wait";
echo $promoteCommand;
echo "\n";
$deployCommandResult = '';
exec($promoteCommand, $deployCommandResult);
var_dump($deployCommandResult);
//If in UPGRADE_HTTP_APPS, set RedirectHttps=No
if(in_array($app, UPGRADE_HTTP_APPS)) {
$noHttpCommand = "convox apps params set RedirectHttps=No -a {$app} --wait";
echo $noHttpCommand;
echo "\n";
$noHttpCommandResult = '';
exec($noHttpCommand, $noHttpCommandResult);
var_dump($noHttpCommandResult);
}
}