deployer/recipe/deploy/prepare.php

50 lines
1.8 KiB
PHP
Raw Normal View History

2016-11-19 15:13:32 +07:00
<?php
/* (c) Anton Medvedev <anton@medv.io>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Deployer;
desc('Preparing server for deploy');
task('deploy:prepare', function () {
// Check if shell is POSIX-compliant
try {
$result = run('echo $0')->toString();
if ($result == 'stdin: is not a tty') {
throw new \RuntimeException(
"Looks like ssh inside another ssh.\n" .
"Help: http://goo.gl/gsdLt9"
);
}
} catch (\RuntimeException $e) {
$formatter = Deployer::get()->getHelper('formatter');
$errorMessage = [
"Shell on your server is not POSIX-compliant. Please change to sh, bash or similar.",
"Usually, you can change your shell to bash by running: chsh -s /bin/bash",
];
write($formatter->formatBlock($errorMessage, 'error', true));
throw $e;
}
run('if [ ! -d {{deploy_path}} ]; then mkdir -p {{deploy_path}}; fi');
// Check for existing /current directory (not symlink)
$result = run('if [ ! -L {{deploy_path}}/current ] && [ -d {{deploy_path}}/current ]; then echo true; fi')->toBool();
if ($result) {
throw new \RuntimeException('There already is a directory (not symlink) named "current" in ' . get('deploy_path') . '. Remove this directory so it can be replaced with a symlink for atomic deployments.');
}
// Create metadata .dep dir.
run("cd {{deploy_path}} && if [ ! -d .dep ]; then mkdir .dep; fi");
// Create releases dir.
run("cd {{deploy_path}} && if [ ! -d releases ]; then mkdir releases; fi");
// Create shared dir.
run("cd {{deploy_path}} && if [ ! -d shared ]; then mkdir shared; fi");
});