Skip to content

MichaelBechHansen/drawquest-web

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

=============
| DrawQuest |
=============

This repo contains the backend of the DrawQuest app, which we ran on AWS. The codebase evolved out of Canvas, our previous product, which is why you'll see mixed references to both Canvas and DrawQuest. Most of DrawQuest's own code is under `website/drawquest/`, which uses the rest of `website/` as a library that it extends. Luckily the two products had enough similarities (Canvas "threads" being analogous to DrawQuest's "galleries") to benefit from substantial code reuse.

The instructions below are preserved from when Canvas & DrawQuest were under active development, which means they'll be broken in various ways. The codebase is likely most useful for extracting bits and pieces, but with some considerable effort could be restored together with the DrawQuest iOS codebase.

If you've got questions about anything in this repo, please file a GitHub issue, or you can contact alex.ehlke@gmail.com

Note: Use of the registered "DRAWQUEST" trademark is not conferred by the LICENSE. You may not use "DrawQuest" in the name of any derivative works without prior written permission.

-------------


1. Prerequisites:
=================

OS X
----
# MANUALLY: Install XCode via thumb drive or App Store
# MANUALLY: Install
java # type this, press enter, will prompt you to install Java
# Skip the next single line if you already have brew installed.
ruby -e "$(curl -fsSL https://raw.github.com/mxcl/homebrew/go)"
brew update
brew tap samueljohn/python
brew install git ack redis nginx wget memcached python pillow libpng libjpeg # requires installed XCode
brew link python --overwrite

# Port 80/443 support
cd /tmp
wget https://s3.amazonaws.com/canvas-public-artifacts/canvas_forward_http.tgz
tar -xzf ./canvas_forward_http.tgz
sudo ./canvas_forward_http.app/Contents/MacOS/Injector
# MANUAL STEP (Window may pop up behind other windows if you're using spaces): Press "Inject" button


Front-end web developers on OS X
--------------------------------
(Feel free to skip this section if you don't plan on doing front-end web development.)

# PhantomJS
cd /tmp
wget https://s3.amazonaws.com/canvas-public-artifacts/qt-mac-opensource-4.7.4.dmg
# You can just install the DMG manually or run the following command.
hdiutil attach qt-mac-opensource-4.7.4.dmg && cd /Volumes/Qt\ 4.7.4/ && sudo installer -pkg Qt.mpkg -target / && cd -
mkdir -p ~/Packages && cd ~/Packages

# DO THIS IN ~/Packages
wget https://s3.amazonaws.com/canvas-public-artifacts/phantomjs-1.5.0-macosx-static.zip && unzip phantomjs-1.5.0-macosx-static.zip

# PySide
cd /tmp
wget https://s3.amazonaws.com/canvas-public-artifacts/pyside-1.1.0-qt47-py27apple.pkg
open pyside-1.1.0-qt47-py27apple.pkg
# Follow the installation wizard.


Everywhere
---------
# ENSURE you have an encrypted location to place your Canvas files (use FileVault for OSX, encrypted home/private in Ubuntu)
# http://viktorpetersson.com/2011/08/01/did-you-know-you-can-create-encrypted-partitions-in-os-x-lion/
cd $PATH_TO_YOUR_ENCRYPTED_LOCATION
git config --global user.name "Your Name"
git config --global user.email you@example.com
# Ensure your new ssh public key (`ssh-keygen`) is uploaded to your GitHub account at this point.
git clone git@github.com:canvasnetworks/canvas.git
sudo ln -s "`pwd`/canvas" /var/canvas

# Add canvas bash commands
# (Either use the following command, or source the canvas bashrc from inside your existing bashrc.)
echo ". /var/canvas/.bashrc" >> ~/.bash_profile && source ~/.bash_profile
# Install python dependencies with pip
# If you already have PIL installed (Python Imaging Library), please uninstall it first.
sudo easy_install pip
sudo /var/canvas/requirements/update_sandbox.sh

2. Setting up local data:
=========================
cd /var/canvas/website # or just `cdc` as a shortcut for this.
dqm syncdb # enter "yes" when prompted to create a local admin user, with a complex/long password
redis-server redis.2.6.conf # migration needs redis
dqm migrate canvas
dqm migrate

rundq # run this in its own tab

open http://dq.savnac.com/login # log in using the superuser account you created before.
dqm initialize_qotd # Run this and follow the instructions (you'll have to run it twice)

3. Running Sass:
================
(Front-end web developers only - feel free to skip this section otherwise.)

Sass is an extension of CSS3, adding nested rules, variables, mixins, selector inheritance, and more. It's translated to well-formatted, standard CSS using the command line tool or a web-framework plugin.

A subset of the stylesheets used on the site are generated by Sass. The rule is that if a CSS file looks minified or all its content is in one
line then it is controlled by sass. Hence, look for it under /static/scss and change it there. There is a conversion step that needs to run after
making changes. But you can run the Sass Daemon and it will watch the files for changes and convert them as needed.

To install Sass, you'll need to have Ruby, then run the sass alias:
sudo gem install --version 3.1.15 sass
csass


4. Running the site:
====================
rundq
open http://dq.savnac.com # this points to localhost


|epilogue|
==========

Logging:
========
In development mode, Django logs are written to /run/django_gunicorn.log.
You can use logs like this:
from canvas.util import logger
logger.debug("debug message").

You can also run a tail on the log file to see the log messages:
cdc
tail -f run/django_gunicorn.log


Reset local data:
=================
cd /var/canvas/website
rm db.sqlite
dqm syncdb
dqm migrate
redis-cli FLUSHALL


Data Migrations:
================
You need to migrate the database schema whenever you make changes to models that will affect the corresponding database tables.
We use a tool called South to make this easy. Here is how to use it:
1. First run the schema migration locally:
dqm schemamigration canvas --auto

This creates a South migration file in canvas/migrations/. It is a Python file. Open it and look through it to verify the changes make sense.

2. You should comment out code that uses the new changes until you've migrated the schema on production. To run the migrations in production, you'll have
to SSH into the Gateway[1]. The Gateway and other machines in production need to have your public key. Mike can do this for you.

a. SSH into the Gateway: There is a command for that! (defined in /var/canvas/.bashrc):
gw

If your username on your local machine is different from your @example.com username, then use this:
gw -l <@example.com username>

b. Once on the Gateway, you can SSH into Cron:
ssh `ip -rg cron`
(Note the backticks. It executed the enclosed command and it becomes the operand)

Now you're on Cron.

c. Execute the schema migration script on Cron:
dqm schemamigration canvas --auto

d. You can now push any code that uses the new schema.

[1] Gateway: It is a machine through which you can access other machines in the cluster. It is the only machine in the cluster that you can externally SSH into.

The Canvas JavaScript API
=========================
The JavaScript api wrapper in statis/js/canvas_api.js is auto generated from api.py. Whenever you add a new api or change the signature of an api
method, you must regenerate the JS wrapper:
dqm generate_js_api

Profiling
=========
sudo pip install RunSnakeRun
mkdir -p ~/.config
runsnake foo.pstats

About

Backend API and web presence of DrawQuest

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Python 70.3%
  • JavaScript 14.7%
  • HTML 8.7%
  • CSS 6.2%
  • CoffeeScript 0.1%
  • Shell 0.0%