2016-11-19 15:13:32 +07:00
< ? php
namespace Deployer ;
2019-08-12 20:59:59 +03:00
use Deployer\Exception\Exception ;
2017-03-19 22:52:05 +07:00
use function Deployer\Support\str_contains ;
desc ( 'Preparing host for deploy' );
2020-04-25 23:00:08 +03:00
task ( 'deploy:setup' , function () {
2016-11-19 15:13:32 +07:00
// Check if shell is POSIX-compliant
2017-08-12 18:06:21 +03:00
$result = run ( 'echo $0' );
2017-03-19 22:52:05 +07:00
if ( ! str_contains ( $result , 'bash' ) && ! str_contains ( $result , 'sh' )) {
throw new \RuntimeException (
'Shell on your server is not POSIX-compliant. Please change to sh, bash or similar.'
);
2016-11-19 15:13:32 +07:00
}
run ( 'if [ ! -d {{deploy_path}} ]; then mkdir -p {{deploy_path}}; fi' );
2021-09-24 10:49:16 +02:00
cd ( '{{deploy_path}}' );
2016-11-19 15:13:32 +07:00
// Check for existing /current directory (not symlink)
2020-10-09 01:35:42 +02:00
$result = test ( '[ ! -L {{current_path}} ] && [ -d {{current_path}} ]' );
2016-11-19 15:13:32 +07:00
if ( $result ) {
2020-10-09 01:35:42 +02:00
throw new Exception ( 'There already is a directory (not symlink) in ' . get ( 'current_path' ) . '. Remove this directory so it can be replaced with a symlink for atomic deployments.' );
2016-11-19 15:13:32 +07:00
}
// Create metadata .dep dir.
2021-09-24 10:49:16 +02:00
run ( " if [ ! -d .dep ]; then mkdir .dep; fi " );
2016-11-19 15:13:32 +07:00
// Create releases dir.
2021-09-24 10:49:16 +02:00
run ( " if [ ! -d releases ]; then mkdir releases; fi " );
2016-11-19 15:13:32 +07:00
// Create shared dir.
2021-09-24 10:49:16 +02:00
run ( " if [ ! -d shared ]; then mkdir shared; fi " );
2016-11-19 15:13:32 +07:00
});