Skip to content

Commit

Permalink
Config updates
Browse files Browse the repository at this point in the history
Squashed commit of the following:

commit 1aea65f
Author: Bryan Ricker <[email protected]>
Date:   Thu Aug 21 00:35:31 2014 -0700

    Add dbsync

commit dbfb14a
Author: Bryan Ricker <[email protected]>
Date:   Fri Jul 11 21:53:05 2014 -0700

    Use SITE_ROOT instead of BASE_DIR

commit da0bca3
Author: Bryan Ricker <[email protected]>
Date:   Fri Jul 11 21:45:35 2014 -0700

    Remove migrations/init from gitignore

commit 2c4405e
Author: Bryan Ricker <[email protected]>
Date:   Fri Jul 11 21:43:55 2014 -0700

    Update SITE_URL; fix STATIC_ROOT

commit 958d7f3
Merge: 08f95e3 6ddd3e3
Author: Bryan Ricker <[email protected]>
Date:   Fri Jul 11 20:24:41 2014 -0700

    Merge remote-tracking branch 'origin/master' into config-updates

    Conflicts:
    	fabfile.py

commit 08f95e3
Author: Bryan Ricker <[email protected]>
Date:   Fri Jul 11 20:24:05 2014 -0700

    Remove some fabric commands

commit 387a6a7
Author: Bryan Ricker <[email protected]>
Date:   Sun Jul 6 23:47:25 2014 -0700

    Add missing init file

commit 5251035
Author: Bryan Ricker <[email protected]>
Date:   Sun Jul 6 23:16:49 2014 -0700

    Remove deploy functions from fabfile

commit 38b92b7
Author: Bryan Ricker <[email protected]>
Date:   Fri Jul 4 19:21:34 2014 -0700

    Update fabfile; run pip on every deploy; point to correct python

commit d3f66f7
Author: Bryan Ricker <[email protected]>
Date:   Fri Jul 4 11:24:47 2014 -0700

    Remove psycopg dep

commit 33e4a2c
Author: Bryan Ricker <[email protected]>
Date:   Fri Jul 4 11:22:58 2014 -0700

    Update MySQL-python version

commit 6d37822
Author: Bryan Ricker <[email protected]>
Date:   Fri Jul 4 11:17:36 2014 -0700

    Update production settings file

commit e531722
Author: Bryan Ricker <[email protected]>
Date:   Fri Jul 4 11:14:48 2014 -0700

    Update gitkeep filename

commit d3d6bf3
Author: Bryan Ricker <[email protected]>
Date:   Fri Jul 4 11:14:23 2014 -0700

    Update passenger loader

commit 2834af4
Author: Bryan Ricker <[email protected]>
Date:   Fri Jul 4 11:13:50 2014 -0700

    Add config files to gitignore
  • Loading branch information
bricker committed Aug 21, 2014
1 parent 6ddd3e3 commit ec358f7
Show file tree
Hide file tree
Showing 11 changed files with 116 additions and 78 deletions.
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,6 @@ bak_wildfireannualreview.json
bak_wildfiredisplaycontent.json
bak_wildfiretweet.json
bak_wildfireupdate.json
migrations/__init__.py

config/*.yml
dbsync_setup.rb
4 changes: 4 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
source "https://rubygems.org"

gem 'rake'
gem 'dbsync', [">= 1.0.0.beta3", "< 2.0.0"]
29 changes: 29 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
@@ -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
1 change: 1 addition & 0 deletions Rakefile
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
require 'dbsync/rake_tasks'
File renamed without changes.
17 changes: 17 additions & 0 deletions dbsync_setup.rb.template
Original file line number Diff line number Diff line change
@@ -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"
}
66 changes: 8 additions & 58 deletions fabfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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))

#### ####

Expand Down Expand Up @@ -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")
local("python manage.py loaddata bak_wildfiredisplaycontent.json")


def __env_cmd(cmd):
return env.bin_root + cmd
19 changes: 8 additions & 11 deletions passenger_wsgi.py
Original file line number Diff line number Diff line change
@@ -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()
Empty file added public/.gitkeep-passenger
Empty file.
3 changes: 1 addition & 2 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
51 changes: 45 additions & 6 deletions settings_production.py
Original file line number Diff line number Diff line change
Expand Up @@ -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/"
Expand All @@ -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 = (
Expand Down

0 comments on commit ec358f7

Please sign in to comment.