Skip to content

Commit

Permalink
Adapted django-example to django 1.7.x. Moved openshiftlibs.py to pro…
Browse files Browse the repository at this point in the history
…ject root. Deleted existing django installation and installed django 1.7.7 app (requires python 2.7 or newer, see django 1.7 release notes)

added the openshiftlibs.py library (existed in the original project, inside the django project which I removed for the sake of generalizing the code). It now resides in the root folder.
  • Loading branch information
zack committed Mar 25, 2015
1 parent dca9622 commit beb0db5
Show file tree
Hide file tree
Showing 22 changed files with 324 additions and 401 deletions.
21 changes: 14 additions & 7 deletions .openshift/action_hooks/deploy
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,22 @@

source $OPENSHIFT_HOMEDIR/python/virtenv/bin/activate

if [ ! -f $OPENSHIFT_DATA_DIR/sqlite3.db ]
# GETTING-STARTED: change 'db.sqlite3' to your sqlite3 database:
if [ ! -f $OPENSHIFT_DATA_DIR/db.sqlite3 ]
then
echo "Copying $OPENSHIFT_REPO_DIR/wsgi/openshift/sqlite3.db to $OPENSHIFT_DATA_DIR"
cp "$OPENSHIFT_REPO_DIR"wsgi/openshift/sqlite3.db $OPENSHIFT_DATA_DIR
# GETTING-STARTED: change 'myproject' to your project name and 'db.sqlite3' to the name of your sqlite3 database:
echo "Copying $OPENSHIFT_REPO_DIR/wsgi/myproject/db.sqlite3 to $OPENSHIFT_DATA_DIR"
# GETTING-STARTED: change 'myproject' to your project name and 'db.sqlite3' to the name of your sqlite3 database:
cp "$OPENSHIFT_REPO_DIR"wsgi/myproject/db.sqlite3 $OPENSHIFT_DATA_DIR
python "$OPENSHIFT_REPO_DIR".openshift/action_hooks/secure_db.py | tee ${OPENSHIFT_DATA_DIR}/CREDENTIALS
else
echo "Executing 'python $OPENSHIFT_REPO_DIR/wsgi/openshift/manage.py syncdb --noinput'"
python "$OPENSHIFT_REPO_DIR"wsgi/openshift/manage.py syncdb --noinput
# GETTING-STARTED: change 'myproject' to your project name:
echo "Executing 'python $OPENSHIFT_REPO_DIR/wsgi/myproject/manage.py syncdb --noinput'"
# GETTING-STARTED: change 'myproject' to your project name:
python "$OPENSHIFT_REPO_DIR"wsgi/myproject/manage.py syncdb --noinput
fi

echo "Executing 'python $OPENSHIFT_REPO_DIR/wsgi/openshift/manage.py collectstatic --noinput'"
python "$OPENSHIFT_REPO_DIR"wsgi/openshift/manage.py collectstatic --noinput
# GETTING-STARTED: change 'myproject' to your project name:
echo "Executing 'python $OPENSHIFT_REPO_DIR/wsgi/myproject/manage.py collectstatic --noinput'"
# GETTING-STARTED: change 'myproject' to your project name:
python "$OPENSHIFT_REPO_DIR"wsgi/myproject/manage.py collectstatic --noinput
6 changes: 4 additions & 2 deletions .openshift/action_hooks/secure_db.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,14 @@
import hashlib, imp, os, sqlite3

# Load the OpenShift helper library
lib_path = os.environ['OPENSHIFT_REPO_DIR'] + 'wsgi/openshift/'
# GETTING-STARTED: change 'myproject' to your project name:
lib_path = os.environ['OPENSHIFT_REPO_DIR'] + 'wsgi/myproject/'
modinfo = imp.find_module('openshiftlibs', [lib_path])
openshiftlibs = imp.load_module('openshiftlibs', modinfo[0], modinfo[1], modinfo[2])

# Open the database
conn = sqlite3.connect(os.environ['OPENSHIFT_DATA_DIR'] + '/sqlite3.db')
# GETTING-STARTED: change 'db.sqlite3' to your sqlite3 database:
conn = sqlite3.connect(os.environ['OPENSHIFT_DATA_DIR'] + '/db.sqlite3')
c = conn.cursor()

# Grab the default security info
Expand Down
133 changes: 0 additions & 133 deletions .openshift/template.patch

This file was deleted.

4 changes: 4 additions & 0 deletions README
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
#######################################################
forked from https://github.com/openshift/django-example
#######################################################

Feel free to change or remove this file, it is informational only.

Repo layout
Expand Down
13 changes: 9 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,17 +1,22 @@
#######################################################
forked from https://github.com/openshift/django-example
#######################################################


Django on OpenShift
===================

This git repository helps you get up and running quickly w/ a Django
installation on OpenShift. The Django project name used in this repo
is 'openshift' but you can feel free to change it. Right now the
is 'myproject' but you can feel free to change it. Right now the
backend is sqlite3 and the database runtime is found in
`$OPENSHIFT_DATA_DIR/sqlite3.db`.
`$OPENSHIFT_DATA_DIR/db.sqlite3`.

Before you push this app for the first time, you will need to change
the [Django admin password](#admin-user-name-and-password).
Then, when you first push this
application to the cloud instance, the sqlite database is copied from
`wsgi/openshift/sqlite3.db` with your newly changed login
`wsgi/myproject/db.sqlite3` with your newly changed login
credentials. Other than the password change, this is the stock
database that is created when `python manage.py syncdb` is run with
only the admin app installed.
Expand Down Expand Up @@ -47,7 +52,7 @@ Install the RHC client tools if you have not already done so:

Create a python application

rhc app create django python-2.6
rhc app create django python-2.7

Add this upstream repo

Expand Down
71 changes: 46 additions & 25 deletions wsgi/openshift/openshiftlibs.py → libs/openshiftlibs.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,25 @@
#!/usr/bin/env python

__author__ = 'N. Harrison Ripps'

"""
This library was written to the original django-example project -
https://github.com/openshift/django-example
by @url(https://github.com/nhr), but since it was placed inside
the django project folder I've removed it when I started working
on my fork -
https://github.com/ZackYovel/django-example
Since it is required by the .openshift/action_hooks/secure_db.py
action hook and since this library is basically a recommendation
of the openshift providers, I'm adding it again but placing it
in the libs folder, as a generic gependency and not a project
specific file.
running 'grep -r openshiftlibs' resulted in one file that
references this library: .openshift/action_hooks/secure_db.py.
"""

import hashlib, inspect, os, random, sys

# Gets the secret token provided by OpenShift
Expand Down Expand Up @@ -59,28 +80,28 @@ def openshift_secure(default_keys, secure_function = 'make_secure_key'):

# This function transforms default keys into per-deployment random keys;
def make_secure_key(key_info):
hashcode = key_info['hash']
key = key_info['variable']
original = key_info['original']

# These are the legal password characters
# as per the Django source code
# (django/contrib/auth/models.py)
chars = 'abcdefghjkmnpqrstuvwxyz'
chars += 'ABCDEFGHJKLMNPQRSTUVWXYZ'
chars += '23456789'

# Use the hash to seed the RNG
random.seed(int("0x" + hashcode[:8], 0))

# Create a random string the same length as the default
rand_key = ''
for _ in range(len(original)):
rand_pos = random.randint(0,len(chars))
rand_key += chars[rand_pos:(rand_pos+1)]

# Reset the RNG
random.seed()

# Set the value
return rand_key
hashcode = key_info['hash']
key = key_info['variable']
original = key_info['original']

# These are the legal password characters
# as per the Django source code
# (django/contrib/auth/models.py)
chars = 'abcdefghjkmnpqrstuvwxyz'
chars += 'ABCDEFGHJKLMNPQRSTUVWXYZ'
chars += '23456789'

# Use the hash to seed the RNG
random.seed(int("0x" + hashcode[:8], 0))

# Create a random string the same length as the default
rand_key = ''
for _ in range(len(original)):
rand_pos = random.randint(0,len(chars))
rand_key += chars[rand_pos:(rand_pos+1)]

# Reset the RNG
random.seed()

# Set the value
return rand_key
Loading

0 comments on commit beb0db5

Please sign in to comment.