For those unfamiliar, Trastr is a project to crowdsource information about grocery prices. A friend (blendergeek) and I have been planning and building it on and off for about 6 months, and I believe it would be beneficial to publish our thought processes as we move forward.

This week, I worked on automating the deployment of our Flask app to a Debian VPS with Ansible. One of the main breakthroughs occurred when I started using Ansible’s “deploy_helper” module in concert with the “copy” module. Previously, we were blindly copying files to the web root of our project with every new deployment, and manually erasing vestigial files. Now, each new release is placed in a different, timestamped folder, and symlinked to a “current” folder that Apache serves from.

Here’s the part of our Ansible playbook that deals with deploying app files:

- name: Initialize deploy root and gather facts
  deploy_helper:
    path: ""
- name: Upload  files
  copy: src=trastr_entry/ dest=
- name: Add an unfinished file, to allow cleanup on successful finalize
  file:
    path: '/'
    state: touch
- name: Finalize the deploy, removing the unfinished file and switching the symlink
  deploy_helper:
    path: ""
    release: ''
    state: finalize

All that now remains between us and functional deployment on our staging server is the adjustment of a few Apache settings, and the configuration of the “tagprism.com” (TagPrism is the brand name we’re using for our instance of Trastr) DNS settings.

My intention is to publish at least one of these a week. We may also record a podcast as we traipse through a grocery store collecting price data, so stay tuned for that!