Permalink
Browse files

moved to cloud service project

  • Loading branch information...
1 parent 4e3fdbf commit c574fdec0f66409cd9a3bfc8f9ffae1e1525fb8b @JustinBeckwith committed Oct 11, 2012
@@ -0,0 +1,13 @@
+<?xml version="1.0"?>
+<ServiceConfiguration xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" serviceName="wazstagram" osFamily="2" osVersion="*" xmlns="http://schemas.microsoft.com/ServiceHosting/2008/10/ServiceConfiguration">
+ <Role name="frontend">
+ <ConfigurationSettings />
+ <Instances count="1" />
+ <Certificates />
+ </Role>
+ <Role name="backend">
+ <ConfigurationSettings />
+ <Instances count="1" />
+ <Certificates />
+ </Role>
+</ServiceConfiguration>
@@ -0,0 +1,13 @@
+<?xml version="1.0"?>
+<ServiceConfiguration xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" serviceName="wazstagram" osFamily="2" osVersion="*" xmlns="http://schemas.microsoft.com/ServiceHosting/2008/10/ServiceConfiguration">
+ <Role name="frontend">
+ <ConfigurationSettings />
+ <Instances count="1" />
+ <Certificates />
+ </Role>
+ <Role name="backend">
+ <ConfigurationSettings />
+ <Instances count="1" />
+ <Certificates />
+ </Role>
+</ServiceConfiguration>
View
@@ -0,0 +1,61 @@
+<?xml version="1.0"?>
+<ServiceDefinition xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" name="wazstagram" xmlns="http://schemas.microsoft.com/ServiceHosting/2008/10/ServiceDefinition">
+ <WorkerRole name="frontend">
+ <Startup>
+ <Task commandLine="setup_worker.cmd &gt; log.txt" executionContext="elevated">
+ <Environment>
+ <Variable name="EMULATED">
+ <RoleInstanceValue xpath="/RoleEnvironment/Deployment/@emulated" />
+ </Variable>
+ <Variable name="RUNTIMEID" value="NODE" />
+ <Variable name="RUNTIMEURL" value="http://nodertncu.blob.core.windows.net/node/0.6.20.exe" />
+ </Environment>
+ </Task>
+ </Startup>
+ <Endpoints>
+ <InputEndpoint name="HttpIn" protocol="tcp" port="80" />
+ </Endpoints>
+ <Runtime>
+ <Environment>
+ <Variable name="PORT">
+ <RoleInstanceValue xpath="/RoleEnvironment/CurrentInstance/Endpoints/Endpoint[@name='HttpIn']/@port" />
+ </Variable>
+ <Variable name="EMULATED">
+ <RoleInstanceValue xpath="/RoleEnvironment/Deployment/@emulated" />
+ </Variable>
+ </Environment>
+ <EntryPoint>
+ <ProgramEntryPoint commandLine="node.cmd .\server.js" setReadyOnProcessStart="true" />
+ </EntryPoint>
+ </Runtime>
+ </WorkerRole>
+ <WorkerRole name="backend">
+ <Startup>
+ <Task commandLine="setup_worker.cmd &gt; log.txt" executionContext="elevated">
+ <Environment>
+ <Variable name="EMULATED">
+ <RoleInstanceValue xpath="/RoleEnvironment/Deployment/@emulated" />
+ </Variable>
+ <Variable name="RUNTIMEID" value="NODE" />
+ <Variable name="RUNTIMEURL" value="http://nodertncu.blob.core.windows.net/node/0.6.20.exe" />
+ </Environment>
+ </Task>
+ </Startup>
+ <Endpoints>
+ <InputEndpoint name="HttpIn" protocol="tcp" port="8080" />
+ </Endpoints>
+ <Runtime>
+ <Environment>
+ <Variable name="PORT">
+ <RoleInstanceValue xpath="/RoleEnvironment/CurrentInstance/Endpoints/Endpoint[@name='HttpIn']/@port" />
+ </Variable>
+ <Variable name="EMULATED">
+ <RoleInstanceValue xpath="/RoleEnvironment/Deployment/@emulated" />
+ </Variable>
+ </Environment>
+ <EntryPoint>
+ <ProgramEntryPoint commandLine="node.cmd .\server.js" setReadyOnProcessStart="true" />
+ </EntryPoint>
+ </Runtime>
+ </WorkerRole>
+</ServiceDefinition>
View
@@ -1,4 +0,0 @@
-node_modules
-keys.json
-iisnode
-instagram-subscriptions.json
View
@@ -0,0 +1,79 @@
+$runtimeUrl = $args[0]
+$overrideUrl = $args[1]
+$current = [string] (Get-Location -PSProvider FileSystem)
+$client = New-Object System.Net.WebClient
+
+function downloadWithRetry {
+ param([string]$url, [string]$dest, [int]$retry)
+ Write-Host
+ Write-Host "Attempt: $retry"
+ Write-Host
+ trap {
+ Write-Host $_.Exception.ToString()
+ if ($retry -lt 5) {
+ $retry=$retry+1
+ Write-Host
+ Write-Host "Waiting 5 seconds and retrying"
+ Write-Host
+ Start-Sleep -s 5
+ downloadWithRetry $url $dest $retry $client
+ }
+ else {
+ Write-Host "Download failed"
+ throw "Max number of retries downloading [5] exceeded"
+ }
+ }
+ $client.downloadfile($url, $dest)
+}
+
+function download($url, $dest) {
+ Write-Host "Downloading $url"
+ downloadWithRetry $url $dest 1
+}
+
+function copyOnVerify($file, $output) {
+ Write-Host "Verifying $file"
+ $verify = Get-AuthenticodeSignature $file
+ Out-Host -InputObject $verify
+ if ($verify.Status -ne "Valid") {
+ throw "Invalid signature for runtime package $file"
+ }
+ else {
+ mv $file $output
+ }
+}
+
+if ($overrideUrl) {
+ Write-Host "Using override url: $overrideUrl"
+ $url = $overrideUrl
+}
+else {
+ $url = $runtimeUrl
+}
+
+foreach($singleUrl in $url -split ";")
+{
+ $suffix = Get-Random
+ $downloaddir = $current + "\sandbox" + $suffix
+ mkdir $downloaddir
+ $dest = $downloaddir + "\sandbox.exe"
+ download $singleUrl $dest
+ $final = $downloaddir + "\runtime.exe"
+ copyOnVerify $dest $final
+ if (Test-Path -LiteralPath $final)
+ {
+ cd $downloaddir
+ Start-Process -FilePath $final -ArgumentList -y -Wait
+ $cmd = $downloaddir + "\setup.cmd"
+ Start-Process -FilePath $cmd -Wait
+ }
+ else
+ {
+ throw "Unable to verify package"
+ }
+ cd $current
+ if (Test-Path -LiteralPath $downloaddir)
+ {
+ Remove-Item -LiteralPath $downloaddir -Force -Recurse
+ }
+}
View
@@ -0,0 +1 @@
+node.exe %1 %2 %3
View
@@ -1,15 +1 @@
-{
- "name": "wazstagram",
- "version": "0.0.1",
- "private": true,
- "scripts": {
- "start": "node server"
- },
- "dependencies": {
- "express": "3.0.0rc4",
- "jade": "*",
- "nconf": "~0.6.4",
- "request": "~2.11.4",
- "azure": "~0.6.4"
- }
-}
+{"name":"wazstagram","version":"0.0.1","private":true,"scripts":{"start":"node server"},"dependencies":{"express":"3.0.0rc4","jade":"*","nconf":"~0.6.4","request":"~2.11.4","azure":"~0.6.4"},"engines":{"node":"0.6.20"}}
View
@@ -35,31 +35,43 @@ module.exports = function (app, nconf, serviceBusService) {
console.log(url);
request(url, function (e, r, b) {
- var data = JSON.parse(b);
- if (data.meta.code == 200) {
+ if (e && e != '') {
+ console.log("ERROR:getMedia::" + e);
+ console.log("ERROR:getMedia::" + JSON.stringify(e));
+ } else {
+ var data = null;
+ try {
+ data = JSON.parse(b);
+ } catch (e) {
+ // if the parse fails, let's find out why...
+ console.log("ERROR:getMedia::\n" + b);
+ }
- if (data.data && data.data.length > 0) {
- var lastId = data.data[0].id;
- console.log('lastId for ' + req.params.city + ' is ' + lastId);
- minIds[req.params.city] = lastId;
+ if (data.meta.code == 200) {
- var pic = {
- city: req.params.city,
- pic: b
- }
- var message = {
- body: JSON.stringify(pic)
- };
- serviceBusService.sendTopicMessage('wazages', message, function (error) {
- if (error) {
- console.log('error sending message to topic! \n' + JSON.stringify(error));
- } else {
- console.log('message sent!');
+ if (data.data && data.data.length > 0) {
+ var lastId = data.data[0].id;
+ console.log('lastId for ' + req.params.city + ' is ' + lastId);
+ minIds[req.params.city] = lastId;
+
+ var pic = {
+ city: req.params.city,
+ pic: b
}
- })
+ var message = {
+ body: JSON.stringify(pic)
+ };
+ serviceBusService.sendTopicMessage('wazages', message, function (error) {
+ if (error) {
+ console.log('error sending message to topic! \n' + JSON.stringify(error));
+ } else {
+ console.log('message sent!');
+ }
+ })
+ }
+ } else {
+ console.log("ERROR::getMedia:: " + data.meta.error_message);
}
- } else {
- console.log("ERROR::getMedia:: " + data.meta.error_message);
}
});
})
View
@@ -0,0 +1,23 @@
+@echo off
+
+echo Granting permissions for Network Service to the deployment directory...
+icacls . /grant "Users":(OI)(CI)F
+if %ERRORLEVEL% neq 0 goto error
+echo OK
+
+if "%EMULATED%"=="true" exit /b 0
+
+echo Configuring powershell permissions
+powershell -c "set-executionpolicy unrestricted"
+
+echo Downloading runtime components
+powershell .\download.ps1 '%RUNTIMEURL%' '%RUNTIMEURLOVERRIDE%'
+if %ERRORLEVEL% neq 0 goto error
+
+echo SUCCESS
+exit /b 0
+
+:error
+
+echo FAILED
+exit /b -1
View
@@ -0,0 +1 @@
+{"Slot":"","Location":"","Subscription":"","StorageAccountName":""}
View
@@ -1,4 +0,0 @@
-node_modules
-keys.json
-iisnode
-instagram-subscriptions.json
View
@@ -0,0 +1,79 @@
+$runtimeUrl = $args[0]
+$overrideUrl = $args[1]
+$current = [string] (Get-Location -PSProvider FileSystem)
+$client = New-Object System.Net.WebClient
+
+function downloadWithRetry {
+ param([string]$url, [string]$dest, [int]$retry)
+ Write-Host
+ Write-Host "Attempt: $retry"
+ Write-Host
+ trap {
+ Write-Host $_.Exception.ToString()
+ if ($retry -lt 5) {
+ $retry=$retry+1
+ Write-Host
+ Write-Host "Waiting 5 seconds and retrying"
+ Write-Host
+ Start-Sleep -s 5
+ downloadWithRetry $url $dest $retry $client
+ }
+ else {
+ Write-Host "Download failed"
+ throw "Max number of retries downloading [5] exceeded"
+ }
+ }
+ $client.downloadfile($url, $dest)
+}
+
+function download($url, $dest) {
+ Write-Host "Downloading $url"
+ downloadWithRetry $url $dest 1
+}
+
+function copyOnVerify($file, $output) {
+ Write-Host "Verifying $file"
+ $verify = Get-AuthenticodeSignature $file
+ Out-Host -InputObject $verify
+ if ($verify.Status -ne "Valid") {
+ throw "Invalid signature for runtime package $file"
+ }
+ else {
+ mv $file $output
+ }
+}
+
+if ($overrideUrl) {
+ Write-Host "Using override url: $overrideUrl"
+ $url = $overrideUrl
+}
+else {
+ $url = $runtimeUrl
+}
+
+foreach($singleUrl in $url -split ";")
+{
+ $suffix = Get-Random
+ $downloaddir = $current + "\sandbox" + $suffix
+ mkdir $downloaddir
+ $dest = $downloaddir + "\sandbox.exe"
+ download $singleUrl $dest
+ $final = $downloaddir + "\runtime.exe"
+ copyOnVerify $dest $final
+ if (Test-Path -LiteralPath $final)
+ {
+ cd $downloaddir
+ Start-Process -FilePath $final -ArgumentList -y -Wait
+ $cmd = $downloaddir + "\setup.cmd"
+ Start-Process -FilePath $cmd -Wait
+ }
+ else
+ {
+ throw "Unable to verify package"
+ }
+ cd $current
+ if (Test-Path -LiteralPath $downloaddir)
+ {
+ Remove-Item -LiteralPath $downloaddir -Force -Recurse
+ }
+}
View
@@ -0,0 +1 @@
+node.exe %1 %2 %3
View
@@ -1,17 +1 @@
-{
- "name": "wazstagram-frontend",
- "version": "0.0.1",
- "private": true,
- "scripts": {
- "start": "node server"
- },
- "dependencies": {
- "express": "3.0.0rc4",
- "jade": "*",
- "socket.io": "~0.9.10",
- "nconf": "~0.6.4",
- "azure": "~0.6.4",
- "ejs": "~0.8.3",
- "node-uuid": "~1.3.3"
- }
-}
+{"name":"wazstagram-frontend","version":"0.0.1","private":true,"scripts":{"start":"node server"},"dependencies":{"express":"3.0.0rc4","jade":"*","socket.io":"~0.9.10","nconf":"~0.6.4","azure":"~0.6.4","ejs":"~0.8.3","node-uuid":"~1.3.3","request":"~2.11.4"},"engines":{"node":"0.6.20"}}
Oops, something went wrong.

0 comments on commit c574fde

Please sign in to comment.