From: Bryan Date: Tue, 14 Jan 2014 23:35:38 +0000 (+0000) Subject: fixes and docs for VM to be more friendly for testing. X-Git-Tag: release-20150131~263 X-Git-Url: https://git.librecmc.org/?a=commitdiff_plain;h=594944c087b7cddc23323521a1ad716e842ca5d9;p=oweals%2Fkarmaworld.git fixes and docs for VM to be more friendly for testing. --- diff --git a/README.md b/README.md index 3f50bd2..8813deb 100644 --- a/README.md +++ b/README.md @@ -293,8 +293,12 @@ not generally be needed. Within the virtualenv: 1. Update the Python depenencies with `pip -i {project_root}/reqs/prod.txt` - * If you want debugging on a production-like system, run - `pip -i {project_root}/reqs/vmdev.txt` + * If you want debugging on a production-like system: + 1. run `pip -i {project_root}/reqs/vmdev.txt` + 1. change `{project_root}/manage.py` to point at `vmdev.py` + instead of `prod.py` + 1. ensure firefox is installed on the system (such as by + `sudo apt-get install firefox`) 1. Setup the database with `python {project_root}/manage.py syncdb --migrate` diff --git a/Vagrantfile b/Vagrantfile index e06c6d7..dbd67ed 100644 --- a/Vagrantfile +++ b/Vagrantfile @@ -54,7 +54,7 @@ Viewer.prototype['rescale'] = Viewer.prototype.rescale; Viewer.prototype['scroll_to'] = Viewer.prototype.scroll_to; PDF2HTMLEXHACK -echo "CREATE USER vagrant WITH CREATEROLE LOGIN; CREATE DATABASE karmaworld OWNER vagrant;" | su postgres -c "psql" +echo "CREATE USER vagrant WITH CREATEROLE CREATEDB LOGIN; CREATE DATABASE karmaworld OWNER vagrant;" | su postgres -c "psql" mkdir -m 775 -p /var/www chown -R :www-data /var/www diff --git a/karmaworld/settings/vmdev.py b/karmaworld/settings/vmdev.py new file mode 100644 index 0000000..b02e1f6 --- /dev/null +++ b/karmaworld/settings/vmdev.py @@ -0,0 +1,208 @@ +#!/usr/bin/env python +# -*- coding:utf8 -*- +# Copyright (C) 2012 FinalsClub Foundation +""" Production settings and globals. """ + + +from os import environ +from datetime import timedelta +from S3 import CallingFormat + +from common import * + + +from karmaworld.secret.static_s3 import DEFAULT_FILE_STORAGE +from karmaworld.secret.static_s3 import AWS_ACCESS_KEY_ID +from karmaworld.secret.static_s3 import AWS_SECRET_ACCESS_KEY +from karmaworld.secret.static_s3 import AWS_STORAGE_BUCKET_NAME +from karmaworld.secret.static_s3 import S3_URL +from karmaworld.secret.static_s3 import STATIC_URL + +from karmaworld.secret.db_settings import PROD_DB_NAME +from karmaworld.secret.db_settings import PROD_DB_USERNAME +from karmaworld.secret.db_settings import PROD_DB_PASSWORD + +try: + # Include email is settings are there + from karmaworld.secret.email import SMTP_HOST + from karmaworld.secret.email import SMTP_USERNAME + from karmaworld.secret.email import SMTP_PASSWORD + EMAIL = True +except: + EMAIL = False + +########## EMAIL CONFIGURATION +if EMAIL: + # See: https://docs.djangoproject.com/en/dev/ref/settings/#email-backend + EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend' + + # See: https://docs.djangoproject.com/en/dev/ref/settings/#email-host + EMAIL_HOST = environ.get('EMAIL_HOST', SMTP_HOST) + + # See: https://docs.djangoproject.com/en/dev/ref/settings/#email-host-password + EMAIL_HOST_PASSWORD = environ.get('EMAIL_HOST_PASSWORD', SMTP_PASSWORD) + + # See: https://docs.djangoproject.com/en/dev/ref/settings/#email-host-user + EMAIL_HOST_USER = environ.get('EMAIL_HOST_USER', SMTP_USERNAME) + + # See: https://docs.djangoproject.com/en/dev/ref/settings/#email-port + EMAIL_PORT = environ.get('EMAIL_PORT', 587) + + # See: https://docs.djangoproject.com/en/dev/ref/settings/#email-subject-prefix + EMAIL_SUBJECT_PREFIX = 'KarmaNotes ' + + # See: https://docs.djangoproject.com/en/dev/ref/settings/#email-use-tls + EMAIL_USE_TLS = True + + DEFAULT_FROM_EMAIL = 'info@karmanotes.org' + + # See: https://docs.djangoproject.com/en/dev/ref/settings/#server-email + SERVER_EMAIL = EMAIL_HOST_USER +########## END EMAIL CONFIGURATION + + +########## DATABASE CONFIGURATION +DATABASES = { + 'default': { + 'ENGINE': 'django.db.backends.postgresql_psycopg2', + 'NAME': PROD_DB_NAME, + 'USER': PROD_DB_USERNAME, + 'PASSWORD': PROD_DB_PASSWORD, + 'HOST': '', + 'PORT': '', # Set to empty string for default. Not used with sqlite3. + } +} +########## END DATABASE CONFIGURATION + + +########## CACHE CONFIGURATION +# See: https://docs.djangoproject.com/en/dev/ref/settings/#caches +CACHES = { + 'default': { + 'BACKEND': 'django.core.cache.backends.memcached.PyLibMCCache', + } +} +########## END CACHE CONFIGURATION + + +########## CELERY CONFIGURATION +# See: http://docs.celeryproject.org/en/latest/configuration.html#broker-transport +BROKER_TRANSPORT = 'amqplib' + +# Set this number to the amount of allowed concurrent connections on your AMQP +# provider, divided by the amount of active workers you have. +# +# For example, if you have the 'Little Lemur' CloudAMQP plan (their free tier), +# they allow 3 concurrent connections. So if you run a single worker, you'd +# want this number to be 3. If you had 3 workers running, you'd lower this +# number to 1, since 3 workers each maintaining one open connection = 3 +# connections total. +# +# See: http://docs.celeryproject.org/en/latest/configuration.html#broker-pool-limit +BROKER_POOL_LIMIT = 3 + +# See: http://docs.celeryproject.org/en/latest/configuration.html#broker-connection-max-retries +BROKER_CONNECTION_MAX_RETRIES = 0 + +# See: http://docs.celeryproject.org/en/latest/configuration.html#broker-url +BROKER_URL = environ.get('RABBITMQ_URL') or environ.get('CLOUDAMQP_URL') + +# See: http://docs.celeryproject.org/en/latest/configuration.html#celery-result-backend +CELERY_RESULT_BACKEND = 'amqp' + +# Periodic tasks +CELERYBEAT_SCHEDULE = { + 'tweet-about-notes': { + 'task': 'tweet_note', + 'schedule': timedelta(minutes=60), + }, +} + +CELERY_TIMEZONE = 'UTC' + +########## END CELERY CONFIGURATION + + +########## STORAGE CONFIGURATION +# See: http://django-storages.readthedocs.org/en/latest/index.html +INSTALLED_APPS += ( + 'storages', + 'gunicorn', +) + +# See: http://django-storages.readthedocs.org/en/latest/backends/amazon-S3.html#settings +STATICFILES_STORAGE = DEFAULT_FILE_STORAGE = 'storages.backends.s3boto.S3BotoStorage' + +# See: http://django-storages.readthedocs.org/en/latest/backends/amazon-S3.html#settings +AWS_CALLING_FORMAT = CallingFormat.SUBDOMAIN + + +# AWS cache settings, don't change unless you know what you're doing: +AWS_EXPIREY = 60 * 60 * 24 * 7 +AWS_HEADERS = { + 'Cache-Control': 'max-age=%d, s-maxage=%d, must-revalidate' % (AWS_EXPIREY, + AWS_EXPIREY) +} + +# See: https://docs.djangoproject.com/en/dev/ref/settings/#static-url +STATIC_URL = 'https://s3.amazonaws.com/%s/' % AWS_STORAGE_BUCKET_NAME +########## END STORAGE CONFIGURATION + + +########## COMPRESSION CONFIGURATION +# See: http://django_compressor.readthedocs.org/en/latest/settings/#django.conf.settings.COMPRESS_OFFLINE +COMPRESS_OFFLINE = True + +# See: http://django_compressor.readthedocs.org/en/latest/settings/#django.conf.settings.COMPRESS_STORAGE +COMPRESS_STORAGE = DEFAULT_FILE_STORAGE + +# See: http://django_compressor.readthedocs.org/en/latest/settings/#django.conf.settings.COMPRESS_CSS_FILTERS +COMPRESS_CSS_FILTERS += [ + 'compressor.filters.cssmin.CSSMinFilter', +] + +# See: http://django_compressor.readthedocs.org/en/latest/settings/#django.conf.settings.COMPRESS_JS_FILTERS +COMPRESS_JS_FILTERS += [ + 'compressor.filters.jsmin.JSMinFilter', +] +########## END COMPRESSION CONFIGURATION + + +########## SECRET CONFIGURATION +# See: https://docs.djangoproject.com/en/dev/ref/settings/#secret-key +SECRET_KEY = environ.get('SECRET_KEY', SECRET_KEY) +########## END SECRET CONFIGURATION + +########## DEBUG CONFIGURATION +# See: https://docs.djangoproject.com/en/dev/ref/settings/#debug +DEBUG = True + +# See: https://docs.djangoproject.com/en/dev/ref/settings/#template-debug +TEMPLATE_DEBUG = DEBUG +########## END DEBUG CONFIGURATION + +########## TESTING CONFIGURATION +# Use django-nose to test our app, see https://github.com/jbalogh/django-nose +TEST_RUNNER = 'django_nose.NoseTestSuiteRunner' +########## END TESTING CONFIGURATION + +########## TOOLBAR CONFIGURATION +# See: https://github.com/django-debug-toolbar/django-debug-toolbar#installation +INSTALLED_APPS += ( + 'debug_toolbar', + 'django_extensions', + 'django_nose', +) + +# See: https://github.com/django-debug-toolbar/django-debug-toolbar#installation +INTERNAL_IPS = ('127.0.0.1',) + +# See: https://github.com/django-debug-toolbar/django-debug-toolbar#installation +MIDDLEWARE_CLASSES += ( + 'debug_toolbar.middleware.DebugToolbarMiddleware', +) + +DEBUG_TOOLBAR_CONFIG = { + 'INTERCEPT_REDIRECTS': False # Don't interrput our redirects! +} +########## END TOOLBAR CONFIGURATION diff --git a/manage.py b/manage.py index 891e68d..cecaabd 100755 --- a/manage.py +++ b/manage.py @@ -7,7 +7,7 @@ if __name__ == "__main__": PROJECT_ROOT = os.path.dirname(os.path.abspath(__file__)) sys.path.append(os.path.join(PROJECT_ROOT, 'karmaworld/apps')) - os.environ.setdefault("DJANGO_SETTINGS_MODULE", "karmaworld.settings.prod") + os.environ.setdefault("DJANGO_SETTINGS_MODULE", "karmaworld.settings.vmdev") from django.core.management import execute_from_command_line