-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdeploy.php
69 lines (53 loc) · 1.66 KB
/
deploy.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
64
65
66
67
68
69
#!/usr/bin/php
<?php
// Command line and input parameters
$options = getopt("c:p:e:h");
if (isset($options['h'])) {
print "Usage: $prog [-c current commit/tag] [-p previous commit/tag] [-e environment]\n";
print "User registration from US\n\n";
print "Options:\n\n";
print " -c current commit/tag\n";
print " -p previous commit/tag\n";
print " -e environment 'beta' or 'live'\n";
print " -h This menu\n\n";
exit;
}
$servers = [
'beta' => 'beta-kagogo1.rhcloud.com',
'live' => 'local-kagogo.rhcloud.com'];
$usernames = [
'beta' => '53c6efe8500446192c00004b',
'live' => '53c5750ce0b8cdf7b900039e'
];
$output = shell_exec("git diff --name-only {$options['c']} {$options['p']}");
echo "\n".$output."\n";
echo "Are you sure you want to deploy this? Type 'yes' to continue: ";
$line = fgets(STDIN);
if(trim($line) != 'yes'){
echo "ABORTING!\n";
exit;
}
$output = explode("\n", $output);
$commands = [];
foreach($output as $file){
if(!empty($file))
$commands[] = "wget https://xueenda:[email protected]/xueenda/kagogo/raw/stripe_payment/{$file} -O ./app-root/repo/{$file}";
}
$commands[] = "gear stop; gear start";
$connection = ssh2_connect($servers[$options['e']], 22, array('hostkey'=>'ssh-rsa'));
if (ssh2_auth_pubkey_file($connection, $usernames[$options['e']],
'/Users/exue/.ssh/id_rsa.pub',
'/Users/exue/.ssh/id_rsa')) {
} else {
die("Public Key Authentication Failed\n");
}
foreach ($commands as $command) {
echo $command."\n";
$stream = ssh2_exec($connection, $command);
}
stream_set_blocking( $stream, true );
while($cmd = fread($stream,4096)){
echo $cmd;
}
fclose($stream);
echo "Done!\n";