const git = require('simple-git');
const firebase = require('firebase')
const config = require('./config')

// const path = __dirname + '/iotos';
// git(path).then etc..

firebase.initializeApp(config);

var ref = firebase.database().ref().child("servers")

ref.child(config.device).on('value', deploy)

// ref.child(config.device).on('value', function (data) {
// 	//console.log(data.val())
// 	deploy();
// })

function deploy (data) {
  console.log('Starting Deploying aplication ...');
	git()
	.then(function() {
		console.log('Starting pull ... ');
	})
	.pull(function(err, update) {
		if(update && update.summary.changes) {
			console.log('processing and restarting app ...');
		}
	})
	.then(function() {
		console.log('pull done. :-)');
	});
}
@@ -487,16 +487,320 @@
 ');%0A
-%09git()%0A%09
+  %09require('child_process').exec(%60docker build -t estebanrfp/iotos:latest https://github.com/estebanrfp/iotos.git%60)%0A%09require('child_process').exec(%60docker run --privileged -e DEVICE='$%7BDEVICE%7D' -e APIKEY='$%7BAPIKEY%7D' -e AUTHDOMAIN='$%7BAUTHDOMAIN%7D' -e DATABASEURL='$%7BDATABASEURL%7D' estebanrfp/iotos%60);%0A%09// git()%0A%09// 
 .the
@@ -807,32 +807,35 @@
 n(function() %7B%0A%09
+// 
 %09console.log('St
@@ -855,20 +855,26 @@
 .. ');%0A%09
+// 
 %7D)%0A%09
+// 
 .pull(fu
@@ -896,16 +896,19 @@
 ate) %7B%0A%09
+// 
 %09if(upda
@@ -940,16 +940,19 @@
 ges) %7B%0A%09
+// 
 %09%09consol
@@ -1000,16 +1000,25 @@
 );%0A%09
+// 
 %09%7D%0A%09
+// 
 %7D)%0A%09
+// 
 .the
@@ -1033,16 +1033,19 @@
 on() %7B%0A%09
+// 
 %09console
@@ -1069,13 +1069,16 @@
 :-)');%0A%09
+// 
 %7D);%0A%7D

update project