Skip to content

canvasnetworks/canvas

Repository files navigation

==========
| Canvas |
==========

This is the entire Canvas repo, including application code and configuration, without being cleaned up and prepped for renewed use. It's definitely doable to get this back into a running state, but please treat the configuration management parts as documentation more than pieces of reusable automation.

As for the bits of DrawQuest in this repo: for a while we ran both sites out of the same repo (the DrawQuest backend requirements were happily similar to what we'd already built with Canvas); once that became a burden, we stopped forking in code and forked in git instead.

## The instructions below are also untouched. They won't help as-is but may be a helpful guide to piece things back together.

If you have any questions feel free to reach out to [email protected]

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

----------


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

OS X
----
# MANUALLY: Install XCode via thumb drive or App Store
xcode-select --install
java # type this, press enter, will prompt you to install Java
ruby -e "$(curl -fsSLk https://gist.github.com/raw/323731/install_homebrew.rb)"
brew install git ack redis nginx pil solr wget memcached # requires installed XCode
sudo ln -s /usr/local/lib/python2.7/site-packages/PIL* /Library/Python/2.7/site-packages/

# 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

# 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.


Everwhere
---------
# 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 [email protected]
# Ensure your new ssh public key (`ssh-keygen`) is uploaded to your GitHub account at this point.
git clone [email protected]:canvasnetworks/canvas.git
sudo ln -s "`pwd`/canvas" /var/canvas

# Add canvas bash commands
echo ". /var/canvas/.bashrc" >> ~/.bash_profile && source ~/.bash_profile
# Install python dependencies with pip
sudo easy_install pip
sudo /var/canvas/requirements/update_sandbox.sh

2. Setting up local data:
=========================
cd /var/canvas/website
python manage.py syncdb
redis-server redis.conf # migration needs redis
python manage.py migrate canvas
python manage.py migrate
runcanvas
python manage.py solr_import group && python manage.py solr_import comment
open http://savnac.com # and manually upload /var/canvas/website/static/img/600-600.png (allows upload from drawing)

3. Running Sass:
================
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:
====================
runcanvas


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

Logging:
========
In development mode, Django logs are written to /run/django_gunicorn.log.
You can use logs like this:
import logging
logging.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
python manage.py syncdb
python manage.py migrate
redis-cli FLUSHALL
rm -rf /var/canvas/deploy/etcpuppet/modules/solr/files/solr/*/data


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:
python manage.py 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:
python manage.py 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:
python manage.py generate_js_api

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