Skip to content
Snippets Groups Projects
Commit 95c56a89 authored by Jared Hancock's avatar Jared Hancock
Browse files

deploy: Disable errors on deployment

Also, write js and css links to be forcibly reloaded by the browser after
deployment
parent 41f5457a
Branches
Tags
No related merge requests found
...@@ -87,6 +87,46 @@ class Deployment extends Unpacker { ...@@ -87,6 +87,46 @@ class Deployment extends Unpacker {
} }
} }
function copyFile($src, $dest) {
static $short = false;
static $version = false;
if (substr($src, -4) != '.php')
return parent::copyFile($src, $dest);
if (!$short) {
$hash = exec('git rev-parse HEAD');
$short = substr($hash, 0, 7);
}
if (!$version)
$version = exec('git describe');
if (!$short || !$version)
return parent::copyFile($src, $dest);
$source = file_get_contents($src);
$source = preg_replace(':<script(.*) src="(.*).js"></script>:',
'<script$1 src="$2.js?'.$short.'"></script>',
$source);
$source = preg_replace(':<link(.*) href="(.*).css"([^/>]*)/?>:', # <?php
'<link$1 href="$2.css?'.$short.'"$3/>',
$source);
// Set THIS_VERSION
$source = preg_replace("/^(\s*)define\s*\(\s*'THIS_VERSION'.*$/m",
"\1define('THIS_VERSION', '".$version."'); // Set by installer",
$source);
// Disable error display
$source = preg_replace("/^(\s*)ini_set\s*\(\s*'(display_errors|display_startup_errors)'.*$/m",
"$1ini_set('$2', '0'); // Set by installer",
$source);
if (!file_put_contents($dest, $source))
die("Unable to apply rewrite rules to ".$dest);
return true;
}
function run($args, $options) { function run($args, $options) {
$this->destination = $args['install-path']; $this->destination = $args['install-path'];
if (!is_dir($this->destination)) if (!is_dir($this->destination))
...@@ -122,7 +162,6 @@ class Deployment extends Unpacker { ...@@ -122,7 +162,6 @@ class Deployment extends Unpacker {
if (!$options['dry-run']) { if (!$options['dry-run']) {
if ($include != "{$this->destination}/include/") if ($include != "{$this->destination}/include/")
$this->change_include_dir($include); $this->change_include_dir($include);
$this->touch_version();
} }
if ($options['clean']) { if ($options['clean']) {
...@@ -134,30 +173,6 @@ class Deployment extends Unpacker { ...@@ -134,30 +173,6 @@ class Deployment extends Unpacker {
"*/.htaccess")); "*/.htaccess"));
} }
} }
function touch_version($version=false) {
if (!$version)
$version = exec('git describe');
if (!$version)
return false;
$bootstrap_php = $this->destination . '/bootstrap.php';
$lines = explode("\n", file_get_contents($bootstrap_php));
# Find the line that defines INCLUDE_DIR
$match = array();
foreach ($lines as &$line) {
// TODO: Change THIS_VERSION inline to be current `git describe`
if (preg_match("/(\s*)define\s*\(\s*'THIS_VERSION'/", $line, $match)) {
# Replace the definition with the new locatin
$line = $match[1] . "define('THIS_VERSION', '"
. $version
. "'); // Set by installer";
break;
}
}
if (!file_put_contents($bootstrap_php, implode("\n", $lines)))
die("Unable to write version information to bootstrap.php\n");
}
} }
Module::register('deploy', 'Deployment'); Module::register('deploy', 'Deployment');
......
...@@ -88,6 +88,10 @@ class Unpacker extends Module { ...@@ -88,6 +88,10 @@ class Unpacker extends Module {
return false; return false;
} }
function copyFile($src, $dest) {
return copy($src, $dest);
}
/** /**
* Copy from source to desination, perhaps recursing up to n folders. * Copy from source to desination, perhaps recursing up to n folders.
* Exclusions are also permitted. If any files match an MD5 sum, they * Exclusions are also permitted. If any files match an MD5 sum, they
...@@ -120,7 +124,7 @@ class Unpacker extends Module { ...@@ -120,7 +124,7 @@ class Unpacker extends Module {
if ($verbose) if ($verbose)
$this->stdout->write($target."\n"); $this->stdout->write($target."\n");
if (!$dryrun) if (!$dryrun)
copy($file, $target); $this->copyFile($file, $target);
} }
} }
if ($recurse) { if ($recurse) {
......
...@@ -134,6 +134,8 @@ if(($mds = glob("$stage_path/*.md"))) { ...@@ -134,6 +134,8 @@ if(($mds = glob("$stage_path/*.md"))) {
# Make an archive of the stage folder # Make an archive of the stage folder
$version = exec('git describe'); $version = exec('git describe');
$hash = exec('git rev-parse HEAD');
$short = substr($hash, 0, 7);
$pwd = getcwd(); $pwd = getcwd();
chdir($stage_path); chdir($stage_path);
...@@ -143,6 +145,10 @@ chdir($stage_path); ...@@ -143,6 +145,10 @@ chdir($stage_path);
shell_exec("sed -ri -e \" shell_exec("sed -ri -e \"
s/( *)define\('THIS_VERSION'.*/\\1define('THIS_VERSION', '$version');/ s/( *)define\('THIS_VERSION'.*/\\1define('THIS_VERSION', '$version');/
\" upload/bootstrap.php"); \" upload/bootstrap.php");
shell_exec("find upload -name '*.php' -print0 | xargs -0 sed -i -e '
s:<script\(.*\) src=\"\(.*\).js\"></script>:<script\\1 src=\"\\2.js?$short\"></script>:
s:<link\(.*\) href=\"\(.*\).css\"\(.*\)*/*>:<link\\1 href=\"\\2.css?$short\"\\3>:
'");
shell_exec("find upload -name '*.php' -print0 | xargs -0 sed -i -e \" shell_exec("find upload -name '*.php' -print0 | xargs -0 sed -i -e \"
s/\( *\)ini_set( *'display_errors'[^])]*);/\\1ini_set('display_errors', 0);/ s/\( *\)ini_set( *'display_errors'[^])]*);/\\1ini_set('display_errors', 0);/
s/\( *\)ini_set( *'display_startup_errors'[^])]*);/\\1ini_set('display_startup_errors', 0);/ s/\( *\)ini_set( *'display_startup_errors'[^])]*);/\\1ini_set('display_startup_errors', 0);/
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment