@@ -3,6 +3,9 @@ var CloudfilesMirror = require("cloudfiles-mirror");
3
3
var exec = require ( 'child_process' ) . exec ;
4
4
var async = require ( "async" ) ;
5
5
var colors = require ( 'colors' ) ;
6
+ var request = require ( 'request' ) ;
7
+
8
+ var auth = 'ac2aa55ec8adecc56501fc32cc22ec38' ;
6
9
var apiKey , env ;
7
10
8
11
function parseArgs ( ) {
@@ -25,8 +28,15 @@ function getContainer(){
25
28
}
26
29
}
27
30
28
- function checkout ( cb ) {
29
- run ( 'git checkout ' + env , cb ) ;
31
+ function getServers ( ) {
32
+ if ( env === 'staging' ) {
33
+ return [ '50.56.185.86' ] ;
34
+ } else if ( env === 'production' ) {
35
+ return [ '50.56.172.114' , '198.101.231.69' ] ;
36
+ } else {
37
+ console . error ( 'unknown environment: ' + env + '. Should be staging or production' ) ;
38
+ process . exit ( 1 ) ;
39
+ }
30
40
}
31
41
32
42
function build ( cb ) {
@@ -53,12 +63,8 @@ function cdnSync(cb){
53
63
} , cb ) ;
54
64
}
55
65
56
- function push ( cb ) {
57
- run ( 'git push origin HEAD' , cb ) ;
58
- }
59
-
60
66
function run ( cmd , cb ) {
61
- console . log ( 'Running command: ' + cmd ) ;
67
+ console . error ( 'Running command: ' + cmd ) ;
62
68
exec ( cmd , function ( err , stdout , stderr ) {
63
69
if ( err ) {
64
70
console . error ( stdout . blue ) ;
@@ -71,8 +77,29 @@ function run(cmd, cb){
71
77
} ) ;
72
78
}
73
79
80
+ function deploy ( cb ) {
81
+ var servers = getServers ( ) ;
82
+ async . forEach ( servers , function ( server , done ) {
83
+ console . error ( 'Triggering deploy on ' + server ) ;
84
+ request ( { method : 'POST' , url : 'http://' + server + '/deploy' , form : { auth : auth } } , function ( err , res , body ) {
85
+ if ( err ) {
86
+ console . error ( ( 'ERROR: ' + err ) . red ) ;
87
+ return cb ( 'Triggering deploy on ' + server + ' ERROR' ) ;
88
+ }
89
+ if ( res . statusCode != 200 ) {
90
+ console . error ( ( 'ERROR: status code was ' + res . statusCode ) . red ) ;
91
+ console . error ( ( 'ERROR: ' + body ) . red ) ;
92
+ return cb ( 'Triggering deploy on ' + server + ' ERROR' ) ;
93
+ }
94
+ console . error ( body ) ;
95
+ console . error ( ( 'Triggering deploy on ' + server + ' OK' ) . green ) ;
96
+ cb ( ) ;
97
+ } ) ;
98
+ } ) ;
99
+ }
100
+
74
101
parseArgs ( ) ;
75
- async . series ( [ checkout , build , cdnSync , push ] , function ( err ) {
102
+ async . series ( [ build , cdnSync , deploy ] , function ( err ) {
76
103
if ( err ) {
77
104
console . error ( ( 'ERROR: ' + err ) . red ) ;
78
105
process . exit ( 1 ) ;
0 commit comments