Skip to content

Instantly share code, notes, and snippets.

@rduplain
Created April 27, 2013 02:06
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rduplain/5471608 to your computer and use it in GitHub Desktop.
Save rduplain/5471608 to your computer and use it in GitHub Desktop.
Makefile for key interactions on a Flask project deployed on heroku.

Here's how I set make deploy to only deploy to Heroku when:

  1. pyflakes reports no issues in Python modules
  2. git index is clean (does not check untracked files)
  3. configuration STATIC_VERSION is bumped if static files changed

I have app.config['SEND_FILE_MAX_AGE_DEFAULT'] = 2592000 to aggressively cache files. For STATIC_VERSION, I have Flask serve static file from a version based URL:

app = Flask(__name__, static_url_path='/static/%s' % static_version)

This is for http://pug.io/, but these are patterns I use in a lot of my projects. I often have a database target to setup a local development sqlite database, but left that out in this Makefile.

#!/bin/bash
# Verify git does not have a dirty index, does not inspect untracked files.
if [ "$(git diff --shortstat $@ 2>/dev/null | tail -n1)" != "" ]; then
echo 'git status: dirty'
exit 1
fi
#!/bin/bash
# Verify project configuration STATIC_VERSION is bumped if static/ changed.
script_dir="$( cd -P "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
project_dir="$( dirname "$script_dir" )"
check=$script_dir/check-git-status
static=$project_dir/pugio/static
config=$project_dir/pugio/config.py
if ( ! $check heroku/master $static >/dev/null ) &&
( ! git diff heroku/master $config | grep '^\+.*STATIC_VERSION' ); then
echo 'Bump STATIC_VERSION before deploying.'
exit 1
fi
# Key project interactions, but not all dependencies are resolved by make.
help:
@heroku help
run:
python manage.py runserver
shell:
python manage.py shell
deploy: flakes check-git-status check-static
git push heroku master
logs:
heroku logs
tail:
heroku logs --tail; true
flakes:
@find . -name '*.py' | xargs pyflakes
check-git-status:
@bin/check-git-status
check-static:
@bin/check-static
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment