The Ember Cli is a great command line tool for managing the development of sophisticated web applications using the popular framework Ember.js. One of the many features is a fully automated build and asset compilation with a whole bunch of subtasks. We at Microsoft love both automation and Ember.js, so I wrote a npm module enabling Azure Websites to automatically compile and deploy your app.
'Ember build' on Azure Websites
If you just came here to figure out how to have Azure Websites run
ember build as soon as you push a new commit to GitHub, BitBucket or Visual Studio Online, simply run the following command in your app's root folder:
$ npm install ember-cli-azure-deploy --save-dev -g
$ azure-deploy init
How Does This Magic Work?
The engine running on Azure Websites, Kudu, allows for customized deployments, enabling us to run a custom Bash script. Running
azure-deploy init creates just such a script. In detail, here's what happens next: As soon as a new commit is made to your repo, Azure is notified and clones the whole repo to a temporary folder. There, it executes
deploy.sh, which checks for the existence of KuduSync and Node.
If the environment is setup okay, we check whether Ember-Cli, Bower and Ember-Cli-Azure-Deploy are installed. If not, we go ahead and install it - and since we're already installing things anyway, we're also pulling down all required Node modules and Bower packages.
Normally, we could just run
ember build at this point. Sadly, the build fails on Azure Websites due to errors with
stdin. In order subvert that issue, I use Node's
child_process module to execute a command with stdin disabled, which now executes successfully. Once we're done, the deploy script simply copies the the built
dist folder over to your website's final deployment destination. Your app is now live - and you didn't even lift a finger!