Ghost 0.5.x from Source to Azure Web Sites–Part 2

This is part 1 of 3 of a blog series where David Wesst takes you through getting Ghost 0.5.x working from source control on Azure Websites. Read part 1 here.

Last time we forked the Ghost Blog source code and found that the default Azure website deployment didn't work.

This time we, we customize the deployment.

Your Custom Deployment

First install the azure-cli from npm.

 npm install -g azure-cli
  

Add a deployment script template to your project by using:

 azure site deploymentscript –-node
  

You should have a *deploy.cmd* and *.deployment* file added to the directory.

Open up your deploy.cmd file and add the following the 3. Install npm packages section that ends around line 106.

     :: 4. (Custom) Run Grunt Commands
    IF EXIST "%DEPLOYMENT_TARGET%\Gruntfile.js" (
      pushd "%DEPLOYMENT_TARGET%"
      echo installing grunt-cli
      call :ExecuteCmd !NPM_CMD! install grunt-cli
      echo running grunt init
      call :ExecuteCmd ./node_modules/.bin/grunt --no-color init
      echo running grunt prod
      call :ExecuteCmd ./node_modules/.bin/grunt --no-color prod
      IF !ERRORLEVEL! NEQ 0 goto error
      popd
    )
  

This checks to makes sure you're using GruntJS by having a Gruntfile.js and then executes the grunt commands.

Each of the `echo` commands marks each step:

  1. Installs the grunt-cli (because it's a devDependency in the project and didn't get installed with the npm install earlier)
  2. Runs the grunt init as per the Ghost setup from source instructions.
  3. Runs the grunt prod command, as per the Ghost setup from source instructions.

Save it, commit it, and publish to your Github repo.

Back to Azure

And now we wait for the deployment to complete on the Windows Azure management site.

image

As you can see, I'm committing to a Github repository which triggers a deployment.

I noticed that it takes a bit longer to deploy now than just publishing the "pre-set" code, but that is to be expected. Plus, it's downloading all the dependencies and such from npm, so it takes a bit of time.

Et Voila! Deployment Successful and your blog is running from source.

Side Note
When I load the page for the first time, I sometimes get a 500 error. Just do a full refresh and it should work.

A Few Considerations

Before you upgrade and publish to the next version, make sure you backup your content on ghost by logging into your blog and going to https://<blognamehere>/ghost/debug after you've logged in.

Because you're doing more on the deployment, I noticed that my Data-In statistics were a bit higher than normal. Not bad by any stretch, but being that this is the cloud and we pay for what we use, just make sure you don't deploy every 10 seconds.

Next Step: Custom Themes

Technically, you have everything up and running now on Azure, so you're good to go. But don't you want to make your blog your own with a custom theme?

Next time, we tackle adding that to our deployment.

--

Thanks for playing. ~ DW

References