diff --git a/.gitignore b/.gitignore index ee8b88c..bb9e5e9 100644 --- a/.gitignore +++ b/.gitignore @@ -21,4 +21,6 @@ bak_wildfireannualreview.json bak_wildfiredisplaycontent.json bak_wildfiretweet.json bak_wildfireupdate.json -migrations/__init__.py \ No newline at end of file + +config/*.yml +dbsync_setup.rb diff --git a/Gemfile b/Gemfile new file mode 100644 index 0000000..f162a9b --- /dev/null +++ b/Gemfile @@ -0,0 +1,4 @@ +source "https://rubygems.org" + +gem 'rake' +gem 'dbsync', [">= 1.0.0.beta3", "< 2.0.0"] diff --git a/Gemfile.lock b/Gemfile.lock new file mode 100644 index 0000000..cf3b08d --- /dev/null +++ b/Gemfile.lock @@ -0,0 +1,29 @@ +GEM + remote: https://rubygems.org/ + specs: + activesupport (4.1.5) + i18n (~> 0.6, >= 0.6.9) + json (~> 1.7, >= 1.7.7) + minitest (~> 5.1) + thread_safe (~> 0.1) + tzinfo (~> 1.1) + climate_control (0.0.3) + activesupport (>= 3.0) + cocaine (0.5.4) + climate_control (>= 0.0.3, < 1.0) + dbsync (1.0.0.beta3) + cocaine (>= 0.5.0, < 0.6) + i18n (0.6.11) + json (1.8.1) + minitest (5.4.0) + rake (10.3.2) + thread_safe (0.3.4) + tzinfo (1.2.2) + thread_safe (~> 0.1) + +PLATFORMS + ruby + +DEPENDENCIES + dbsync (>= 1.0.0.beta3, < 2.0.0) + rake diff --git a/Rakefile b/Rakefile new file mode 100644 index 0000000..1f1087e --- /dev/null +++ b/Rakefile @@ -0,0 +1 @@ +require 'dbsync/rake_tasks' diff --git a/public/.gitkeep b/calfire_tracker/migrations/__init__.py similarity index 100% rename from public/.gitkeep rename to calfire_tracker/migrations/__init__.py diff --git a/dbsync_setup.rb.template b/dbsync_setup.rb.template new file mode 100644 index 0000000..2c7bc4f --- /dev/null +++ b/dbsync_setup.rb.template @@ -0,0 +1,17 @@ +# Copy this file into dbsync_setup.rb and update the information. + +Dbsync.file_config = { + :strategy => :curl, + :bin_opts => "--netrc", + :local => "~/dbdumps/dbsync-firetracker.sql", + :remote => "ftp://backups-server.scpr.org/database/firetracker-latest.sql.gz" +} + +# If you haven't set a password (or if dbsync is asking for your +# database password), remove the :password line. +Dbsync.db_config = { + :adapter => "mysql2", + :database => "yourdb", + :username => "youruser", + :password => "yourpassword" +} diff --git a/fabfile.py b/fabfile.py index fb15c2c..f649fe8 100644 --- a/fabfile.py +++ b/fabfile.py @@ -6,68 +6,14 @@ from fabric.contrib.console import confirm from fabric.colors import green -env.user = 'archive' -env.hosts = ['66.226.4.228'] -env.project_root = '/web/archive/apps/firetracker/firetracker' -env.python_exe = "/web/archive/apps/firetracker/virtualenvs/firetracker/bin/python" - logging.basicConfig(format='\033[1;36m%(levelname)s:\033[0;37m %(message)s', level=logging.DEBUG) -# production functions -def update_code(): - # production function to update the code on the remote server - with cd(env.project_root): - run('git pull') - -def restart(): - # production function to restart the server - with cd(env.project_root): - run('mkdir -p tmp/ && touch tmp/restart.txt') - -def collectstatic(): - # production function to handle the static assets on the remote server - with cd(env.project_root): - with shell_env(DJANGO_SETTINGS_MODULE='settings_production'): - run("%s manage.py collectstatic --noinput" % env.python_exe) - -def deploy(): - # production function to pull the latest code from source control & restarts the server - with cd(env.project_root): - update_code() - collectstatic() - restart() - -def migrate(*args): - #production function to execute south migrations (takes arguments) - with cd(env.project_root): - with shell_env(DJANGO_SETTINGS_MODULE='settings_production'): - run("%s manage.py migrate " % env.python_exe) + " ".join(args) - -def revert(): - # production function to revert git via reset --hard @{1} - with cd(env.project_root): - run('git reset --hard @{1}') - collectstatic() - restart() - -def server_scrape(): - # production function to manually run the scraper on the remote server - with cd(env.project_root): - with shell_env(DJANGO_SETTINGS_MODULE='settings_production'): - run("%s manage.py scraper_wildfires" % env.python_exe) - def server_update_ids(): # production function to manually run the scraper on the remote server with cd(env.project_root): with shell_env(DJANGO_SETTINGS_MODULE='settings_production'): run("%s manage.py update_fire_ids" % env.python_exe) -def server_tweets(): - # production function to manually poll twitter on the remote server - with cd(env.project_root): - with shell_env(DJANGO_SETTINGS_MODULE='settings_production'): - run("%s manage.py tweepy_to_db" % env.python_exe) - def server_fixture_dump(model=''): # dumps fixtures file of wildfires in the database # ex usage: @@ -78,7 +24,7 @@ def server_fixture_dump(model=''): # fab server_fixture_dump:'wildfiredisplaycontent' with cd(env.project_root): with shell_env(DJANGO_SETTINGS_MODULE='settings_production'): - run("%s manage.py dumpdata calfire_tracker.%s --indent=2 > bak_%s.json" % (env.python_exe, model, model)) + run(__env_cmd("python manage.py dumpdata calfire_tracker.%s --indent=2 > bak_%s.json" % (model, model))) def server_fixture_load(model=''): # dumps fixtures file of wildfires in the database @@ -90,7 +36,7 @@ def server_fixture_load(model=''): # fab server_fixture_load:'wildfiredisplaycontent' with cd(env.project_root): with shell_env(DJANGO_SETTINGS_MODULE='settings_production'): - run("%s manage.py loaddata bak_%s.json" % (env.python_exe, model)) + run(__env_cmd("python manage.py loaddata bak_%s.json" % model)) def server_sync_data_with_local(model=''): # pulls data for older fires from development, uploads to server @@ -105,7 +51,7 @@ def server_sync_data_with_local(model=''): local("scp ~/Programming/2kpcc/django-projects/firetracker/bak_%s.json archive@media:/web/archive/apps/firetracker/firetracker" % (model)) with cd(env.project_root): with shell_env(DJANGO_SETTINGS_MODULE='settings_production'): - run("%s manage.py loaddata bak_%s.json" % (env.python_exe, model)) + run(__env_cmd("python manage.py loaddata bak_%s.json" % model)) #### #### @@ -174,4 +120,8 @@ def local_sync_data_with_server(): server_fixture_dump('wildfiredisplaycontent') local("scp archive@media:/web/archive/apps/firetracker/firetracker/bak_wildfiredisplaycontent.json .") - local("python manage.py loaddata bak_wildfiredisplaycontent.json") \ No newline at end of file + local("python manage.py loaddata bak_wildfiredisplaycontent.json") + + +def __env_cmd(cmd): + return env.bin_root + cmd diff --git a/passenger_wsgi.py b/passenger_wsgi.py index 080a471..d5fee70 100644 --- a/passenger_wsgi.py +++ b/passenger_wsgi.py @@ -1,19 +1,16 @@ -import os, sys, site +import os, sys, site, yaml -#REMOTE_APP_ROOT = "/Users/bryan/projects/firetracker" +env = os.environ.setdefault("DJANGO_ENV", "production") +os.environ.setdefault("DJANGO_SETTINGS_MODULE", "settings_%s" % env) +app_config = yaml.load(open("config/app.yml", 'r'))[env] -REMOTE_APP_ROOT = "/web/archive/apps/firetracker" -INTERP = "%s/virtualenvs/firetracker/bin/python" % REMOTE_APP_ROOT +INTERP = os.path.join(app_config['bin_root'], 'python') -if sys.executable != INTERP: os.execl(INTERP, INTERP, *sys.argv) +if sys.executable != INTERP: + os.execl(INTERP, INTERP, *sys.argv) -sys.path.append(REMOTE_APP_ROOT) -sys.path.append('%s/firetracker' % REMOTE_APP_ROOT) - - -sys.path.append(REMOTE_APP_ROOT) -os.environ.setdefault("DJANGO_SETTINGS_MODULE", "settings_production") +sys.path.append(os.getcwd()) import django.core.handlers.wsgi application = django.core.handlers.wsgi.WSGIHandler() diff --git a/public/.gitkeep-passenger b/public/.gitkeep-passenger new file mode 100644 index 0000000..e69de29 diff --git a/requirements.txt b/requirements.txt index 00135e3..889c2c1 100644 --- a/requirements.txt +++ b/requirements.txt @@ -2,7 +2,7 @@ BeautifulSoup==3.2.1 Django==1.4.13 -e git://github.com/MichalMaM/django-commander.git@15ebe29728821dd986000bac178a65f6845e3e99#egg=Django_commander-dev Fabric==1.6.1 -MySQL-python==1.2.4 +MySQL-python==1.2.5 PyYAML==3.10 South==0.7.6 argparse==1.2.1 @@ -27,7 +27,6 @@ gunicorn==0.17.4 mechanize==0.2.5 mimeparse==0.1.3 paramiko==1.10.1 -psycopg2==2.5 pycrypto==2.6 python-dateutil==1.5 python-ptrace==0.6.4 diff --git a/settings_production.py b/settings_production.py index c127248..ec859e1 100644 --- a/settings_production.py +++ b/settings_production.py @@ -4,23 +4,62 @@ import os from os.path import expanduser from settings_common import * +import yaml DEBUG = False TEMPLATE_DEBUG = DEBUG -execfile(expanduser('~/apps/firetracker/.production_settings')) +env = 'production' + +CONFIG_DB = yaml.load(open("config/database.yml", 'r'))[env] +CONFIG_CACHE = yaml.load(open("config/cache.yml", 'r'))[env] +CONFIG_APP = yaml.load(open("config/app.yml", 'r'))[env] +CONFIG_API = yaml.load(open("config/api.yml", 'r'))[env] +CONFIG_EMAIL = yaml.load(open("config/email.yml", 'r'))[env] + +DATABASES = { + 'default': { + 'ENGINE' : 'django.db.backends.mysql', + 'NAME' : CONFIG_DB['database'], + 'USER' : CONFIG_DB['username'], + 'PASSWORD' : CONFIG_DB['password'], + 'HOST' : CONFIG_DB['host'], + 'PORT' : CONFIG_DB['port'] + } +} + +SECRET_KEY = CONFIG_APP['secret_key'] + +TWEEPY_CONSUMER_KEY = CONFIG_API['tweepy']['consumer_key'] +TWEEPY_CONSUMER_SECRET = CONFIG_API['tweepy']['consumer_secret'] +TWEEPY_ACCESS_TOKEN = CONFIG_API['tweepy']['access_token'] +TWEEPY_ACCESS_TOKEN_SECRET = CONFIG_API['tweepy']['access_token_secret'] + +ASSETHOST_TOKEN_SECRET = CONFIG_API['assethost']['token_secret'] + +# auth to send out emails when models change +EMAIL_HOST = CONFIG_EMAIL['host'] +EMAIL_HOST_USER = CONFIG_EMAIL['user'] +EMAIL_HOST_PASSWORD = CONFIG_EMAIL['password'] +EMAIL_PORT = CONFIG_EMAIL['port'] +EMAIL_USE_TLS = CONFIG_EMAIL['use_tls'] + CACHES = { "default": { 'BACKEND': 'redis_cache.cache.RedisCache', - 'LOCATION': '10.226.4.234:6379:5', + 'LOCATION': '%s:%s:%s' % ( + CONFIG_CACHE['host'], + CONFIG_CACHE['port'], + CONFIG_CACHE['db'] + ), 'OPTIONS': { 'CLIENT_CLASS': 'redis_cache.client.DefaultClient', } } } -ADMIN_MEDIA_PREFIX = '/firetracker/media/' +ADMIN_MEDIA_PREFIX = '/media/' # Absolute filesystem path to the directory that will hold user-uploaded files. # Example: "/home/media/media.lawrence.com/media/" @@ -35,13 +74,13 @@ # Don't put anything in this directory yourself; store your static files # in apps' "static/" subdirectories and in STATICFILES_DIRS. # Example: "/home/media/media.lawrence.com/static/" -STATIC_ROOT = '/web/archive/apps/firetracker/firetracker/public/static/' +STATIC_ROOT = os.path.join(SITE_ROOT, "public", "static") # URL prefix for static files. # Example: "http://media.lawrence.com/static/" -STATIC_URL = '/firetracker/static/' +STATIC_URL = '/static/' -SITE_URL = 'http://projects.scpr.org' +SITE_URL = 'http://firetracker.scpr.org' # Additional locations of static files STATICFILES_DIRS = (