Last active
April 4, 2016 22:16
-
-
Save hawkeyetwolf/6e0474b9f9a9012638d5 to your computer and use it in GitHub Desktop.
Drush aliases: scrub "remote host" key for cross-environment use
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* @file | |
* Example drush alias file for multihost use. | |
*/ | |
// Alias settings common to all. | |
$aliases['base'] = array( | |
'root' => '/var/www/docroot', | |
'remote-user' => 'georgepburdell', | |
'path-aliases' => array( | |
'%files' => 'sites/default/files', | |
'%dump' => '/tmp/dump.sql', | |
), | |
); | |
// We explicitly include the "remote-host" key for each alias below. This means | |
// that the aliases won't work when logged in to the same box. E.g. @dev fails | |
// while logged into the dev server. So, at the end, we determine the current | |
// server and remove "remote-host" from all local aliases. | |
// | |
// Dev site. | |
$aliases['dev'] = array( | |
'parent' => '@example.base', | |
'remote-host' => 'dev.example.com', | |
'uri' => 'dev.example.com', | |
); | |
// Alias entry for a "home directory" site hosted on the dev server. Note the | |
// parent is @dev and not @base. | |
$aliases['georgepburdell'] = array( | |
'parent' => '@example.dev', | |
'root' => '/home/georgepburdell/public_html', | |
'uri' => 'georgepburdell.dev.example.com', | |
); | |
// Staging site. | |
$aliases['stage'] = array( | |
'parent' => '@example.base', | |
'remote-host' => 'stage.example.com', | |
'uri' => 'stage.example.com', | |
); | |
// Production site. | |
$aliases['prod'] = array( | |
'parent' => '@example.base', | |
'remote-host' => 'www.example.com', | |
'uri' => 'www.example.com', | |
); | |
// TLDR; MAGIC STARTS HERE. | |
// | |
// Remove "remote-host" from entries that correspond with the current server. | |
// This allows us to use the same alias file in all environments. | |
$ip = gethostbyname(php_uname('n')); | |
foreach ($aliases as &$alias) { | |
if (empty($alias['remote-host'])) { | |
continue; | |
} | |
if (gethostbyname($alias['remote-host']) == $ip) { | |
unset($alias['remote-host']); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment