<?xml version="1.0" encoding="utf-8"?>
<rss xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:pingback="http://madskills.com/public/xml/rss/module/pingback/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:dc="http://purl.org/dc/elements/1.1/" version="2.0">
  <channel>
    <title>Jay Harris is Cpt. LoadTest - Azure</title>
    <link>http://www.cptloadtest.com/</link>
    <description>a .net developers blog on improving user experience of humans and coders</description>
    <language>en-us</language>
    <copyright>Jason Harris</copyright>
    <lastBuildDate>Tue, 03 Dec 2013 05:34:25 GMT</lastBuildDate>
    <generator>newtelligence dasBlog 2.3.12105.0</generator>
    <managingEditor>jharris@harrisdesigns.com</managingEditor>
    <webMaster>jharris@harrisdesigns.com</webMaster>
    <item>
      <trackback:ping>http://www.cptloadtest.com/Trackback.aspx?guid=1a39fd38-1ee4-4c7d-85fd-4b10cb7ea54d</trackback:ping>
      <pingback:server>http://www.cptloadtest.com/pingback.aspx</pingback:server>
      <pingback:target>http://www.cptloadtest.com/PermaLink,guid,1a39fd38-1ee4-4c7d-85fd-4b10cb7ea54d.aspx</pingback:target>
      <dc:creator>Jay Harris</dc:creator>
      <wfw:comment>http://www.cptloadtest.com/CommentView,guid,1a39fd38-1ee4-4c7d-85fd-4b10cb7ea54d.aspx</wfw:comment>
      <wfw:commentRss>http://www.cptloadtest.com/SyndicationService.asmx/GetEntryCommentsRss?guid=1a39fd38-1ee4-4c7d-85fd-4b10cb7ea54d</wfw:commentRss>
      <slash:comments>4</slash:comments>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
Azure Websites are a fantastic method of hosting your own web site. At Arana Software,
we use them often, particularly as test environments for our client projects. We can
quickly spin up a free site that is constantly up-to-date with the latest code using
continuous deployment from the project’s Git repository. Clients are able to see progress
on our development efforts without us having to worry about synchronizing codebases
or managing infrastructure. Since Windows Azure is a Microsoft offering, it is a natural
for handling .NET projects, but JavaScript-based nodejs is also a natural fit and
a first-class citizen on the Azure ecosystem.
</p>
        <h3>Incorporating Grunt
</h3>
        <p>
          <a href="http://gruntjs.com/">Grunt</a> is a JavaScript-based task runner for your
development projects to help you with those repetitive, menial, and mundane tasks
that are necessary for production readiness. This could be running unit tests, compiling
code, image processing, bundling and minification, and more. For our production deployments,
we commonly use Grunt to compile LESS into CSS, CoffeeScript into JavaScript, and
Jade into HTML, taking the code we write and preparing it for browser consumption.
We also use Grunt to optimize these various files for speed through bundling and minification.
The output of this work is done at deployment rather than development, with only the
source code committed into Git and never its optimized output.
</p>
        <h3>Git Deploy and Kudu
</h3>
        <p>
Continuous deployment will automatically update your site with the latest source code
whenever modifications are made to the source repository. This will also work with
Mercurial. There is plenty of existing documentation on <a href="http://www.windowsazure.com/en-us/develop/nodejs/common-tasks/publishing-with-git/">setting
up Git Deploy in Azure</a>, so consider that a prerequisite for this article. However,
Git Deploy, alone, will only take the files as they are in source, and directly deploy
them to the site. If you need to run additional tasks, such as compiling your .NET
source or running Grunt, that is where Kudu comes in.
</p>
        <p>
Kudu is the engine that drives Git deployments in Windows Azure. Untouched, it will
simply synchronize files from Git to your /wwwroot, but it can be easily reconfigured
to execute a deployment command, such as a Windows Command file, a Shell Script, or
a nodejs script. This is enabled through a standardized file named ".deployment".
For Grunt deployment, we are going to execute a Shell Script that will perform npm,
Bower, and Grunt commands in an effort to make our code production-ready. For other
options on .deployment, check out the <a href="https://github.com/projectkudu/kudu/wiki">Kudu
project wiki</a>.
</p>
        <p>
Kudu is also available locally for testing, and to help build out your deployment
scripts. The engine is available as a part of the cross-platform Windows Azure Command
Line Tools, available through npm.
</p>
        <h4>Installing the Azure CLI
</h4>
        <pre class="plain:nocontrols" name="code">npm install azure-cli –-global</pre>
        <p>
We can also use the Azure CLI to generate default Kudu scripts for our nodejs project.
Though we will need to make a few modifications to make the scripts work with Grunt,
it will give us a good start.
</p>
        <pre class="plain:nocontrols" name="code">azure site deploymentscript –-node</pre>
        <p>
This command will generate both our &lt;code&gt;.deployment&lt;/code&gt; and the default
&lt;code&gt;deploy.sh&lt;/code&gt;.
</p>
        <h4>Our .deployment file
</h4>
        <pre class="plain" name="code">[config]
command = bash ./deploy.sh</pre>
        <h3>Customizing deploy.sh for Grunt Deployment
</h3>
        <p>
From <code>.deployment</code>, Kudu will automatically execute our <code>deploy.sh</code> script.
Kudu’s default <code>deploy.sh</code> for a nodejs project will establish the environment
for node and npm as well as some supporting environment variables. It will also include
a "# Deployment" section containing all of the deployment steps. By default,
this will copy your repository contents to your /wwwroot, and then execute <code>npm
install --production</code> against wwwroot, as if installing the application's operating
dependencies. However, under Grunt, we want to execute tasks prior to <code>/wwwroot</code> deployment,
such as executing our Grunt tasks to compile LESS into CSS and CoffeeScript into JavaScript.
By replacing the entire Deployment section with the code below, we instruct Kudu to
perform the following tasks:
</p>
        <ol>
          <li>
Get the latest changes from Git (or Hg). This is done automatically before running
deploy.sh. 
</li>
          <li>
Run <code>npm install</code>, installing all dependencies, including those necessary
for development. 
</li>
          <li>
Optionally run <code>bower install</code>, if bower.json exists. This will update
our client-side JavaScript libraries. 
</li>
          <li>
Optionally run <code>grunt</code>, if Gruntfile.js exists. Below, I have grunt configured
to run the Clean, Common, and Dist tasks, which are LinemanJS's default tasks for
constructing a production-ready build. You can update the script to run whichever
tasks you need, or modify your Gruntfile to set these as the default tasks. 
</li>
          <li>
Finally, sync the contents of the prepared <code>/dist</code> directory to <code>/wwwroot</code>.
It is important to note that this is a KuduSync (similar to RSync), and not just a
copy. We only need to update the files that changed, which includes removing any obsolete
files. 
</li>
        </ol>
        <h4>Our deploy.sh file's Deployment Section
</h4>
        <pre class="plain:firstline[98]" name="code"># Deployment
# ----------

echo Handling node.js grunt deployment.

# 1. Select node version
selectNodeVersion

# 2. Install npm packages
if [ -e "$DEPLOYMENT_SOURCE/package.json" ]; then
  eval $NPM_CMD install
  exitWithMessageOnError "npm failed"
fi

# 3. Install bower packages
if [ -e "$DEPLOYMENT_SOURCE/bower.json" ]; then
  eval $NPM_CMD install bower
  exitWithMessageOnError "installing bower failed"
  ./node_modules/.bin/bower install
  exitWithMessageOnError "bower failed"
fi

# 4. Run grunt
if [ -e "$DEPLOYMENT_SOURCE/Gruntfile.js" ]; then
  eval $NPM_CMD install grunt-cli
  exitWithMessageOnError "installing grunt failed"
  ./node_modules/.bin/grunt --no-color clean common dist
  exitWithMessageOnError "grunt failed"
fi

# 5. KuduSync to Target
"$KUDU_SYNC_CMD" -v 500 -f "$DEPLOYMENT_SOURCE/dist" -t "$DEPLOYMENT_TARGET" -n "$NEXT_MANIFEST_PATH" -p "$PREVIOUS_MANIFEST_PATH" -i ".git;.hg;.deployment;deploy.sh"
exitWithMessageOnError "Kudu Sync to Target failed"</pre>
        <p>
These commands will execute bower and Grunt from local npm installations, rather than
the global space, as Windows Azure does not allow easy access to global installations.
Because bower and Grunt are manually installed based on the existence of bower.json
or Gruntfile.js, they also are not required to be referenced in your own package.json.
Finally, be sure to leave the –no-color flag enabled for Grunt execution, as the Azure
Deployment Logs will stumble when processing the ANSI color codes that are common
on Grunt output.
</p>
        <p>
Assuming that Git Deployment has already been configured, committing these files in
to Git will complete the process. Because the latest changes from Git are pulled before
executing the deployment steps, these two new files (<code>.deployment</code> and <code>deploy.sh</code>)
will be available when Kudu is ready for them.
</p>
        <h3>Troubleshooting
</h3>
        <h4>Long Directory Paths and the 260-Character Path Limit
</h4>
        <p>
Though Azure does a fantastic job of hosting nodejs projects, at the end of the day
Azure is still hosted on the Windows platform, and brings with it Windows limitations.
One of the issues that you will quickly run into under node is the <a href="http://msdn.microsoft.com/en-us/library/aa365247%28VS.85%29.aspx#maxpath">260-Character
Path Limitation</a>. Under nodejs, the dependency tree for a node modules can get
rather deep. And because each dependency module loads up its own dependency modules
under its child folder structure, the folder structure can get rather deep, too. For
example, Lineman requires Testem, which requires Winston, which requires Request;
in the end, the directory tree can lead to ~/node_modules/lineman/node_modules/testem/node_modules/winston/node_modules/request/node_modules/form-data/node_modules/combined-stream/node_modules/delayed-stream,
which combined with the root path structure, can far exceed the 260 limit.
</p>
        <p>
          <i>The Workaround</i>
        </p>
        <p>
To reduce this nesting, make some of these dependencies into first-level dependencies.
With the nodejs dependency model, if a module has already been brought in at a higher
level, it is not repeated in the chain. Thus, if Request is made as a direct dependency
and listed in your project's project.json, it will no longer be nested under Winston,
splitting this single dependency branch in two:
</p>
        <ol>
          <li>
~/node_modules/lineman/node_modules/testem/node_modules/winston 
</li>
          <li>
~/node_modules/request/node_modules/form-data/node_modules/combined-stream/node_modules/delayed-stream 
</li>
        </ol>
        <p>
This is not ideal, but it will solve is a workaround for the Windows file structure
limitations. The element that you must be careful of is with dependency versioning,
as you will need to make sure your <code>package.json</code> references the appropriate
version of your pseudo-dependency; in this case, make sure your <code>package.json</code> references
the same version of Request as is referenced by Winston.
</p>
        <p>
To help find those deep dependencies, use <code>npm list</code>. It will show you
the full graph on the command line, supplying a handy visual indicator.
</p>
        <h4>__dirname vs Process.cwd()
</h4>
        <p>
In the node ecosystem, <code>Process.cwd()</code> is the current working directory
for the node process. There is also a common variable named <code>__dirname</code> that
is created by node; its value is the directory that contained your node script. If
you executed node against a script in the current working directory, then these values
should be the same. Except when they aren't, like in Windows Azure.
</p>
        <p>
In Windows Azure, everything is executed on the system drive, C:. Node and npm live
here, and it appears as though your deployment space does as well. However, this deployment
space is really a mapped directory, coming in from a network share where your files
are persisted. In Azure's node ecosystem, this means that your <code>Process.cwd()</code> is
the C-rooted path, while <code>__dirname</code> is the \\10.whatever-rooted UNC path
to your persisted files. Some Grunt-based tools and plugins (including Lineman) will
fail because that it will reference <code>__dirname</code> files while Grunt's core
is attempting to run tasks with the scope of <code>Process.cwd()</code>; Grunt recognizes
that it's trying to take action on \\10.whatever-rooted files in a C-rooted scope,
and fails because the files are not in a child directory.
</p>
        <p>
          <i>The Workaround</i>
        </p>
        <p>
If you are encountering this issue, reconfigure Grunt to work in the \\10.whatever-rooted
scope. You can do this by setting it's base path to <code>__dirname</code>, overriding
the default <code>Process.cwd()</code>. Within your Gruntfile.js, set the base path
immediately within your module export:
</p>
        <pre class="jscript" name="code">module.exports = function (grunt) {
  grunt.file.setBase(__dirname);
  // Code omitted
}</pre>
        <h4>Unable to find environment variable LINEMAN_MAIN
</h4>
        <p>
If like me, you are using Lineman to build your applications, you will encounter this
issue. Lineman manages Grunt and its configuration, so it prefers that all Grunt tasks
are executed via the Lineman CLI rather than directly executed via the Grunt CLI.
Lineman's Gruntfile.js includes a reference to an environment variable LINEMAN_MAIN,
set by the Lineman CLI, so that Grunt will run under the context of the proper Lineman
installation, which is what causes the failure if Grunt is executed directly.
</p>
        <p>
          <i>The Fix (Because this isn't a hack)</i>
        </p>
        <p>
Your development cycle has been configured to use lineman, so your deployment cycle
should use it, too! Update your <code>deploy.sh</code> Grunt execution to run Lineman
instead of Grunt. Also, since Lineman is referenced in your package.json, we don't
need to install it; it is already there.
</p>
        <p>
Option 1: deploy.sh
</p>
        <pre class="plain:firstline[120]" name="code"># 4. Run grunt
if [ -e "$DEPLOYMENT_SOURCE/Gruntfile.js" ]; then
  ./node_modules/.bin/lineman --no-color grunt clean common dist
  exitWithMessageOnError "lineman failed"
fi</pre>
        <p>
Recommendation: Since Lineman is wrapping Grunt for all of its tasks, consider simplifying <code>lineman
grunt clean common dist</code> into <code>lineman clean build</code>. You will still
need the <code>--no-color</code> flag, so that Grunt will not use ANSI color codes. 
</p>
        <p>
          <i>The Alternate Workaround</i>
        </p>
        <p>
If you don't want to change your <code>deploy.sh</code>—perhaps because you want to
maintain the generic file to handle all things Grunt—then as an alternative you can
update your <code>Gruntfile.js</code> to specify a default value for the missing <code>LINEMAN_MAIN</code> environment
variable. This environment variable is just a string value passed in to node's require
function, so that the right Lineman module can be loaded. Since Lineman is already
included in your <code>package.json</code>, it will already be available in the local <code>/node_modules</code> folder
because of the earlier <code>npm install</code> (deploy.sh, Step #2), and we can pass
'lineman' into <code>require( )</code> to have Grunt load the local Lineman installation.
Lineman will then supply its configuration into Grunt, and the system will proceed
as if you executed Lineman directly.
</p>
        <p>
Option 2: Gruntfile.js
</p>
        <pre class="jscript" name="code">module.exports = function(grunt) {
  grunt.file.setBase(__dirname);
  if (process.env['LINEMAN_MAIN'] === null || process.env['LINEMAN_MAIN'] === undefined) {
    process.env['LINEMAN_MAIN'] = 'lineman';
  }
  require(process.env['LINEMAN_MAIN']).config.grunt.run(grunt);
};</pre>
        <h3>Credits
</h3>
        <p>
Thank you to <a href="http://www.twitter.com/davidebbo">@davidebbo</a>, <a href="http://www.twitter.com/guayan">@guayan</a>, <a href="http://www.twitter.com/amitapl">@amitapl</a>,
and <a href="http://www.twitter.com/dburton">@dburton</a> for helping troubleshoot
Kudu and Grunt Deploy, making this all possible.
</p>
        <h3>Changelog
</h3>
        <p>
2013-12-03: Updated LINEMAN_MAIN Troubleshooting to improve resolution. Rather than
editing deploy.sh to set the environment variable, edit the file to execute Lineman.
This is the proper (and more elegant) solution. [Credit: <a href="http://www.twitter.com/searls">@searls</a>]
</p>
        <div id="scid:0767317B-992E-4b12-91E0-4F059A8CECA8:9b0ba700-7d7e-41fe-8c1b-8c35f6d0d010" class="wlWriterEditableSmartContent" style="float: none; padding-bottom: 0px; padding-top: 0px; padding-left: 0px; margin: 0px; display: inline; padding-right: 0px">Technorati
Tags: <a href="http://technorati.com/tags/Grunt" rel="tag">Grunt</a>,<a href="http://technorati.com/tags/Lineman" rel="tag">Lineman</a>,<a href="http://technorati.com/tags/Node" rel="tag">Node</a>,<a href="http://technorati.com/tags/Azure" rel="tag">Azure</a>,<a href="http://technorati.com/tags/Git" rel="tag">Git</a></div>
        <img width="0" height="0" src="http://www.cptloadtest.com/aggbug.ashx?id=1a39fd38-1ee4-4c7d-85fd-4b10cb7ea54d" />
      </body>
      <title>Git and Grunt Deploy to Windows Azure</title>
      <guid isPermaLink="false">http://www.cptloadtest.com/PermaLink,guid,1a39fd38-1ee4-4c7d-85fd-4b10cb7ea54d.aspx</guid>
      <link>http://www.cptloadtest.com/2013/12/03/Git-And-Grunt-Deploy-To-Windows-Azure.aspx</link>
      <pubDate>Tue, 03 Dec 2013 05:34:25 GMT</pubDate>
      <description>&lt;p&gt;
Azure Websites are a fantastic method of hosting your own web site. At Arana Software,
we use them often, particularly as test environments for our client projects. We can
quickly spin up a free site that is constantly up-to-date with the latest code using
continuous deployment from the project’s Git repository. Clients are able to see progress
on our development efforts without us having to worry about synchronizing codebases
or managing infrastructure. Since Windows Azure is a Microsoft offering, it is a natural
for handling .NET projects, but JavaScript-based nodejs is also a natural fit and
a first-class citizen on the Azure ecosystem.
&lt;/p&gt;
&lt;h3&gt;Incorporating Grunt
&lt;/h3&gt;
&lt;p&gt;
&lt;a href="http://gruntjs.com/"&gt;Grunt&lt;/a&gt; is a JavaScript-based task runner for your
development projects to help you with those repetitive, menial, and mundane tasks
that are necessary for production readiness. This could be running unit tests, compiling
code, image processing, bundling and minification, and more. For our production deployments,
we commonly use Grunt to compile LESS into CSS, CoffeeScript into JavaScript, and
Jade into HTML, taking the code we write and preparing it for browser consumption.
We also use Grunt to optimize these various files for speed through bundling and minification.
The output of this work is done at deployment rather than development, with only the
source code committed into Git and never its optimized output.
&lt;/p&gt;
&lt;h3&gt;Git Deploy and Kudu
&lt;/h3&gt;
&lt;p&gt;
Continuous deployment will automatically update your site with the latest source code
whenever modifications are made to the source repository. This will also work with
Mercurial. There is plenty of existing documentation on &lt;a href="http://www.windowsazure.com/en-us/develop/nodejs/common-tasks/publishing-with-git/"&gt;setting
up Git Deploy in Azure&lt;/a&gt;, so consider that a prerequisite for this article. However,
Git Deploy, alone, will only take the files as they are in source, and directly deploy
them to the site. If you need to run additional tasks, such as compiling your .NET
source or running Grunt, that is where Kudu comes in.
&lt;/p&gt;
&lt;p&gt;
Kudu is the engine that drives Git deployments in Windows Azure. Untouched, it will
simply synchronize files from Git to your /wwwroot, but it can be easily reconfigured
to execute a deployment command, such as a Windows Command file, a Shell Script, or
a nodejs script. This is enabled through a standardized file named &amp;quot;.deployment&amp;quot;.
For Grunt deployment, we are going to execute a Shell Script that will perform npm,
Bower, and Grunt commands in an effort to make our code production-ready. For other
options on .deployment, check out the &lt;a href="https://github.com/projectkudu/kudu/wiki"&gt;Kudu
project wiki&lt;/a&gt;.
&lt;/p&gt;
&lt;p&gt;
Kudu is also available locally for testing, and to help build out your deployment
scripts. The engine is available as a part of the cross-platform Windows Azure Command
Line Tools, available through npm.
&lt;/p&gt;
&lt;h4&gt;Installing the Azure CLI
&lt;/h4&gt;
&lt;pre class="plain:nocontrols" name="code"&gt;npm install azure-cli –-global&lt;/pre&gt;
&lt;p&gt;
We can also use the Azure CLI to generate default Kudu scripts for our nodejs project.
Though we will need to make a few modifications to make the scripts work with Grunt,
it will give us a good start.
&lt;/p&gt;
&lt;pre class="plain:nocontrols" name="code"&gt;azure site deploymentscript –-node&lt;/pre&gt;
&lt;p&gt;
This command will generate both our &amp;lt;code&amp;gt;.deployment&amp;lt;/code&amp;gt; and the default
&amp;lt;code&amp;gt;deploy.sh&amp;lt;/code&amp;gt;.
&lt;/p&gt;
&lt;h4&gt;Our .deployment file
&lt;/h4&gt;
&lt;pre class="plain" name="code"&gt;[config]
command = bash ./deploy.sh&lt;/pre&gt;
&lt;h3&gt;Customizing deploy.sh for Grunt Deployment
&lt;/h3&gt;
&lt;p&gt;
From &lt;code&gt;.deployment&lt;/code&gt;, Kudu will automatically execute our &lt;code&gt;deploy.sh&lt;/code&gt; script.
Kudu’s default &lt;code&gt;deploy.sh&lt;/code&gt; for a nodejs project will establish the environment
for node and npm as well as some supporting environment variables. It will also include
a &amp;quot;# Deployment&amp;quot; section containing all of the deployment steps. By default,
this will copy your repository contents to your /wwwroot, and then execute &lt;code&gt;npm
install --production&lt;/code&gt; against wwwroot, as if installing the application's operating
dependencies. However, under Grunt, we want to execute tasks prior to &lt;code&gt;/wwwroot&lt;/code&gt; deployment,
such as executing our Grunt tasks to compile LESS into CSS and CoffeeScript into JavaScript.
By replacing the entire Deployment section with the code below, we instruct Kudu to
perform the following tasks:
&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;
Get the latest changes from Git (or Hg). This is done automatically before running
deploy.sh. 
&lt;/li&gt;
&lt;li&gt;
Run &lt;code&gt;npm install&lt;/code&gt;, installing all dependencies, including those necessary
for development. 
&lt;/li&gt;
&lt;li&gt;
Optionally run &lt;code&gt;bower install&lt;/code&gt;, if bower.json exists. This will update
our client-side JavaScript libraries. 
&lt;/li&gt;
&lt;li&gt;
Optionally run &lt;code&gt;grunt&lt;/code&gt;, if Gruntfile.js exists. Below, I have grunt configured
to run the Clean, Common, and Dist tasks, which are LinemanJS's default tasks for
constructing a production-ready build. You can update the script to run whichever
tasks you need, or modify your Gruntfile to set these as the default tasks. 
&lt;/li&gt;
&lt;li&gt;
Finally, sync the contents of the prepared &lt;code&gt;/dist&lt;/code&gt; directory to &lt;code&gt;/wwwroot&lt;/code&gt;.
It is important to note that this is a KuduSync (similar to RSync), and not just a
copy. We only need to update the files that changed, which includes removing any obsolete
files. 
&lt;/li&gt;
&lt;/ol&gt;
&lt;h4&gt;Our deploy.sh file's Deployment Section
&lt;/h4&gt;
&lt;pre class="plain:firstline[98]" name="code"&gt;# Deployment
# ----------

echo Handling node.js grunt deployment.

# 1. Select node version
selectNodeVersion

# 2. Install npm packages
if [ -e &amp;quot;$DEPLOYMENT_SOURCE/package.json&amp;quot; ]; then
  eval $NPM_CMD install
  exitWithMessageOnError &amp;quot;npm failed&amp;quot;
fi

# 3. Install bower packages
if [ -e &amp;quot;$DEPLOYMENT_SOURCE/bower.json&amp;quot; ]; then
  eval $NPM_CMD install bower
  exitWithMessageOnError &amp;quot;installing bower failed&amp;quot;
  ./node_modules/.bin/bower install
  exitWithMessageOnError &amp;quot;bower failed&amp;quot;
fi

# 4. Run grunt
if [ -e &amp;quot;$DEPLOYMENT_SOURCE/Gruntfile.js&amp;quot; ]; then
  eval $NPM_CMD install grunt-cli
  exitWithMessageOnError &amp;quot;installing grunt failed&amp;quot;
  ./node_modules/.bin/grunt --no-color clean common dist
  exitWithMessageOnError &amp;quot;grunt failed&amp;quot;
fi

# 5. KuduSync to Target
&amp;quot;$KUDU_SYNC_CMD&amp;quot; -v 500 -f &amp;quot;$DEPLOYMENT_SOURCE/dist&amp;quot; -t &amp;quot;$DEPLOYMENT_TARGET&amp;quot; -n &amp;quot;$NEXT_MANIFEST_PATH&amp;quot; -p &amp;quot;$PREVIOUS_MANIFEST_PATH&amp;quot; -i &amp;quot;.git;.hg;.deployment;deploy.sh&amp;quot;
exitWithMessageOnError &amp;quot;Kudu Sync to Target failed&amp;quot;&lt;/pre&gt;
&lt;p&gt;
These commands will execute bower and Grunt from local npm installations, rather than
the global space, as Windows Azure does not allow easy access to global installations.
Because bower and Grunt are manually installed based on the existence of bower.json
or Gruntfile.js, they also are not required to be referenced in your own package.json.
Finally, be sure to leave the –no-color flag enabled for Grunt execution, as the Azure
Deployment Logs will stumble when processing the ANSI color codes that are common
on Grunt output.
&lt;/p&gt;
&lt;p&gt;
Assuming that Git Deployment has already been configured, committing these files in
to Git will complete the process. Because the latest changes from Git are pulled before
executing the deployment steps, these two new files (&lt;code&gt;.deployment&lt;/code&gt; and &lt;code&gt;deploy.sh&lt;/code&gt;)
will be available when Kudu is ready for them.
&lt;/p&gt;
&lt;h3&gt;Troubleshooting
&lt;/h3&gt;
&lt;h4&gt;Long Directory Paths and the 260-Character Path Limit
&lt;/h4&gt;
&lt;p&gt;
Though Azure does a fantastic job of hosting nodejs projects, at the end of the day
Azure is still hosted on the Windows platform, and brings with it Windows limitations.
One of the issues that you will quickly run into under node is the &lt;a href="http://msdn.microsoft.com/en-us/library/aa365247%28VS.85%29.aspx#maxpath"&gt;260-Character
Path Limitation&lt;/a&gt;. Under nodejs, the dependency tree for a node modules can get
rather deep. And because each dependency module loads up its own dependency modules
under its child folder structure, the folder structure can get rather deep, too. For
example, Lineman requires Testem, which requires Winston, which requires Request;
in the end, the directory tree can lead to ~/node_modules/lineman/node_modules/testem/node_modules/winston/node_modules/request/node_modules/form-data/node_modules/combined-stream/node_modules/delayed-stream,
which combined with the root path structure, can far exceed the 260 limit.
&lt;/p&gt;
&lt;p&gt;
&lt;i&gt;The Workaround&lt;/i&gt;
&lt;/p&gt;
&lt;p&gt;
To reduce this nesting, make some of these dependencies into first-level dependencies.
With the nodejs dependency model, if a module has already been brought in at a higher
level, it is not repeated in the chain. Thus, if Request is made as a direct dependency
and listed in your project's project.json, it will no longer be nested under Winston,
splitting this single dependency branch in two:
&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;
~/node_modules/lineman/node_modules/testem/node_modules/winston 
&lt;/li&gt;
&lt;li&gt;
~/node_modules/request/node_modules/form-data/node_modules/combined-stream/node_modules/delayed-stream 
&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;
This is not ideal, but it will solve is a workaround for the Windows file structure
limitations. The element that you must be careful of is with dependency versioning,
as you will need to make sure your &lt;code&gt;package.json&lt;/code&gt; references the appropriate
version of your pseudo-dependency; in this case, make sure your &lt;code&gt;package.json&lt;/code&gt; references
the same version of Request as is referenced by Winston.
&lt;/p&gt;
&lt;p&gt;
To help find those deep dependencies, use &lt;code&gt;npm list&lt;/code&gt;. It will show you
the full graph on the command line, supplying a handy visual indicator.
&lt;/p&gt;
&lt;h4&gt;__dirname vs Process.cwd()
&lt;/h4&gt;
&lt;p&gt;
In the node ecosystem, &lt;code&gt;Process.cwd()&lt;/code&gt; is the current working directory
for the node process. There is also a common variable named &lt;code&gt;__dirname&lt;/code&gt; that
is created by node; its value is the directory that contained your node script. If
you executed node against a script in the current working directory, then these values
should be the same. Except when they aren't, like in Windows Azure.
&lt;/p&gt;
&lt;p&gt;
In Windows Azure, everything is executed on the system drive, C:. Node and npm live
here, and it appears as though your deployment space does as well. However, this deployment
space is really a mapped directory, coming in from a network share where your files
are persisted. In Azure's node ecosystem, this means that your &lt;code&gt;Process.cwd()&lt;/code&gt; is
the C-rooted path, while &lt;code&gt;__dirname&lt;/code&gt; is the \\10.whatever-rooted UNC path
to your persisted files. Some Grunt-based tools and plugins (including Lineman) will
fail because that it will reference &lt;code&gt;__dirname&lt;/code&gt; files while Grunt's core
is attempting to run tasks with the scope of &lt;code&gt;Process.cwd()&lt;/code&gt;; Grunt recognizes
that it's trying to take action on \\10.whatever-rooted files in a C-rooted scope,
and fails because the files are not in a child directory.
&lt;/p&gt;
&lt;p&gt;
&lt;i&gt;The Workaround&lt;/i&gt;
&lt;/p&gt;
&lt;p&gt;
If you are encountering this issue, reconfigure Grunt to work in the \\10.whatever-rooted
scope. You can do this by setting it's base path to &lt;code&gt;__dirname&lt;/code&gt;, overriding
the default &lt;code&gt;Process.cwd()&lt;/code&gt;. Within your Gruntfile.js, set the base path
immediately within your module export:
&lt;/p&gt;
&lt;pre class="jscript" name="code"&gt;module.exports = function (grunt) {
  grunt.file.setBase(__dirname);
  // Code omitted
}&lt;/pre&gt;
&lt;h4&gt;Unable to find environment variable LINEMAN_MAIN
&lt;/h4&gt;
&lt;p&gt;
If like me, you are using Lineman to build your applications, you will encounter this
issue. Lineman manages Grunt and its configuration, so it prefers that all Grunt tasks
are executed via the Lineman CLI rather than directly executed via the Grunt CLI.
Lineman's Gruntfile.js includes a reference to an environment variable LINEMAN_MAIN,
set by the Lineman CLI, so that Grunt will run under the context of the proper Lineman
installation, which is what causes the failure if Grunt is executed directly.
&lt;/p&gt;
&lt;p&gt;
&lt;i&gt;The Fix (Because this isn't a hack)&lt;/i&gt;
&lt;/p&gt;
&lt;p&gt;
Your development cycle has been configured to use lineman, so your deployment cycle
should use it, too! Update your &lt;code&gt;deploy.sh&lt;/code&gt; Grunt execution to run Lineman
instead of Grunt. Also, since Lineman is referenced in your package.json, we don't
need to install it; it is already there.
&lt;/p&gt;
&lt;p&gt;
Option 1: deploy.sh
&lt;/p&gt;
&lt;pre class="plain:firstline[120]" name="code"&gt;# 4. Run grunt
if [ -e &amp;quot;$DEPLOYMENT_SOURCE/Gruntfile.js&amp;quot; ]; then
  ./node_modules/.bin/lineman --no-color grunt clean common dist
  exitWithMessageOnError &amp;quot;lineman failed&amp;quot;
fi&lt;/pre&gt;
&lt;p&gt;
Recommendation: Since Lineman is wrapping Grunt for all of its tasks, consider simplifying &lt;code&gt;lineman
grunt clean common dist&lt;/code&gt; into &lt;code&gt;lineman clean build&lt;/code&gt;. You will still
need the &lt;code&gt;--no-color&lt;/code&gt; flag, so that Grunt will not use ANSI color codes. 
&lt;/p&gt;
&lt;p&gt;
&lt;i&gt;The Alternate Workaround&lt;/i&gt;
&lt;/p&gt;
&lt;p&gt;
If you don't want to change your &lt;code&gt;deploy.sh&lt;/code&gt;—perhaps because you want to
maintain the generic file to handle all things Grunt—then as an alternative you can
update your &lt;code&gt;Gruntfile.js&lt;/code&gt; to specify a default value for the missing &lt;code&gt;LINEMAN_MAIN&lt;/code&gt; environment
variable. This environment variable is just a string value passed in to node's require
function, so that the right Lineman module can be loaded. Since Lineman is already
included in your &lt;code&gt;package.json&lt;/code&gt;, it will already be available in the local &lt;code&gt;/node_modules&lt;/code&gt; folder
because of the earlier &lt;code&gt;npm install&lt;/code&gt; (deploy.sh, Step #2), and we can pass
'lineman' into &lt;code&gt;require( )&lt;/code&gt; to have Grunt load the local Lineman installation.
Lineman will then supply its configuration into Grunt, and the system will proceed
as if you executed Lineman directly.
&lt;/p&gt;
&lt;p&gt;
Option 2: Gruntfile.js
&lt;/p&gt;
&lt;pre class="jscript" name="code"&gt;module.exports = function(grunt) {
  grunt.file.setBase(__dirname);
  if (process.env['LINEMAN_MAIN'] === null || process.env['LINEMAN_MAIN'] === undefined) {
    process.env['LINEMAN_MAIN'] = 'lineman';
  }
  require(process.env['LINEMAN_MAIN']).config.grunt.run(grunt);
};&lt;/pre&gt;
&lt;h3&gt;Credits
&lt;/h3&gt;
&lt;p&gt;
Thank you to &lt;a href="http://www.twitter.com/davidebbo"&gt;@davidebbo&lt;/a&gt;, &lt;a href="http://www.twitter.com/guayan"&gt;@guayan&lt;/a&gt;, &lt;a href="http://www.twitter.com/amitapl"&gt;@amitapl&lt;/a&gt;,
and &lt;a href="http://www.twitter.com/dburton"&gt;@dburton&lt;/a&gt; for helping troubleshoot
Kudu and Grunt Deploy, making this all possible.
&lt;/p&gt;
&lt;h3&gt;Changelog
&lt;/h3&gt;
&lt;p&gt;
2013-12-03: Updated LINEMAN_MAIN Troubleshooting to improve resolution. Rather than
editing deploy.sh to set the environment variable, edit the file to execute Lineman.
This is the proper (and more elegant) solution. [Credit: &lt;a href="http://www.twitter.com/searls"&gt;@searls&lt;/a&gt;]
&lt;/p&gt;
&lt;div id="scid:0767317B-992E-4b12-91E0-4F059A8CECA8:9b0ba700-7d7e-41fe-8c1b-8c35f6d0d010" class="wlWriterEditableSmartContent" style="float: none; padding-bottom: 0px; padding-top: 0px; padding-left: 0px; margin: 0px; display: inline; padding-right: 0px"&gt;Technorati
Tags: &lt;a href="http://technorati.com/tags/Grunt" rel="tag"&gt;Grunt&lt;/a&gt;,&lt;a href="http://technorati.com/tags/Lineman" rel="tag"&gt;Lineman&lt;/a&gt;,&lt;a href="http://technorati.com/tags/Node" rel="tag"&gt;Node&lt;/a&gt;,&lt;a href="http://technorati.com/tags/Azure" rel="tag"&gt;Azure&lt;/a&gt;,&lt;a href="http://technorati.com/tags/Git" rel="tag"&gt;Git&lt;/a&gt;
&lt;/div&gt;
&lt;img width="0" height="0" src="http://www.cptloadtest.com/aggbug.ashx?id=1a39fd38-1ee4-4c7d-85fd-4b10cb7ea54d" /&gt;</description>
      <comments>http://www.cptloadtest.com/CommentView,guid,1a39fd38-1ee4-4c7d-85fd-4b10cb7ea54d.aspx</comments>
      <category>Azure</category>
      <category>Continuous Integration</category>
      <category>JavaScript</category>
      <category>Programming</category>
      <category>Task Automation</category>
    </item>
  </channel>
</rss>