├── data └── .gitkeep ├── libs └── .gitkeep ├── .openshift ├── markers │ └── .gitkeep ├── cron │ ├── daily │ │ └── .gitignore │ ├── hourly │ │ └── .gitignore │ ├── minutely │ │ └── .gitignore │ ├── monthly │ │ └── .gitignore │ ├── weekly │ │ ├── chrono.dat │ │ ├── chronograph │ │ ├── jobs.deny │ │ ├── jobs.allow │ │ └── README │ └── README.cron ├── README.md └── action_hooks │ ├── post_deploy │ ├── pre_build │ ├── build │ ├── deploy │ └── secure_db.py ├── wsgi ├── openshift │ ├── __init__.py │ ├── db.sqlite3 │ ├── views.py │ ├── templates │ │ └── home │ │ │ └── home.html │ ├── manage.py │ ├── urls.py │ ├── wsgi.py │ ├── openshiftlibs.py │ └── settings.py ├── application └── static │ └── README ├── .gitignore ├── setup.py ├── app.py.disabled └── README.md /data/.gitkeep: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /libs/.gitkeep: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /.openshift/markers/.gitkeep: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /wsgi/openshift/__init__.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /.openshift/cron/daily/.gitignore: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /.openshift/cron/hourly/.gitignore: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /.openshift/cron/minutely/.gitignore: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /.openshift/cron/monthly/.gitignore: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /.openshift/cron/weekly/chrono.dat: -------------------------------------------------------------------------------- 1 | Time And Relative D...n In Execution (Open)Shift! 2 | -------------------------------------------------------------------------------- /.openshift/cron/weekly/chronograph: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | echo "`date`: `cat $(dirname \"$0\")/chrono.dat`" 4 | -------------------------------------------------------------------------------- /wsgi/openshift/db.sqlite3: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rancavil/django-openshift-quickstart/HEAD/wsgi/openshift/db.sqlite3 -------------------------------------------------------------------------------- /wsgi/openshift/views.py: -------------------------------------------------------------------------------- 1 | from django.shortcuts import render_to_response 2 | 3 | def home(request): 4 | return render_to_response('home/home.html') 5 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | *.py[co] 2 | *.sw[po] 3 | *.bak 4 | *.orig 5 | *~ 6 | *.log 7 | *.egg-info 8 | .project 9 | .pydevproject 10 | venv/ 11 | virtenv/ 12 | dist/ 13 | build/ 14 | -------------------------------------------------------------------------------- /wsgi/application: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python 2 | 3 | import openshift.wsgi 4 | 5 | # reuse the application callable from openshift.wsgi 6 | application = openshift.wsgi.application 7 | -------------------------------------------------------------------------------- /wsgi/openshift/templates/home/home.html: -------------------------------------------------------------------------------- 1 | Congrats you have Django 1.6 running on OpenShift! 2 |
3 | let's admin 4 |
5 | Enjoy!!! 6 | -------------------------------------------------------------------------------- /.openshift/cron/weekly/jobs.deny: -------------------------------------------------------------------------------- 1 | # 2 | # Any script or job files listed in here (one entry per line) will NOT be 3 | # executed (read as ignored by run-parts). 4 | # 5 | 6 | README 7 | 8 | -------------------------------------------------------------------------------- /.openshift/README.md: -------------------------------------------------------------------------------- 1 | For information about action hooks supported by OpenShift, consult the documentation: 2 | 3 | http://openshift.github.io/documentation/oo_user_guide.html#the-openshift-directory 4 | -------------------------------------------------------------------------------- /.openshift/action_hooks/post_deploy: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # This is a simple post deploy hook executed after your application 3 | # is deployed and started. This script gets executed directly, so 4 | # it could be python, php, ruby, etc. 5 | -------------------------------------------------------------------------------- /.openshift/action_hooks/pre_build: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # This is a simple script and will be executed on your CI system if 3 | # available. Otherwise it will execute while your application is stopped 4 | # before the build step. This script gets executed directly, so it 5 | # could be python, php, ruby, etc. 6 | -------------------------------------------------------------------------------- /wsgi/openshift/manage.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | import os 3 | import sys 4 | 5 | if __name__ == "__main__": 6 | os.environ.setdefault("DJANGO_SETTINGS_MODULE", "settings") 7 | 8 | from django.core.management import execute_from_command_line 9 | 10 | execute_from_command_line(sys.argv) 11 | -------------------------------------------------------------------------------- /wsgi/openshift/urls.py: -------------------------------------------------------------------------------- 1 | from django.conf.urls import patterns, include, url 2 | 3 | from django.contrib import admin 4 | admin.autodiscover() 5 | 6 | urlpatterns = patterns('', 7 | # Examples: 8 | url(r'^$', 'views.home', name='home'), 9 | # url(r'^blog/', include('blog.urls')), 10 | 11 | url(r'^admin/', include(admin.site.urls)), 12 | ) 13 | -------------------------------------------------------------------------------- /.openshift/action_hooks/build: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # This is a simple build script and will be executed on your CI system if 3 | # available. Otherwise it will execute while your application is stopped 4 | # before the deploy step. This script gets executed directly, so it 5 | # could be python, php, ruby, etc. 6 | 7 | # Activate VirtualEnv in order to use the correct libraries 8 | -------------------------------------------------------------------------------- /.openshift/cron/weekly/jobs.allow: -------------------------------------------------------------------------------- 1 | # 2 | # Script or job files listed in here (one entry per line) will be 3 | # executed on a weekly-basis. 4 | # 5 | # Example: The chronograph script will be executed weekly but the README 6 | # and chrono.dat files in this directory will be ignored. 7 | # 8 | # The README file is actually ignored due to the entry in the 9 | # jobs.deny which is checked before jobs.allow (this file). 10 | # 11 | chronograph 12 | 13 | -------------------------------------------------------------------------------- /wsgi/static/README: -------------------------------------------------------------------------------- 1 | Public, static content goes here. Users can create rewrite rules to link to 2 | content in the static dir. For example, django commonly uses /media/ 3 | directories for static content. For example in a .htaccess file in a 4 | wsgi/.htaccess location, developers could put: 5 | 6 | RewriteEngine On 7 | RewriteRule ^application/media/(.+)$ /static/media/$1 [L] 8 | 9 | Then copy the media/* content to yourapp/wsgi/static/media/ and it should 10 | just work. 11 | 12 | Note: The ^application/ part of the URI match is required. 13 | -------------------------------------------------------------------------------- /setup.py: -------------------------------------------------------------------------------- 1 | from setuptools import setup 2 | 3 | import os 4 | 5 | # Put here required packages 6 | packages = ['Django<=1.6',] 7 | 8 | if 'REDISCLOUD_URL' in os.environ and 'REDISCLOUD_PORT' in os.environ and 'REDISCLOUD_PASSWORD' in os.environ: 9 | packages.append('django-redis-cache') 10 | packages.append('hiredis') 11 | 12 | setup(name='YourAppName', 13 | version='1.0', 14 | description='OpenShift App', 15 | author='Your Name', 16 | author_email='example@example.com', 17 | url='https://pypi.python.org/pypi', 18 | install_requires=packages, 19 | ) 20 | 21 | -------------------------------------------------------------------------------- /.openshift/cron/weekly/README: -------------------------------------------------------------------------------- 1 | Run scripts or jobs on a weekly basis 2 | ===================================== 3 | Any scripts or jobs added to this directory will be run on a scheduled basis 4 | (weekly) using run-parts. 5 | 6 | run-parts ignores any files that are hidden or dotfiles (.*) or backup 7 | files (*~ or *,) or named *.{rpmsave,rpmorig,rpmnew,swp,cfsaved} and handles 8 | the files named jobs.deny and jobs.allow specially. 9 | 10 | In this specific example, the chronograph script is the only script or job file 11 | executed on a weekly basis (due to white-listing it in jobs.allow). And the 12 | README and chrono.dat file are ignored either as a result of being black-listed 13 | in jobs.deny or because they are NOT white-listed in the jobs.allow file. 14 | 15 | For more details, please see ../README.cron file. 16 | 17 | -------------------------------------------------------------------------------- /wsgi/openshift/wsgi.py: -------------------------------------------------------------------------------- 1 | """ 2 | WSGI config for openshift project. 3 | 4 | It exposes the WSGI callable as a module-level variable named ``application``. 5 | 6 | For more information on this file, see 7 | https://docs.djangoproject.com/en/1.6/howto/deployment/wsgi/ 8 | """ 9 | import os 10 | import sys 11 | 12 | os.environ['DJANGO_SETTINGS_MODULE'] = 'settings' 13 | 14 | if os.environ.has_key('OPENSHIFT_REPO_DIR'): 15 | sys.path.append(os.path.join(os.environ['OPENSHIFT_REPO_DIR'], 'wsgi', 'openshift')) 16 | virtenv = os.environ['OPENSHIFT_PYTHON_DIR'] + '/virtenv/' 17 | os.environ['PYTHON_EGG_CACHE'] = os.path.join(virtenv, 'lib/python2.7/site-packages') 18 | virtualenv = os.path.join(virtenv, 'bin/activate_this.py') 19 | try: 20 | execfile(virtualenv, dict(__file__=virtualenv)) 21 | except IOError: 22 | pass 23 | 24 | from django.core.wsgi import get_wsgi_application 25 | application = get_wsgi_application() 26 | 27 | -------------------------------------------------------------------------------- /.openshift/action_hooks/deploy: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # This deploy hook gets executed after dependencies are resolved and the 3 | # build hook has been run but before the application has been started back 4 | # up again. This script gets executed directly, so it could be python, php, 5 | # ruby, etc. 6 | 7 | source $OPENSHIFT_HOMEDIR/python/virtenv/bin/activate 8 | 9 | if [ ! -f $OPENSHIFT_DATA_DIR/db.sqlite3 ] 10 | then 11 | echo "Copying $OPENSHIFT_REPO_DIR/wsgi/openshift/db.sqlite3 to $OPENSHIFT_DATA_DIR" 12 | cp "$OPENSHIFT_REPO_DIR"wsgi/openshift/db.sqlite3 $OPENSHIFT_DATA_DIR 13 | python "$OPENSHIFT_REPO_DIR".openshift/action_hooks/secure_db.py | tee ${OPENSHIFT_DATA_DIR}/CREDENTIALS 14 | else 15 | echo "Executing 'python $OPENSHIFT_REPO_DIR/wsgi/openshift/manage.py syncdb --noinput'" 16 | python "$OPENSHIFT_REPO_DIR"wsgi/openshift/manage.py syncdb --noinput 17 | fi 18 | 19 | echo "Executing 'python $OPENSHIFT_REPO_DIR/wsgi/openshift/manage.py collectstatic --noinput'" 20 | python "$OPENSHIFT_REPO_DIR"wsgi/openshift/manage.py collectstatic --noinput 21 | -------------------------------------------------------------------------------- /.openshift/cron/README.cron: -------------------------------------------------------------------------------- 1 | Run scripts or jobs on a periodic basis 2 | ======================================= 3 | Any scripts or jobs added to the minutely, hourly, daily, weekly or monthly 4 | directories will be run on a scheduled basis (frequency is as indicated by the 5 | name of the directory) using run-parts. 6 | 7 | run-parts ignores any files that are hidden or dotfiles (.*) or backup 8 | files (*~ or *,) or named *.{rpmsave,rpmorig,rpmnew,swp,cfsaved} 9 | 10 | The presence of two specially named files jobs.deny and jobs.allow controls 11 | how run-parts executes your scripts/jobs. 12 | jobs.deny ===> Prevents specific scripts or jobs from being executed. 13 | jobs.allow ===> Only execute the named scripts or jobs (all other/non-named 14 | scripts that exist in this directory are ignored). 15 | 16 | The principles of jobs.deny and jobs.allow are the same as those of cron.deny 17 | and cron.allow and are described in detail at: 18 | http://docs.redhat.com/docs/en-US/Red_Hat_Enterprise_Linux/6/html/Deployment_Guide/ch-Automating_System_Tasks.html#s2-autotasks-cron-access 19 | 20 | See: man crontab or above link for more details and see the the weekly/ 21 | directory for an example. 22 | 23 | PLEASE NOTE: The Cron cartridge must be installed in order to run the configured jobs. 24 | -------------------------------------------------------------------------------- /.openshift/action_hooks/secure_db.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | import hashlib, imp, os, sqlite3, sys 3 | 4 | # Load the openshift helper library 5 | lib_path = os.environ['OPENSHIFT_REPO_DIR'] + 'wsgi/openshift/' 6 | modinfo = imp.find_module('openshiftlibs', [lib_path]) 7 | openshiftlibs = imp.load_module('openshiftlibs', modinfo[0], modinfo[1], modinfo[2]) 8 | 9 | # Open the database 10 | conn = sqlite3.connect(os.environ['OPENSHIFT_DATA_DIR'] + '/db.sqlite3') 11 | c = conn.cursor() 12 | 13 | # Grab the default security info 14 | c.execute('SELECT password FROM AUTH_USER WHERE id = 1') 15 | pw_info = c.fetchone()[0] 16 | 17 | # The password is stored as [hashtype]$[iterations]$[salt]$[hashed] 18 | pw_fields = pw_info.split("$") 19 | hashtype = pw_fields[0] 20 | old_salt = pw_fields[2] 21 | old_pass = pw_fields[3] 22 | 23 | # Randomly generate a new password and a new salt 24 | # The PASSWORD value below just sets the length (12) 25 | # for the real new password. 26 | old_keys = { 'SALT': old_salt, 'PASS': '123456789ABC' } 27 | use_keys = openshiftlibs.openshift_secure(old_keys) 28 | 29 | # Encrypt the new password 30 | new_salt = use_keys['SALT'] 31 | new_pass = use_keys['PASS'] 32 | 33 | c.close() 34 | conn.close() 35 | 36 | # Update the user admin password 37 | os.environ['DJANGO_SETTINGS_MODULE'] = 'settings' 38 | sys.path.append(os.path.join(os.environ['OPENSHIFT_REPO_DIR'], 'wsgi', 'openshift')) 39 | from django.contrib.auth.models import User 40 | usr = User.objects.get(username__exact='admin') 41 | usr.set_password(new_pass) 42 | usr.save() 43 | 44 | # Print the new password info 45 | print "Django application credentials:\n\tuser: admin\n\t" + new_pass 46 | -------------------------------------------------------------------------------- /app.py.disabled: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | 3 | # 4 | # This file may be used instead of Apache mod_wsgi to run your python 5 | # web application in a different framework. A few examples are 6 | # provided (cherrypi, gevent), but this file may be altered to run 7 | # whatever framework is desired - or a completely customized service. 8 | # 9 | import imp 10 | import os 11 | 12 | try: 13 | zvirtenv = os.path.join(os.environ['OPENSHIFT_PYTHON_DIR'], 14 | 'virtenv', 'bin', 'activate_this.py') 15 | execfile(zvirtenv, dict(__file__ = zvirtenv) ) 16 | except IOError: 17 | pass 18 | 19 | # 20 | # IMPORTANT: Put any additional includes below this line. If placed above this 21 | # line, it's possible required libraries won't be in your searchable path 22 | # 23 | 24 | 25 | # 26 | # main(): 27 | # 28 | if __name__ == '__main__': 29 | ip = os.environ['OPENSHIFT_PYTHON_IP'] 30 | port = int(os.environ['OPENSHIFT_PYTHON_PORT']) 31 | app = imp.load_source('application', 'wsgi/application') 32 | 33 | fwtype="wsgiref" 34 | for fw in ("gevent", "cherrypy", "flask"): 35 | try: 36 | imp.find_module(fw) 37 | fwtype = fw 38 | except ImportError: 39 | pass 40 | 41 | print('Starting WSGIServer type %s on %s:%d ... ' % (fwtype, ip, port)) 42 | if fwtype == "gevent": 43 | from gevent.pywsgi import WSGIServer 44 | WSGIServer((ip, port), app.application).serve_forever() 45 | 46 | elif fwtype == "cherrypy": 47 | from cherrypy import wsgiserver 48 | server = wsgiserver.CherryPyWSGIServer( 49 | (ip, port), app.application, server_name=os.environ['OPENSHIFT_APP_DNS']) 50 | server.start() 51 | 52 | elif fwtype == "flask": 53 | from flask import Flask 54 | server = Flask(__name__) 55 | server.wsgi_app = app.application 56 | server.run(host=ip, port=port) 57 | 58 | else: 59 | from wsgiref.simple_server import make_server 60 | make_server(ip, port, app.application).serve_forever() 61 | -------------------------------------------------------------------------------- /wsgi/openshift/openshiftlibs.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | import hashlib, inspect, os, random, sys 3 | 4 | # Gets the secret token provided by OpenShift 5 | # or generates one (this is slightly less secure, but good enough for now) 6 | def get_openshift_secret_token(): 7 | token = os.getenv('OPENSHIFT_SECRET_TOKEN') 8 | name = os.getenv('OPENSHIFT_APP_NAME') 9 | uuid = os.getenv('OPENSHIFT_APP_UUID') 10 | if token is not None: 11 | return token 12 | elif (name is not None and uuid is not None): 13 | return hashlib.sha256(name + '-' + uuid).hexdigest() 14 | return None 15 | 16 | # Loop through all provided variables and generate secure versions 17 | # If not running on OpenShift, returns defaults and logs an error message 18 | # 19 | # This function calls secure_function and passes an array of: 20 | # { 21 | # 'hash': generated sha hash, 22 | # 'variable': name of variable, 23 | # 'original': original value 24 | # } 25 | def openshift_secure(default_keys, secure_function = 'make_secure_key'): 26 | # Attempts to get secret token 27 | my_token = get_openshift_secret_token() 28 | 29 | # Only generate random values if on OpenShift 30 | my_list = default_keys 31 | 32 | if my_token is not None: 33 | # Loop over each default_key and set the new value 34 | for key, value in default_keys.iteritems(): 35 | # Create hash out of token and this key's name 36 | sha = hashlib.sha256(my_token + '-' + key).hexdigest() 37 | # Pass a dictionary so we can add stuff without breaking existing calls 38 | vals = { 'hash': sha, 'variable': key, 'original': value } 39 | # Call user specified function or just return hash 40 | my_list[key] = sha 41 | if secure_function is not None: 42 | # Pick through the global and local scopes to find the function. 43 | possibles = globals().copy() 44 | possibles.update(locals()) 45 | supplied_function = possibles.get(secure_function) 46 | if not supplied_function: 47 | raise Exception("Cannot find supplied security function") 48 | else: 49 | my_list[key] = supplied_function(vals) 50 | else: 51 | calling_file = inspect.stack()[1][1] 52 | if os.getenv('OPENSHIFT_REPO_DIR'): 53 | base = os.getenv('OPENSHIFT_REPO_DIR') 54 | calling_file.replace(base,'') 55 | sys.stderr.write("OPENSHIFT WARNING: Using default values for secure variables, please manually modify in " + calling_file + "\n") 56 | 57 | return my_list 58 | 59 | 60 | # This function transforms default keys into per-deployment random keys; 61 | def make_secure_key(key_info): 62 | hashcode = key_info['hash'] 63 | key = key_info['variable'] 64 | original = key_info['original'] 65 | 66 | # These are the legal password characters 67 | # as per the Django source code 68 | # (django/contrib/auth/models.py) 69 | chars = 'abcdefghjkmnpqrstuvwxyz' 70 | chars += 'ABCDEFGHJKLMNPQRSTUVWXYZ' 71 | chars += '23456789' 72 | 73 | # Use the hash to seed the RNG 74 | random.seed(int("0x" + hashcode[:8], 0)) 75 | 76 | # Create a random string the same length as the default 77 | rand_key = '' 78 | for _ in range(len(original)): 79 | rand_pos = random.randint(0,len(chars)) 80 | rand_key += chars[rand_pos:(rand_pos+1)] 81 | 82 | # Reset the RNG 83 | random.seed() 84 | 85 | # Set the value 86 | return rand_key 87 | -------------------------------------------------------------------------------- /wsgi/openshift/settings.py: -------------------------------------------------------------------------------- 1 | """ 2 | Django settings for openshift project. 3 | 4 | For more information on this file, see 5 | https://docs.djangoproject.com/en/1.6/topics/settings/ 6 | 7 | For the full list of settings and their values, see 8 | https://docs.djangoproject.com/en/1.6/ref/settings/ 9 | """ 10 | # Build paths inside the project like this: os.path.join(BASE_DIR, ...) 11 | import os 12 | import imp 13 | 14 | ON_OPENSHIFT = False 15 | if os.environ.has_key('OPENSHIFT_REPO_DIR'): 16 | ON_OPENSHIFT = True 17 | 18 | BASE_DIR = os.path.dirname(os.path.realpath(__file__)) 19 | 20 | # Quick-start development settings - unsuitable for production 21 | # See https://docs.djangoproject.com/en/1.6/howto/deployment/checklist/ 22 | 23 | # SECURITY WARNING: keep the secret key used in production secret! 24 | # SECRET_KEY = 'ascq#%bii8(tld52#(^*ht@pzq%=nyb7fdv+@ok$u^iwb@2hwh' 25 | 26 | default_keys = { 'SECRET_KEY': 'vm4rl5*ymb@2&d_(gc$gb-^twq9w(u69hi--%$5xrh!xk(t%hw' } 27 | use_keys = default_keys 28 | if ON_OPENSHIFT: 29 | imp.find_module('openshiftlibs') 30 | import openshiftlibs 31 | use_keys = openshiftlibs.openshift_secure(default_keys) 32 | 33 | SECRET_KEY = use_keys['SECRET_KEY'] 34 | 35 | # SECURITY WARNING: don't run with debug turned on in production! 36 | if ON_OPENSHIFT: 37 | DEBUG = False 38 | else: 39 | DEBUG = True 40 | 41 | TEMPLATE_DEBUG = DEBUG 42 | 43 | if DEBUG: 44 | ALLOWED_HOSTS = [] 45 | else: 46 | ALLOWED_HOSTS = ['*'] 47 | 48 | # Application definition 49 | 50 | INSTALLED_APPS = ( 51 | 'django.contrib.admin', 52 | 'django.contrib.auth', 53 | 'django.contrib.contenttypes', 54 | 'django.contrib.sessions', 55 | 'django.contrib.messages', 56 | 'django.contrib.staticfiles', 57 | ) 58 | 59 | MIDDLEWARE_CLASSES = ( 60 | 'django.contrib.sessions.middleware.SessionMiddleware', 61 | 'django.middleware.common.CommonMiddleware', 62 | 'django.middleware.csrf.CsrfViewMiddleware', 63 | 'django.contrib.auth.middleware.AuthenticationMiddleware', 64 | 'django.contrib.messages.middleware.MessageMiddleware', 65 | 'django.middleware.clickjacking.XFrameOptionsMiddleware', 66 | ) 67 | 68 | # If you want configure the REDISCLOUD 69 | if 'REDISCLOUD_URL' in os.environ and 'REDISCLOUD_PORT' in os.environ and 'REDISCLOUD_PASSWORD' in os.environ: 70 | redis_server = os.environ['REDISCLOUD_URL'] 71 | redis_port = os.environ['REDISCLOUD_PORT'] 72 | redis_password = os.environ['REDISCLOUD_PASSWORD'] 73 | CACHES = { 74 | 'default' : { 75 | 'BACKEND' : 'redis_cache.RedisCache', 76 | 'LOCATION' : '%s:%d'%(redis_server,int(redis_port)), 77 | 'OPTIONS' : { 78 | 'DB':0, 79 | 'PARSER_CLASS' : 'redis.connection.HiredisParser', 80 | 'PASSWORD' : redis_password, 81 | } 82 | } 83 | } 84 | MIDDLEWARE_CLASSES = ('django.middleware.cache.UpdateCacheMiddleware',) + MIDDLEWARE_CLASSES + ('django.middleware.cache.FetchFromCacheMiddleware',) 85 | 86 | ROOT_URLCONF = 'urls' 87 | 88 | WSGI_APPLICATION = 'wsgi.application' 89 | 90 | TEMPLATE_DIRS = ( 91 | os.path.join(BASE_DIR,'templates'), 92 | ) 93 | 94 | # Database 95 | # https://docs.djangoproject.com/en/1.6/ref/settings/#databases 96 | if ON_OPENSHIFT: 97 | DATABASES = { 98 | 'default': { 99 | 'ENGINE': 'django.db.backends.sqlite3', 100 | 'NAME': os.path.join(os.environ['OPENSHIFT_DATA_DIR'], 'db.sqlite3'), 101 | } 102 | } 103 | else: 104 | DATABASES = { 105 | 'default': { 106 | 'ENGINE': 'django.db.backends.sqlite3', 107 | 'NAME': os.path.join(BASE_DIR, 'db.sqlite3'), 108 | } 109 | } 110 | 111 | # Internationalization 112 | # https://docs.djangoproject.com/en/1.6/topics/i18n/ 113 | 114 | LANGUAGE_CODE = 'en-us' 115 | 116 | TIME_ZONE = 'UTC' 117 | 118 | USE_I18N = True 119 | 120 | USE_L10N = True 121 | 122 | USE_TZ = True 123 | 124 | 125 | # Static files (CSS, JavaScript, Images) 126 | # https://docs.djangoproject.com/en/1.6/howto/static-files/ 127 | STATIC_ROOT = os.path.join(BASE_DIR, '..', 'static') 128 | STATIC_URL = '/static/' 129 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | Django 1.6 on OpenShift 2 | ======================= 3 | 4 | This git repository helps you get up and running quickly w/ a Django 1.6 5 | installation on OpenShift. The Django project name used in this repo 6 | is 'openshift' but you can feel free to change it. Right now the 7 | backend is sqlite3 and the database runtime is found in 8 | `$OPENSHIFT_DATA_DIR/db.sqlite3`. 9 | 10 | Before you push this app for the first time, you will need to change 11 | the [Django admin password](#admin-user-name-and-password). 12 | Then, when you first push this 13 | application to the cloud instance, the sqlite database is copied from 14 | `wsgi/openshift/db.sqlite3` to $OPENSHIFT_DATA_DIR/ with your newly 15 | changed login credentials. Other than the password change, this is the 16 | stock database that is created when `python manage.py syncdb` is run with 17 | only the admin app installed. 18 | 19 | On subsequent pushes, a `python manage.py syncdb` is executed to make 20 | sure that any models you added are created in the DB. If you do 21 | anything that requires an alter table, you could add the alter 22 | statements in `GIT_ROOT/.openshift/action_hooks/alter.sql` and then use 23 | `GIT_ROOT/.openshift/action_hooks/deploy` to execute that script (make 24 | sure to back up your database w/ `rhc app snapshot save` first :) ) 25 | 26 | With this you can install Django 1.6 on OpenShift. 27 | 28 | Running on OpenShift 29 | -------------------- 30 | 31 | Create an account at http://openshift.redhat.com/ 32 | 33 | Install the RHC client tools if you have not already done so: 34 | 35 | sudo gem install rhc 36 | 37 | Create a python-2.7 application 38 | 39 | rhc app create -a djangoproj -t python-2.7 40 | 41 | Add this upstream repo 42 | 43 | cd djangoproj 44 | git remote add upstream -m master git://github.com/rancavil/django-openshift-quickstart.git 45 | git pull -s recursive -X theirs upstream master 46 | 47 | ####Note: 48 | If you want to use the Redis-Cloud with Django see [the wiki](https://github.com/rancavil/django-openshift-quickstart/wiki/Django-1.6-with-Redis-Cloud) 49 | 50 | Then push the repo upstream 51 | 52 | git push 53 | 54 | Here, the [admin user name and password will be displayed](#admin-user-name-and-password), so pay 55 | special attention. 56 | 57 | That's it. You can now checkout your application at: 58 | 59 | http://djangoproj-$yournamespace.rhcloud.com 60 | 61 | Admin user name and password 62 | ---------------------------- 63 | As the `git push` output scrolls by, keep an eye out for a 64 | line of output that starts with `Django application credentials: `. This line 65 | contains the generated admin password that you will need to begin 66 | administering your Django app. This is the only time the password 67 | will be displayed, so be sure to save it somewhere. You might want 68 | to pipe the output of the git push to a text file so you can grep for 69 | the password later. 70 | 71 | When you make: 72 | 73 | git push 74 | 75 | In the console output, you must find something like this: 76 | 77 | remote: Django application credentials: 78 | remote: user: admin 79 | remote: SY1ScjQGb2qb 80 | 81 | Or you can go to SSH console, and check the CREDENTIALS file located 82 | in $OPENSHIFT_DATA_DIR. 83 | 84 | cd $OPENSHIFT_DATA_DIR 85 | vi CREDENTIALS 86 | 87 | You should see the output: 88 | 89 | Django application credentials: 90 | user: admin 91 | SY1ScjQGb2qb 92 | 93 | After, you can change the password in the Django admin console. 94 | 95 | Django project directory structure 96 | ---------------------------------- 97 | 98 | djangoproj/ 99 | .gitignore 100 | .openshift/ 101 | README.md 102 | action_hooks/ (Scripts for deploy the application) 103 | build 104 | post_deploy 105 | pre_build 106 | deploy 107 | secure_db.py 108 | cron/ 109 | markers/ 110 | setup.py (Setup file with de dependencies and required libs) 111 | README.md 112 | libs/ (Adicional libraries) 113 | data/ (For not-externally exposed wsgi code) 114 | wsgi/ (Externally exposed wsgi goes) 115 | application (Script to execute the application on wsgi) 116 | openshift/ (Django project directory) 117 | __init__.py 118 | manage.py 119 | openshiftlibs.py 120 | settings.py 121 | urls.py 122 | views.py 123 | wsgi.py 124 | templates/ 125 | home/ 126 | home.html (Default home page, change it) 127 | static/ (Public static content gets served here) 128 | README 129 | 130 | From HERE you can start with your own application. 131 | --------------------------------------------------------------------------------