forked from cocoonprojects/welo-backend
-
Notifications
You must be signed in to change notification settings - Fork 0
/
idxfile.php
63 lines (53 loc) · 1.74 KB
/
idxfile.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
<?php
use Idephix\Idephix;
$targets = array(
'stage-ora' => array(
'hosts' => array('10.250.2.235'),
'ssh_params' => ['user' => 'cocoon'],
'deploy' => array(
'local_base_dir' => __DIR__,
'remote_base_dir' => '/var/www/vhosts/cocoon/',
'rsync_exclude_file' => 'deploy_exclude'
),
),
'stage' => array(
'hosts' => array('10.250.2.235'),
'ssh_params' => ['user' => 'cocoon'],
'deploy' => array(
'local_base_dir' => __DIR__,
'remote_base_dir' => '/var/www/vhosts/welo-stage/',
'rsync_exclude_file' => 'deploy_exclude'
),
),
'prod' => array(
'hosts' => array('10.250.2.235'),
'ssh_params' => ['user' => 'cocoon'],
'deploy' => array(
'local_base_dir' => __DIR__,
'remote_base_dir' => '/var/www/vhosts/welo-prod/',
'rsync_exclude_file' => 'deploy_exclude'
),
),
);
$idx = new Idephix($targets);
$deploy = function($go = false) use ($idx)
{
$target = $idx->getCurrentTarget();
if ($target === null) {
throw new \InvalidArgumentException(
"Please provide a valid target with --env=<target>"
);
}
$host = $idx->getCurrentTargetHost();
$user = $target->get('ssh_params.user');
$path = $target->get('deploy.remote_base_dir');
$opts = '-rlDcz --no-perms --force --delete --progress';
$opts .= ' --exclude-from=' . $target->get('deploy.rsync_exclude_file');
$dryrun = $go ? '' : '--dry-run';
$idx->local("rsync $opts $dryrun -e 'ssh' . $user@$host:$path");
if ($go) {
$idx->remote("cd $path && composer install --no-dev -o");
}
};
$idx->add('deploy', $deploy);
$idx->run();