Automated Deployment with Rackspace Cloud Files

Over the last couple months I’ve been doing an entirely manual deployment process for each blog post. It isn’t a difficult process but it takes time and is prone to errors.

I’ve finally gone through and automated the deployment. I first attempted to use Deploy for this, but I couldn’t justify $10 per month to save me the small amount of time I was spending on deployments each month. Instead, I decided to create my own solution.

I already had tools for generating the HTML and preparing the files to be copied up to Rackspace. All that was left was automating the transfer from my computer up to Rackspace. I took a look through the OpenStack API for .NET and wrote a program which could run through all the files generated for my site and upload them to Rackspace.

Deployment Requirements

In the past, every time I created a new post, I would have to do go through the following steps:

  1. Regenerate the site.

  2. Determine which files had changed.

  3. Upload the changed files to Rackspace

The new process is much shorter:

  1. Run a batch file.

The Tools

Below is a list of the tools I use to generate and deploy the blog:

  1. GoStatic Site Generator - The program used to generate the site from markdown. You can substitute this tool for any static site generator, or even hand created HTML files.

  2. Static Site Squisher - Minifies the HTML, JS, and CSS on my site. I published this program on my blog earlier this month.

  3. Cloud Files Deploy - Copies the contents of the folder up to Rackspace Cloud Files. Details about this program will come in a future post.

  4. A batch file to link all this together.

Below is the batch file I use to deploy my blog after adding a new post.

@echo off
SET /P AREYOUSURE=This will deploy to the production blog. Are you sure? (Y/[N])?

:: Delete old files.
rmdir "blogrpcom/public" /q /s
echo Deleting old files

:: Regenerate the site for processing
"bin/gostatic-32-win.exe" -f "blogrpcom/site/config"

:: Minify the site
"bin/StaticSiteSquisher" "blogrpcom/public"

:: Deploy the files site for any attachments to posts and the blog site.
"bin/CloudFiles-Deploy.exe" FilesContainerName "filesrpcom" username api_key
"bin/CloudFiles-Deploy.exe" BlogContainerName "blogrpcom/public" username api_key

echo Deployment completed successfully
pause > nul

I added the prompt to verify I wanted to run the deployment, since it is sitting in a folder with a couple other batch files I use for testing the blog. I wanted to prevent any accidental deployments. The testing files don’t contain a verification to prevent me from accidentally deploying due to muscle memory.

This process will be optimized in the future by improvements to the Deploy tool to check the existing files and determine what has changed. For now it’s simply doing a brute-force upload and overwriting all the existing files. It does not delete any files on the server, so anything deleted from the local directory will not be removed from the server when the deployment is run.

Written on August 27th, 2014 by Dan Walker

Want to read more?

If you’ve enjoyed what you’ve seen so far, you might like some of my other posts. Visit the archive to see all of my past writings.

Blog Archive »

About the Author

Dan Walker is a programmer from Grand Rapids, MI. He works at Gordon Food Service.

More About Dan »

Get in touch