Udostępnij za pośrednictwem


Using io.js with Azure Web Apps & Azure Websites

Using io.js with Azure Web Apps & Azure Websites

By Felix Rieseberg, Partner Catalyst Team, with input from Domenic Denicola (Google, member of the ECMAScript/JavaScript technical committee).

 

This case study describes a solution that enables the use of io.js with Azure Web Apps (formerly known as Azure Websites).  Any developer interested in using the io.js fork of Node.js on Azure can learn how in this case study.  A more concise tutorial is available on Azure.com.

 

Customer Problem

The Node.js fork io.js gained significant attention and popularity, since many Node.js core contributors declared it a more agile, forward-thinking and community-driven implementation of JavaScript I/O.  Within days after the initial release, many popular leading companies announced that they were planning to switch to io.js for better performance.  As a result, cloud providers hurried to support  io.js with their Node.js infrastructure.  Several JavaScript, Node.js and startup community members contacted Microsoft, indicating interest in running io.js on Azure Websites.    Based on that input, we set to work ensuring that io.js runs well on Azure Web Apps.

 

 Overview of the Solution

Using io.js on Azure Web apps is enabled through a deployment script that a) downloads the latest available stable version of io.js for Windows during deployment and b) configures the runtime to use the downloaded binary as the system-wide Node executable.

 

The resulting solution is available in three flavors:

  • One-click installation via Azure Deploy (also known as Azure Resource Manager) on GitHub
  • Inclusion of the deployment payload with any project
  • Manual inclusion of an io.js binary, paired with the runtime configuration.

 

Implementation

Kudu, a Microsoft-sponsored open source project, powers Azure Web App deployments. It allows for custom deployment scripts and can execute Bash, PowerShell and scripts in other languages during the deployment phase. IISNode, the IIS plugin that enables the use of Node.js, can be configured to use a specific binary as Node executable.

 

Using Kudu and IISNode together allows for an elegant implementation.  A script describing the deployment of the project creates a ‘bin’ folder outside wwwroot and downloads the latest available stable version of io.js. While the script also handles other required deployment tasks, it’s merely 150 lines long. In detail, it starts by accepting the deployment command, copying the new deployment payload to the respective wwwroot folder. During this phase, the script also ensures that Node and npm are installed and accessible. Once deployed, the script moves on to download iojs (see below). Once that is done, Azure Website’s default Node installation routine is executed – meaning that npm modules are downloaded and the environment is configured for IISNode.

 

 :: 2. Dowloading io.js
 if not exist "D:\home\site\bin" mkdir D:\home\site\bin
 if not exist "D:\home\site\bin\iojs" mkdir D:\home\site\bin\iojs
 call :ExecuteCmd curl -L -o D:\home\site\bin\iojs\iojs.exe https://iojs.org/dist/latest/win-x64/iojs.exe
 call :ExecuteCmd curl -L -o D:\home\site\bin\iojs\iojs.lib https://iojs.org/dist/latest/win-x64/iojs.lib

 

Configration of IISNode itself is simple: A file named iisnode.yml in the wwwroot of a website is parsed by IISNode, allowing a text-based configuration of environment variables. One of those variables is ‘nodeProcessCommandLine’, allowing the specification of a binary to be used for Node calls.

 

 nodeProcessCommandLine: "D:\home\site\wwwroot\bin\iojs\iojs.exe"

 

io.js is npm-compatible, so no changes are required to enable package management.  To get this running in your Azure Website, see the instructions at https://azure.microsoft.com/en-us/documentation/articles/web-sites-nodejs-iojs/.

 

To run this code yourself, see the full tutorial on Azure.com or directly to GitHub, where clicking the ‘Deploy to Azure’ button automates the process.

 

Opportunities for Reuse

The code is available on GitHub and referenced as the primary solution for io.js on Azure Web Apps on Azure.com. It has been referenced in various blog posts and "cool technology on Azure" demos.

 

The quick support for io.js was received well by the community. Simon Bisson (ZDNet, Infoworld) wrote: “It’s good to see Microsoft simplifying the process of working with new open Web technologies on Azure. Scripts like this, while not supported directly, make it possible for developers to experiment with new technologies without affecting production systems. Sharing scripts through Github is an important development, as it gives developers the option of modifying and updating scripts – and for the io.js team to fork the script and adopt it as part of their distribution tools.

 

 

 

The code can be easily reused for different branches or forks of Node.js and is also the basis for Node 0.12 on Azure.

 

Felix Rieseberg is an Open Source Engineer in Microsoft's Partner Catalyst team where he spends his time coding on the cutting edge of technology, trying to improve developer's lives by releasing quality code on GitHub and touring the world presenting the lessons we've learned. Read his blog at https://www.felixrieseberg.com/, follow him on twitter @felixrieseberg, and check out his work on github at https://github.com/felixrieseberg.