-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdeploy-to-production.php.example
56 lines (40 loc) · 1.19 KB
/
deploy-to-production.php.example
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
<?php
/** Configuration */
$remote_directory = '';
$ssh_user = '';
$ssh_host = '';
/** Stop editing */
$local_site_directory = '.';
$excluded_files = array(
'*.DS_Store',
'deploy-to-*.php',
'.htaccess',
'.env',
'.git',
'.gitignore',
'.travis.yml',
'composer.json',
'composer.lock',
'keys',
'ruleset.xml',
'README.md',
);
////////////////////////
// Stop editing here! //
////////////////////////
function build_rysnc_exclusion(array $excluded_files){
$command_array = array();
foreach ($excluded_files as $file){
$command_array[] = "--exclude=$file";
}
return implode(' ', $command_array);
}
$excluded_files_string = build_rysnc_exclusion($excluded_files);
$change_ownership_to_user = "sudo chown -R {$ssh_user}: $remote_directory";
$change_ownership_to_apache = "sudo chown -R apache: $remote_directory";
echo '** Starting deployment process **' . "\r\n";
echo '** Syncing changes **' . "\r\n";
echo shell_exec("ssh -t $ssh_user@$ssh_host '$change_ownership_to_user'");
echo shell_exec("rsync -avz $excluded_files_string $local_site_directory $ssh_user@$ssh_host:'$remote_directory'");
echo shell_exec("ssh -t $ssh_user@$ssh_host '$change_ownership_to_apache'");
echo 'Complete';