From dfe4b33de4b075675e96bc10db4b84f955af17c8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Moreira?= Date: Thu, 25 Aug 2011 03:41:57 +0000 Subject: [PATCH 01/38] Fixed typo --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 613c593..3d65cf1 100644 --- a/README.md +++ b/README.md @@ -15,7 +15,7 @@ should for security). On subsequent pushes, a 'python manage.py syncdb' is executed to make sure that any models you added are created in the DB. If you do anything that requires an alter table, you could add the alter statements in GIT_ROOT/.openshift/action_hooks/alter and then use -GIT_ROOT/.openshift/action_hooks/build to execute that script (make susre to +GIT_ROOT/.openshift/action_hooks/build to execute that script (make sure to back up your database w/ rhc-snapshot first :) ) From 58e07613aedb7cecc124bda2f11dccbba8d236b7 Mon Sep 17 00:00:00 2001 From: Dan McPherson Date: Sat, 19 Nov 2011 18:43:56 -0500 Subject: [PATCH 02/38] action hook updates --- .gitignore | 2 ++ .openshift/action_hooks/build | 7 ++++--- .openshift/action_hooks/deploy | 5 +++++ .openshift/action_hooks/post_deploy | 4 ++++ .openshift/action_hooks/pre_build | 5 +++++ README.md | 2 +- 6 files changed, 21 insertions(+), 4 deletions(-) create mode 100644 .openshift/action_hooks/deploy create mode 100644 .openshift/action_hooks/post_deploy create mode 100644 .openshift/action_hooks/pre_build diff --git a/.gitignore b/.gitignore index f3e9dd5..0152c92 100644 --- a/.gitignore +++ b/.gitignore @@ -3,3 +3,5 @@ *.bak *.orig *~ +.project +.pydevproject diff --git a/.openshift/action_hooks/build b/.openshift/action_hooks/build index 1176dd4..0aeae29 100755 --- a/.openshift/action_hooks/build +++ b/.openshift/action_hooks/build @@ -1,7 +1,8 @@ #!/bin/bash -# This is a simple build script, place your post-deploy but pre-start commands -# in this script. This script gets executed directly, so it could be python, -# php, ruby, etc. +# This is a simple build script and will be executed on your CI system if +# available. Otherwise it will execute while your application is stopped +# before the deploy step. This script gets executed directly, so it +# could be python, php, ruby, etc. # Activate VirtualEnv in order to use the correct libraries source $OPENSHIFT_APP_DIR/virtenv/bin/activate diff --git a/.openshift/action_hooks/deploy b/.openshift/action_hooks/deploy new file mode 100644 index 0000000..ed5eb99 --- /dev/null +++ b/.openshift/action_hooks/deploy @@ -0,0 +1,5 @@ +#!/bin/bash +# This deploy hook gets executed after dependencies are resolved and the +# build hook has been run but before the application has been started back +# up again. This script gets executed directly, so it could be python, php, +# ruby, etc. \ No newline at end of file diff --git a/.openshift/action_hooks/post_deploy b/.openshift/action_hooks/post_deploy new file mode 100644 index 0000000..a57d1f5 --- /dev/null +++ b/.openshift/action_hooks/post_deploy @@ -0,0 +1,4 @@ +#!/bin/bash +# This is a simple post deploy hook executed after your application +# is deployed and started. This script gets executed directly, so +# it could be python, php, ruby, etc. \ No newline at end of file diff --git a/.openshift/action_hooks/pre_build b/.openshift/action_hooks/pre_build new file mode 100644 index 0000000..10cd544 --- /dev/null +++ b/.openshift/action_hooks/pre_build @@ -0,0 +1,5 @@ +#!/bin/bash +# This is a simple script and will be executed on your CI system if +# available. Otherwise it will execute while your application is stopped +# before the build step. This script gets executed directly, so it +# could be python, php, ruby, etc. \ No newline at end of file diff --git a/README.md b/README.md index 3d65cf1..1204992 100644 --- a/README.md +++ b/README.md @@ -40,5 +40,5 @@ Then push the repo upstream That's it, you can now checkout your application at (default admin account is admin/admin): - http://django-$yourlogin.rhcloud.com + http://django-$yournamespace.rhcloud.com From 518273f91a7f2bb11ab21565aea7c2ca78c4d66c Mon Sep 17 00:00:00 2001 From: Dan McPherson Date: Sat, 19 Nov 2011 18:56:34 -0500 Subject: [PATCH 03/38] action hook updates --- .openshift/action_hooks/deploy | 0 .openshift/action_hooks/post_deploy | 0 .openshift/action_hooks/pre_build | 0 3 files changed, 0 insertions(+), 0 deletions(-) mode change 100644 => 100755 .openshift/action_hooks/deploy mode change 100644 => 100755 .openshift/action_hooks/post_deploy mode change 100644 => 100755 .openshift/action_hooks/pre_build diff --git a/.openshift/action_hooks/deploy b/.openshift/action_hooks/deploy old mode 100644 new mode 100755 diff --git a/.openshift/action_hooks/post_deploy b/.openshift/action_hooks/post_deploy old mode 100644 new mode 100755 diff --git a/.openshift/action_hooks/pre_build b/.openshift/action_hooks/pre_build old mode 100644 new mode 100755 From 3d3a5c426a17352f9ce806418633dc11930a04de Mon Sep 17 00:00:00 2001 From: Dan McPherson Date: Sun, 27 Nov 2011 20:24:08 -0500 Subject: [PATCH 04/38] doc updates --- README | 6 ++++-- README.md | 4 ++-- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/README b/README index 75f37d5..c99fb9e 100644 --- a/README +++ b/README @@ -8,8 +8,10 @@ libs/ - Additional libraries data/ - For not-externally exposed wsgi code setup.py - Standard setup.py, specify deps here ../data - For persistent data (also env var: OPENSHIFT_DATA_DIR) -.openshift/action_hooks/build - Script that gets run every push, just prior to - starting your app +.openshift/action_hooks/pre_build - Script that gets run every git push before the build +.openshift/action_hooks/build - Script that gets run every git push as part of the build process (on the CI system if available) +.openshift/action_hooks/deploy - Script that gets run every git push after build but before the app is restarted +.openshift/action_hooks/post_deploy - Script that gets run every git push after the app is restarted Environment Variables diff --git a/README.md b/README.md index 1204992..3f53063 100644 --- a/README.md +++ b/README.md @@ -14,8 +14,8 @@ You can delete the database from your git repo after the first push (you probabl should for security). On subsequent pushes, a 'python manage.py syncdb' is executed to make sure that any models you added are created in the DB. If you do anything that requires an alter table, you could add the alter statements -in GIT_ROOT/.openshift/action_hooks/alter and then use -GIT_ROOT/.openshift/action_hooks/build to execute that script (make sure to +in GIT_ROOT/.openshift/action_hooks/alter.sql and then use +GIT_ROOT/.openshift/action_hooks/post_deploy to execute that script (make sure to back up your database w/ rhc-snapshot first :) ) From c0281be52b305622df620e4028ccf3f2036b9cbe Mon Sep 17 00:00:00 2001 From: Dan McPherson Date: Mon, 28 Nov 2011 13:35:46 -0500 Subject: [PATCH 05/38] working out right place for db logic --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 3f53063..358ecfa 100644 --- a/README.md +++ b/README.md @@ -15,7 +15,7 @@ should for security). On subsequent pushes, a 'python manage.py syncdb' is executed to make sure that any models you added are created in the DB. If you do anything that requires an alter table, you could add the alter statements in GIT_ROOT/.openshift/action_hooks/alter.sql and then use -GIT_ROOT/.openshift/action_hooks/post_deploy to execute that script (make sure to +GIT_ROOT/.openshift/action_hooks/deploy to execute that script (make sure to back up your database w/ rhc-snapshot first :) ) From eeb285ac9c4d6ec95d81a2947cd2f5e5239a3e1e Mon Sep 17 00:00:00 2001 From: David Blado Date: Thu, 16 Feb 2012 13:42:08 -0800 Subject: [PATCH 06/38] swap out wsgi-3.2 for python-2.6 --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 358ecfa..3057fbd 100644 --- a/README.md +++ b/README.md @@ -26,7 +26,7 @@ Create an account at http://openshift.redhat.com/ Create a wsgi-3.2 application - rhc-create-app -a django -t wsgi-3.2 + rhc-create-app -a django -t python-2.6 Add this upstream seambooking repo From 37eac5dd60ffc03b07d180073f775213a5f001d4 Mon Sep 17 00:00:00 2001 From: Dan McPherson Date: Sun, 26 Feb 2012 19:12:43 -0500 Subject: [PATCH 07/38] wsgi-3.2 -> python-2.6 --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 3057fbd..f7090c9 100644 --- a/README.md +++ b/README.md @@ -24,7 +24,7 @@ Running on OpenShift Create an account at http://openshift.redhat.com/ -Create a wsgi-3.2 application +Create a python-2.6 application rhc-create-app -a django -t python-2.6 From 09533323e17ee389b76fb29e8a6cfc1607aeee83 Mon Sep 17 00:00:00 2001 From: Dan McPherson Date: Sun, 26 Feb 2012 22:33:47 -0500 Subject: [PATCH 08/38] Updating with new command format --- README | 2 +- wsgi/openshift/settings.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/README b/README index c99fb9e..a597f49 100644 --- a/README +++ b/README @@ -25,7 +25,7 @@ of use. The following list are some common variables but far from exhaustive: os.environ['OPENSHIFT_DATA_DIR'] - For persistent storage (between pushes) os.environ['OPENSHIFT_TMP_DIR'] - Temp storage (unmodified files deleted after 10 days) -When embedding a database using rhc-ctl-app, you can reference environment +When embedding a database using 'rhc app cartridge add', you can reference environment variables for username, host and password: os.environ['OPENSHIFT_DB_HOST'] - DB host diff --git a/wsgi/openshift/settings.py b/wsgi/openshift/settings.py index 989ecca..9c59d65 100644 --- a/wsgi/openshift/settings.py +++ b/wsgi/openshift/settings.py @@ -19,7 +19,7 @@ if ON_OPENSHIFT: # os.environ['OPENSHIFT_DB_*'] variables can be used with databases created - # with rhc-ctl-app (see /README in this git repo) + # with rhc app cartridge add (see /README in this git repo) DATABASES = { 'default': { 'ENGINE': 'django.db.backends.sqlite3', # Add 'postgresql_psycopg2', 'postgresql', 'mysql', 'sqlite3' or 'oracle'. From cd98da0df963acf8c4718a80e6e6b6f69fcf59dd Mon Sep 17 00:00:00 2001 From: Dan McPherson Date: Mon, 27 Feb 2012 10:26:05 -0500 Subject: [PATCH 09/38] Updating with new command format --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index f7090c9..4c88193 100644 --- a/README.md +++ b/README.md @@ -16,7 +16,7 @@ executed to make sure that any models you added are created in the DB. If you do anything that requires an alter table, you could add the alter statements in GIT_ROOT/.openshift/action_hooks/alter.sql and then use GIT_ROOT/.openshift/action_hooks/deploy to execute that script (make sure to -back up your database w/ rhc-snapshot first :) ) +back up your database w/ 'rhc app snapshot save' first :) ) Running on OpenShift @@ -26,7 +26,7 @@ Create an account at http://openshift.redhat.com/ Create a python-2.6 application - rhc-create-app -a django -t python-2.6 + rhc app create -a django -t python-2.6 Add this upstream seambooking repo From c29b6af96dacbee12b71a77886faaf3f58c69260 Mon Sep 17 00:00:00 2001 From: Albert Hopkins Date: Mon, 5 Mar 2012 14:34:45 -0500 Subject: [PATCH 10/38] settings.py: Set MEDIA_ROOT to OPENSHIFT_DATA environ, if defined. --- wsgi/openshift/settings.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/wsgi/openshift/settings.py b/wsgi/openshift/settings.py index 9c59d65..450328c 100644 --- a/wsgi/openshift/settings.py +++ b/wsgi/openshift/settings.py @@ -67,7 +67,7 @@ # Absolute filesystem path to the directory that will hold user-uploaded files. # Example: "/home/media/media.lawrence.com/media/" -MEDIA_ROOT = '' +MEDIA_ROOT = os.environ.get('OPENSHIFT_DATA', '') # URL that handles the media served from MEDIA_ROOT. Make sure to use a # trailing slash. From 5a28b912dedca2d2e677a2434dd1e02af58fa13e Mon Sep 17 00:00:00 2001 From: Albert Hopkins Date: Mon, 5 Mar 2012 14:40:39 -0500 Subject: [PATCH 11/38] OPENSHIFT_DATA != OPENSHIFT_DATA_DIR --- wsgi/openshift/settings.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/wsgi/openshift/settings.py b/wsgi/openshift/settings.py index 450328c..842669e 100644 --- a/wsgi/openshift/settings.py +++ b/wsgi/openshift/settings.py @@ -67,7 +67,7 @@ # Absolute filesystem path to the directory that will hold user-uploaded files. # Example: "/home/media/media.lawrence.com/media/" -MEDIA_ROOT = os.environ.get('OPENSHIFT_DATA', '') +MEDIA_ROOT = os.environ.get('OPENSHIFT_DATA_DIR', '') # URL that handles the media served from MEDIA_ROOT. Make sure to use a # trailing slash. From bf901804ca6d8112b487111dfc20cb07d37857c2 Mon Sep 17 00:00:00 2001 From: Dan McPherson Date: Thu, 22 Mar 2012 10:28:59 -0400 Subject: [PATCH 12/38] OPENSHIFT_APP -> OPENSHIFT_GEAR --- .openshift/action_hooks/build | 2 +- README | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.openshift/action_hooks/build b/.openshift/action_hooks/build index 0aeae29..e9cf9e0 100755 --- a/.openshift/action_hooks/build +++ b/.openshift/action_hooks/build @@ -5,7 +5,7 @@ # could be python, php, ruby, etc. # Activate VirtualEnv in order to use the correct libraries -source $OPENSHIFT_APP_DIR/virtenv/bin/activate +source $OPENSHIFT_GEAR_DIR/virtenv/bin/activate if [ ! -f $OPENSHIFT_DATA_DIR/sqlite3.db ] then diff --git a/README b/README index a597f49..df1ff25 100644 --- a/README +++ b/README @@ -21,7 +21,7 @@ OpenShift Express provides several environment variables to reference for ease of use. The following list are some common variables but far from exhaustive: os.environ['OPENSHIFT_APP_NAME'] - Application name - os.environ['OPENSHIFT_APP_DIR'] - Application dir + os.environ['OPENSHIFT_GEAR_DIR'] - Application dir os.environ['OPENSHIFT_DATA_DIR'] - For persistent storage (between pushes) os.environ['OPENSHIFT_TMP_DIR'] - Temp storage (unmodified files deleted after 10 days) From eefc5114c51e4857ea487d9b785f9cf83dc3e4b4 Mon Sep 17 00:00:00 2001 From: Grant Shipley Date: Mon, 2 Apr 2012 13:19:21 -0300 Subject: [PATCH 13/38] Update README --- README | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README b/README index df1ff25..6510c1f 100644 --- a/README +++ b/README @@ -17,7 +17,7 @@ setup.py - Standard setup.py, specify deps here Environment Variables ===================== -OpenShift Express provides several environment variables to reference for ease +OpenShift provides several environment variables to reference for ease of use. The following list are some common variables but far from exhaustive: os.environ['OPENSHIFT_APP_NAME'] - Application name From b39ff343b13c2cab0b67006d8a8a7f3287b120c6 Mon Sep 17 00:00:00 2001 From: Grant Shipley Date: Mon, 2 Apr 2012 13:19:55 -0300 Subject: [PATCH 14/38] Update README.md --- README.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 4c88193..f4c08d5 100644 --- a/README.md +++ b/README.md @@ -1,8 +1,8 @@ -Django on OpenShift Express -============================ +Django on OpenShift +=================== This git repository helps you get up and running quickly w/ a Django installation -on OpenShift Express. The Django project name used in this repo is 'openshift' +on OpenShift. The Django project name used in this repo is 'openshift' but you can feel free to change it. Right now the backend is sqlite3 and the database runtime is @ $OPENSHIFT_DATA_DIR/sqlite3.db. From acbf797a7876a6c49160fe29c762979609ac2bae Mon Sep 17 00:00:00 2001 From: Dan McPherson Date: Mon, 9 Apr 2012 08:53:44 +0800 Subject: [PATCH 15/38] fix copied section --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index f4c08d5..9ab728d 100644 --- a/README.md +++ b/README.md @@ -28,7 +28,7 @@ Create a python-2.6 application rhc app create -a django -t python-2.6 -Add this upstream seambooking repo +Add this upstream repo cd django git remote add upstream -m master git://github.com/openshift/django-example.git From ed8782532011a6a741e0b2e0115f00069c672eec Mon Sep 17 00:00:00 2001 From: Pengfei Xue Date: Fri, 8 Jun 2012 00:17:47 +0800 Subject: [PATCH 16/38] move scripts to this file since the env has changed adding / at the end of the vars, the script should be updated as well --- .openshift/action_hooks/deploy | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/.openshift/action_hooks/deploy b/.openshift/action_hooks/deploy index ed5eb99..a108305 100755 --- a/.openshift/action_hooks/deploy +++ b/.openshift/action_hooks/deploy @@ -2,4 +2,18 @@ # This deploy hook gets executed after dependencies are resolved and the # build hook has been run but before the application has been started back # up again. This script gets executed directly, so it could be python, php, -# ruby, etc. \ No newline at end of file +# ruby, etc. + +source $OPENSHIFT_GEAR_DIR/virtenv/bin/activate + +if [ ! -f $OPENSHIFT_DATA_DIR/sqlite3.db ] +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 +else + echo "Executing 'python $OPENSHIFT_REPO_DIR/wsgi/openshift/manage.py syncdb --noinput'" + python "$OPENSHIFT_REPO_DIR"wsgi/openshift/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 \ No newline at end of file From 8ee93f288e6ce85cf83e83edea13f77c3775b7f4 Mon Sep 17 00:00:00 2001 From: Pengfei Xue Date: Fri, 8 Jun 2012 00:19:40 +0800 Subject: [PATCH 17/38] the file shouldn't be here, move it to action_hook/deploy --- .openshift/action_hooks/build | 13 ------------- 1 file changed, 13 deletions(-) diff --git a/.openshift/action_hooks/build b/.openshift/action_hooks/build index e9cf9e0..9aec2e8 100755 --- a/.openshift/action_hooks/build +++ b/.openshift/action_hooks/build @@ -5,16 +5,3 @@ # could be python, php, ruby, etc. # Activate VirtualEnv in order to use the correct libraries -source $OPENSHIFT_GEAR_DIR/virtenv/bin/activate - -if [ ! -f $OPENSHIFT_DATA_DIR/sqlite3.db ] -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/ -else - echo "Executing 'python $OPENSHIFT_REPO_DIR/wsgi/openshift/manage.py syncdb --noinput'" - python $OPENSHIFT_REPO_DIR/wsgi/openshift/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 From db416a6a0415428e36e655ffe3aa56bfab3a0972 Mon Sep 17 00:00:00 2001 From: Grant Shipley Date: Tue, 12 Jun 2012 14:27:00 -0300 Subject: [PATCH 18/38] Update master --- README.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/README.md b/README.md index 9ab728d..dea2381 100644 --- a/README.md +++ b/README.md @@ -24,6 +24,9 @@ Running on OpenShift Create an account at http://openshift.redhat.com/ +Install the RHC client tools if you have not already done so: + sudo gem install rhc + Create a python-2.6 application rhc app create -a django -t python-2.6 From 76277a7fcba4b40a74086ddd583c4594738f22d5 Mon Sep 17 00:00:00 2001 From: Grant Shipley Date: Tue, 12 Jun 2012 14:27:15 -0300 Subject: [PATCH 19/38] Update master --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index dea2381..0b576e1 100644 --- a/README.md +++ b/README.md @@ -25,6 +25,7 @@ Running on OpenShift Create an account at http://openshift.redhat.com/ Install the RHC client tools if you have not already done so: + sudo gem install rhc Create a python-2.6 application From 2b49faba38b8ceb8abe639b5f7ec022a59f47ce0 Mon Sep 17 00:00:00 2001 From: "N. Harrison Ripps" Date: Mon, 23 Jul 2012 11:05:13 -0400 Subject: [PATCH 20/38] Added changes to templatize the quick start. --- README.md | 42 ++++++++++------- wsgi/openshift/openshiftlibs.py | 81 +++++++++++++++++++++++++++++++++ wsgi/openshift/settings.py | 14 +++++- 3 files changed, 119 insertions(+), 18 deletions(-) create mode 100644 wsgi/openshift/openshiftlibs.py diff --git a/README.md b/README.md index 0b576e1..520385e 100644 --- a/README.md +++ b/README.md @@ -1,26 +1,31 @@ + 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 backend is sqlite3 and the -database runtime is @ $OPENSHIFT_DATA_DIR/sqlite3.db. +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 +backend is sqlite3 and the database runtime is @ +$OPENSHIFT_DATA_DIR/sqlite3.db. -When you push this application up for the first time, the sqlite database is -copied from wsgi/openshift/sqlite3.db. This is the stock database that is created -when 'python manage.py syncdb' is run with only the admin app installed. +Before you push this app for the first time, you will need to change +the Django admin password (see below). 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 +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. -You can delete the database from your git repo after the first push (you probably -should for security). On subsequent pushes, a 'python manage.py syncdb' is -executed to make sure that any models you added are created in the DB. If you -do anything that requires an alter table, you could add the alter statements -in GIT_ROOT/.openshift/action_hooks/alter.sql and then use -GIT_ROOT/.openshift/action_hooks/deploy to execute that script (make sure to -back up your database w/ 'rhc app snapshot save' first :) ) +On subsequent pushes, a 'python manage.py syncdb' is executed to make +sure that any models you added are created in the DB. If you do +anything that requires an alter table, you could add the alter +statements in GIT_ROOT/.openshift/action_hooks/alter.sql and then use +GIT_ROOT/.openshift/action_hooks/deploy to execute that script (make +sure to back up your database w/ 'rhc app snapshot save' first :) ) Running on OpenShift ----------------------------- +-------------------- Create an account at http://openshift.redhat.com/ @@ -37,12 +42,17 @@ Add this upstream repo cd django git remote add upstream -m master git://github.com/openshift/django-example.git git pull -s recursive -X theirs upstream master + +Set your Django admin password + + cd wsgi/openshift + ./manage.py changepassword admin Then push the repo upstream + cd ../../ git push That's it, you can now checkout your application at (default admin account is admin/admin): http://django-$yournamespace.rhcloud.com - diff --git a/wsgi/openshift/openshiftlibs.py b/wsgi/openshift/openshiftlibs.py new file mode 100644 index 0000000..a11e0e5 --- /dev/null +++ b/wsgi/openshift/openshiftlibs.py @@ -0,0 +1,81 @@ +#!/usr/bin/env python +import hashlib, inspect, os, random, sys + +# Gets the secret token provided by OpenShift +# or generates one (this is slightly less secure, but good enough for now) +def get_openshift_secret_token(): + token = os.getenv('OPENSHIFT_SECRET_TOKEN') + name = os.getenv('OPENSHIFT_APP_NAME') + uuid = os.getenv('OPENSHIFT_APP_UUID') + if token is not None: + return token + elif (name is not None and uuid is not None): + return hashlib.sha256(name + '-' + uuid).hexdigest() + return None + +# Loop through all provided variables and generate secure versions +# If not running on OpenShift, returns defaults and logs an error message +# +# This function calls secure_function and passes an array of: +# { +# 'hash': generated sha hash, +# 'variable': name of variable, +# 'original': original value +# } +def openshift_secure(default_keys, secure_function = 'make_secure_key'): + # Attempts to get secret token + my_token = get_openshift_secret_token() + + # Only generate random values if on OpenShift + my_list = default_keys + + if my_token is not None: + # Loop over each default_key and set the new value + for key, value in default_keys.iteritems(): + # Create hash out of token and this key's name + sha = hashlib.sha256(my_token + '-' + key).hexdigest() + # Pass a dictionary so we can add stuff without breaking existing calls + vals = { 'hash': sha, 'variable': key, 'original': value } + # Call user specified function or just return hash + my_list[key] = sha + if secure_function is not None: + # Pick through the global and local scopes to find the function. + possibles = globals().copy() + possibles.update(locals()) + supplied_function = possibles.get(secure_function) + if not supplied_function: + raise Exception("Cannot find supplied security function") + else: + my_list[key] = supplied_function(vals) + else: + calling_file = inspect.stack()[1][1] + if os.getenv('OPENSHIFT_REPO_DIR'): + base = os.getenv('OPENSHIFT_REPO_DIR') + calling_file.replace(base,'') + sys.stderr.write("OPENSHIFT WARNING: Using default values for secure variables, please manually modify in " + calling_file + "\n") + + return my_list + + +# 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'] + + chars = '0123456789abcdef' + + # 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 diff --git a/wsgi/openshift/settings.py b/wsgi/openshift/settings.py index 842669e..2f44079 100644 --- a/wsgi/openshift/settings.py +++ b/wsgi/openshift/settings.py @@ -1,6 +1,6 @@ # -*- coding: utf-8 -*- # Django settings for openshift project. -import os +import imp, os # a setting to determine whether we are running on OpenShift ON_OPENSHIFT = False @@ -104,8 +104,18 @@ #'django.contrib.staticfiles.finders.DefaultStorageFinder', ) +# Make a dictionary of default keys +default_keys = { 'SECRET_KEY': 'vm4rl5*ymb@2&d_(gc$gb-^twq9w(u69hi--%$5xrh!xk(t%hw' } + +# Replace default keys with dynamic values if we are in OpenShift +use_keys = default_keys +if ON_OPENSHIFT: + imp.find_module('openshiftlibs') + import openshiftlibs + use_keys = openshiftlibs.openshift_secure(default_keys) + # Make this unique, and don't share it with anybody. -SECRET_KEY = 'vm4rl5*ymb@2&d_(gc$gb-^twq9w(u69hi--%$5xrh!xk(t%hw' +SECRET_KEY = use_keys['SECRET_KEY'] # List of callables that know how to import templates from various sources. TEMPLATE_LOADERS = ( From 520c56c490e94c6a9b66b8e2c5cf4320e88d19cc Mon Sep 17 00:00:00 2001 From: "N. Harrison Ripps" Date: Mon, 23 Jul 2012 11:13:42 -0400 Subject: [PATCH 21/38] Added templatizing info and patch file to package --- .openshift/README.md | 25 +++++++ .openshift/template.patch | 133 ++++++++++++++++++++++++++++++++++++++ README.md | 2 +- 3 files changed, 159 insertions(+), 1 deletion(-) create mode 100644 .openshift/README.md create mode 100644 .openshift/template.patch diff --git a/.openshift/README.md b/.openshift/README.md new file mode 100644 index 0000000..6265e00 --- /dev/null +++ b/.openshift/README.md @@ -0,0 +1,25 @@ +# Django Template for OpenShift + +## Template App Information +Product: Django +Version: 1.4 +Source: https://github.com/django/django.git +Commit: 2591fb8d4c0246f68b79554976c012039df75359 + +## Maintenance +This folder contains a diff file that includes the changes made to the +stock Django app in order to make it OpenShift-Template-ready. If +you are a maintainer tasked with updating the Django template, you +may be able to use this patch file on the updated Django code to +automatically reapply these changes. + +Here are the steps involved: + +1. Under the 'wsgi' directory, apply any patches required to update the 'openshift' Django app. +2. From the template root directory, run 'git apply --check .openshift/template.patch' to test for patching problems. +3. Next run 'git am --signoff < .openshift/template.patch' to apply the patch to the template. + +If this process succeeds, then the changes have been automatically +applied. Otherwise it may be necessary to manually apply the +changes. If the base package has changed enough, you may need to +re-audit the base code and generate a new patch file. diff --git a/.openshift/template.patch b/.openshift/template.patch new file mode 100644 index 0000000..1f22aca --- /dev/null +++ b/.openshift/template.patch @@ -0,0 +1,133 @@ +From 2b49faba38b8ceb8abe639b5f7ec022a59f47ce0 Mon Sep 17 00:00:00 2001 +From: "N. Harrison Ripps" +Date: Mon, 23 Jul 2012 11:05:13 -0400 +Subject: [PATCH] Added changes to templatize the quick start. + +--- + wsgi/openshift/openshiftlibs.py | 81 +++++++++++++++++++++++++++++++++++++++ + wsgi/openshift/settings.py | 14 ++++++- + 2 files changed, 93 insertions(+), 2 deletions(-) + create mode 100644 wsgi/openshift/openshiftlibs.py + +diff --git a/wsgi/openshift/openshiftlibs.py b/wsgi/openshift/openshiftlibs.py +new file mode 100644 +index 0000000..a11e0e5 +--- /dev/null ++++ b/wsgi/openshift/openshiftlibs.py +@@ -0,0 +1,81 @@ ++#!/usr/bin/env python ++import hashlib, inspect, os, random, sys ++ ++# Gets the secret token provided by OpenShift ++# or generates one (this is slightly less secure, but good enough for now) ++def get_openshift_secret_token(): ++ token = os.getenv('OPENSHIFT_SECRET_TOKEN') ++ name = os.getenv('OPENSHIFT_APP_NAME') ++ uuid = os.getenv('OPENSHIFT_APP_UUID') ++ if token is not None: ++ return token ++ elif (name is not None and uuid is not None): ++ return hashlib.sha256(name + '-' + uuid).hexdigest() ++ return None ++ ++# Loop through all provided variables and generate secure versions ++# If not running on OpenShift, returns defaults and logs an error message ++# ++# This function calls secure_function and passes an array of: ++# { ++# 'hash': generated sha hash, ++# 'variable': name of variable, ++# 'original': original value ++# } ++def openshift_secure(default_keys, secure_function = 'make_secure_key'): ++ # Attempts to get secret token ++ my_token = get_openshift_secret_token() ++ ++ # Only generate random values if on OpenShift ++ my_list = default_keys ++ ++ if my_token is not None: ++ # Loop over each default_key and set the new value ++ for key, value in default_keys.iteritems(): ++ # Create hash out of token and this key's name ++ sha = hashlib.sha256(my_token + '-' + key).hexdigest() ++ # Pass a dictionary so we can add stuff without breaking existing calls ++ vals = { 'hash': sha, 'variable': key, 'original': value } ++ # Call user specified function or just return hash ++ my_list[key] = sha ++ if secure_function is not None: ++ # Pick through the global and local scopes to find the function. ++ possibles = globals().copy() ++ possibles.update(locals()) ++ supplied_function = possibles.get(secure_function) ++ if not supplied_function: ++ raise Exception("Cannot find supplied security function") ++ else: ++ my_list[key] = supplied_function(vals) ++ else: ++ calling_file = inspect.stack()[1][1] ++ if os.getenv('OPENSHIFT_REPO_DIR'): ++ base = os.getenv('OPENSHIFT_REPO_DIR') ++ calling_file.replace(base,'') ++ sys.stderr.write("OPENSHIFT WARNING: Using default values for secure variables, please manually modify in " + calling_file + "\n") ++ ++ return my_list ++ ++ ++# 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'] ++ ++ chars = '0123456789abcdef' ++ ++ # 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 +diff --git a/wsgi/openshift/settings.py b/wsgi/openshift/settings.py +index 842669e..2f44079 100644 +--- a/wsgi/openshift/settings.py ++++ b/wsgi/openshift/settings.py +@@ -1,6 +1,6 @@ + # -*- coding: utf-8 -*- + # Django settings for openshift project. +-import os ++import imp, os + + # a setting to determine whether we are running on OpenShift + ON_OPENSHIFT = False +@@ -104,8 +104,18 @@ STATICFILES_FINDERS = ( + #'django.contrib.staticfiles.finders.DefaultStorageFinder', + ) + ++# Make a dictionary of default keys ++default_keys = { 'SECRET_KEY': 'vm4rl5*ymb@2&d_(gc$gb-^twq9w(u69hi--%$5xrh!xk(t%hw' } ++ ++# Replace default keys with dynamic values if we are in OpenShift ++use_keys = default_keys ++if ON_OPENSHIFT: ++ imp.find_module('openshiftlibs') ++ import openshiftlibs ++ use_keys = openshiftlibs.openshift_secure(default_keys) ++ + # Make this unique, and don't share it with anybody. +-SECRET_KEY = 'vm4rl5*ymb@2&d_(gc$gb-^twq9w(u69hi--%$5xrh!xk(t%hw' ++SECRET_KEY = use_keys['SECRET_KEY'] + + # List of callables that know how to import templates from various sources. + TEMPLATE_LOADERS = ( +-- +1.7.5.4 + diff --git a/README.md b/README.md index 520385e..b97bdb9 100644 --- a/README.md +++ b/README.md @@ -43,7 +43,7 @@ Add this upstream repo git remote add upstream -m master git://github.com/openshift/django-example.git git pull -s recursive -X theirs upstream master -Set your Django admin password +Set your Django admin password. (Django must be installed on your dev system for this to work; 'sudo yum install Django' will do this for Fedora and RHEL) cd wsgi/openshift ./manage.py changepassword admin From 8fb2624a894e9ab3e637f403b59db795253ce60c Mon Sep 17 00:00:00 2001 From: "N. Harrison Ripps" Date: Wed, 25 Jul 2012 11:50:46 -0400 Subject: [PATCH 22/38] Added password generation routine to default DB --- .openshift/action_hooks/deploy | 3 +- .openshift/action_hooks/secure_db.py | 42 ++++++++++++++++++++++++++++ wsgi/openshift/openshiftlibs.py | 11 +++++--- 3 files changed, 51 insertions(+), 5 deletions(-) create mode 100755 .openshift/action_hooks/secure_db.py diff --git a/.openshift/action_hooks/deploy b/.openshift/action_hooks/deploy index a108305..5dfad20 100755 --- a/.openshift/action_hooks/deploy +++ b/.openshift/action_hooks/deploy @@ -10,10 +10,11 @@ if [ ! -f $OPENSHIFT_DATA_DIR/sqlite3.db ] 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 + python "$OPENSHIFT_REPO_DIR".openshift/action_hooks/secure_db.py else echo "Executing 'python $OPENSHIFT_REPO_DIR/wsgi/openshift/manage.py syncdb --noinput'" python "$OPENSHIFT_REPO_DIR"wsgi/openshift/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 \ No newline at end of file +python "$OPENSHIFT_REPO_DIR"wsgi/openshift/manage.py collectstatic --noinput diff --git a/.openshift/action_hooks/secure_db.py b/.openshift/action_hooks/secure_db.py new file mode 100755 index 0000000..faee8b4 --- /dev/null +++ b/.openshift/action_hooks/secure_db.py @@ -0,0 +1,42 @@ +#!/usr/bin/env python +import hashlib, imp, os, sqlite3 + +# Load the openshift helper library +lib_path = os.environ['OPENSHIFT_REPO_DIR'] + 'wsgi/openshift/' +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') +c = conn.cursor() + +# Grab the default security info +c.execute('SELECT password FROM AUTH_USER WHERE id = 1') +pw_info = c.fetchone()[0] + +# The password is stored as [hashtype]$[salt]$[hashed] +pw_fields = pw_info.split("$") +hashtype = pw_fields[0] +old_salt = pw_fields[1] +old_pass = pw_fields[2] + +# Randomly generate a new password and a new salt +# The PASSWORD value below just sets the length (12) +# for the real new password. +old_keys = { 'SALT': old_salt, 'PASS': '123456789ABC' } +use_keys = openshiftlibs.openshift_secure(old_keys) + +# Encrypt the new password +new_salt = use_keys['SALT'] +new_pass = use_keys['PASS'] +new_hashed = hashlib.sha1(new_salt + new_pass).hexdigest() +new_pw_info = "$".join([hashtype,new_salt,new_hashed]) + +# Update the database +c.execute('UPDATE AUTH_USER SET password = ? WHERE id = 1', [new_pw_info]) +conn.commit() +c.close() +conn.close() + +# Print the new password info +print "CLIENT_MESSAGE: The password for user 'admin' in your Django app is " + new_pass + " ...be sure to write this down as you will not see this message again.\n" diff --git a/wsgi/openshift/openshiftlibs.py b/wsgi/openshift/openshiftlibs.py index a11e0e5..b0e53a6 100644 --- a/wsgi/openshift/openshiftlibs.py +++ b/wsgi/openshift/openshiftlibs.py @@ -1,7 +1,7 @@ #!/usr/bin/env python import hashlib, inspect, os, random, sys -# Gets the secret token provided by OpenShift +# Gets the secret token provided by OpenShift # or generates one (this is slightly less secure, but good enough for now) def get_openshift_secret_token(): token = os.getenv('OPENSHIFT_SECRET_TOKEN') @@ -28,7 +28,7 @@ def openshift_secure(default_keys, secure_function = 'make_secure_key'): # Only generate random values if on OpenShift my_list = default_keys - + if my_token is not None: # Loop over each default_key and set the new value for key, value in default_keys.iteritems(): @@ -62,8 +62,11 @@ def make_secure_key(key_info): hashcode = key_info['hash'] key = key_info['variable'] original = key_info['original'] - - chars = '0123456789abcdef' + + chars = '0123456789' + chars += 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ' + chars += '!@#%^&*()' + chars += '-_ []{}<>~`+=,.;:/?|' # Use the hash to seed the RNG random.seed(int("0x" + hashcode[:8], 0)) From f5d88696a36aabc5449b8066f7c073857825db02 Mon Sep 17 00:00:00 2001 From: "N. Harrison Ripps" Date: Thu, 26 Jul 2012 10:16:37 -0400 Subject: [PATCH 23/38] Updated README.md to add a note about the generated admin password. --- README.md | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index b97bdb9..97e5917 100644 --- a/README.md +++ b/README.md @@ -43,15 +43,15 @@ Add this upstream repo git remote add upstream -m master git://github.com/openshift/django-example.git git pull -s recursive -X theirs upstream master -Set your Django admin password. (Django must be installed on your dev system for this to work; 'sudo yum install Django' will do this for Fedora and RHEL) - - cd wsgi/openshift - ./manage.py changepassword admin - Then push the repo upstream - cd ../../ git push + +**Note**: As the git push output scrolls by, keep an eye out for a + line of output that starts with 'CLIENT_MESSAGE: '. This line + contains the generated admin password that you will need to begin + administering your Django app. This is the only time the password + will be displayed, so be sure to save it somewhere! That's it, you can now checkout your application at (default admin account is admin/admin): From 457d2d22de244da7d87ce6fa164423d4bbddb83b Mon Sep 17 00:00:00 2001 From: "N. Harrison Ripps" Date: Tue, 31 Jul 2012 11:18:25 -0400 Subject: [PATCH 24/38] Fixed random password generator --- wsgi/openshift/openshiftlibs.py | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/wsgi/openshift/openshiftlibs.py b/wsgi/openshift/openshiftlibs.py index b0e53a6..8e25320 100644 --- a/wsgi/openshift/openshiftlibs.py +++ b/wsgi/openshift/openshiftlibs.py @@ -63,10 +63,12 @@ def make_secure_key(key_info): key = key_info['variable'] original = key_info['original'] - chars = '0123456789' - chars += 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ' - chars += '!@#%^&*()' - chars += '-_ []{}<>~`+=,.;:/?|' + # 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)) From 9158fd3ee0f9d663a2c4c6db9a49bf55da909a93 Mon Sep 17 00:00:00 2001 From: "N. Harrison Ripps" Date: Tue, 31 Jul 2012 11:24:38 -0400 Subject: [PATCH 25/38] Fixed python spacing --- wsgi/openshift/openshiftlibs.py | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/wsgi/openshift/openshiftlibs.py b/wsgi/openshift/openshiftlibs.py index 8e25320..a75be18 100644 --- a/wsgi/openshift/openshiftlibs.py +++ b/wsgi/openshift/openshiftlibs.py @@ -63,17 +63,17 @@ def make_secure_key(key_info): 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' + # 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 + # Create a random string the same length as the default rand_key = '' for _ in range(len(original)): rand_pos = random.randint(0,len(chars)) From 9427e13611e9a534732a538349284d718d724148 Mon Sep 17 00:00:00 2001 From: Mrunal Patel Date: Thu, 4 Oct 2012 16:37:20 -0700 Subject: [PATCH 26/38] Typeless changes. --- .openshift/action_hooks/deploy | 3 ++- README | 11 ++++++----- wsgi/openshift/settings.py | 2 +- 3 files changed, 9 insertions(+), 7 deletions(-) diff --git a/.openshift/action_hooks/deploy b/.openshift/action_hooks/deploy index 5dfad20..b1bdce2 100755 --- a/.openshift/action_hooks/deploy +++ b/.openshift/action_hooks/deploy @@ -4,7 +4,8 @@ # up again. This script gets executed directly, so it could be python, php, # ruby, etc. -source $OPENSHIFT_GEAR_DIR/virtenv/bin/activate +cartridge_type="python-2.6" +source $OPENSHIFT_HOMEDIR/$cartridge_type/virtenv/bin/activate if [ ! -f $OPENSHIFT_DATA_DIR/sqlite3.db ] then diff --git a/README b/README index 6510c1f..f763745 100644 --- a/README +++ b/README @@ -21,17 +21,18 @@ OpenShift provides several environment variables to reference for ease of use. The following list are some common variables but far from exhaustive: os.environ['OPENSHIFT_APP_NAME'] - Application name - os.environ['OPENSHIFT_GEAR_DIR'] - Application dir os.environ['OPENSHIFT_DATA_DIR'] - For persistent storage (between pushes) os.environ['OPENSHIFT_TMP_DIR'] - Temp storage (unmodified files deleted after 10 days) When embedding a database using 'rhc app cartridge add', you can reference environment variables for username, host and password: - os.environ['OPENSHIFT_DB_HOST'] - DB host - os.environ['OPENSHIFT_DB_PORT'] - DB Port - os.environ['OPENSHIFT_DB_USERNAME'] - DB Username - os.environ['OPENSHIFT_DB_PASSWORD'] - DB Password +If you embed MySQL, then: + + os.environ['OPENSHIFT_MYSQL_DB_HOST'] - DB host + os.environ['OPENSHIFT_MYSQL_DB_PORT'] - DB Port + os.environ['OPENSHIFT_MYSQL_DB_USERNAME'] - DB Username + os.environ['OPENSHIFT_MYSQL_DB_PASSWORD'] - DB Password To get a full list of environment variables, simply add a line in your .openshift/action_hooks/build script that says "export" and push. diff --git a/wsgi/openshift/settings.py b/wsgi/openshift/settings.py index 2f44079..99be6c0 100644 --- a/wsgi/openshift/settings.py +++ b/wsgi/openshift/settings.py @@ -18,7 +18,7 @@ MANAGERS = ADMINS if ON_OPENSHIFT: - # os.environ['OPENSHIFT_DB_*'] variables can be used with databases created + # os.environ['OPENSHIFT_MYSQL_DB_*'] variables can be used with databases created # with rhc app cartridge add (see /README in this git repo) DATABASES = { 'default': { From 1df8d36b8ed01e37202b14ee51d61022fb028ec9 Mon Sep 17 00:00:00 2001 From: Steven Citron-Pousty Date: Fri, 14 Dec 2012 17:49:41 -0800 Subject: [PATCH 27/38] Fixed admin password instructions --- README.md | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 97e5917..fefe7c8 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,3 @@ - Django on OpenShift =================== @@ -51,8 +50,10 @@ Then push the repo upstream line of output that starts with 'CLIENT_MESSAGE: '. This line contains the generated admin password that you will need to begin administering your Django app. This is the only time the password - will be displayed, so be sure to save it somewhere! + will be displayed, so be sure to save it somewhere! You might want + to pipe the output of the git push to a text file so you can grep for + the password later. -That's it, you can now checkout your application at (default admin account is admin/admin): +That's it, you can now checkout your application at: http://django-$yournamespace.rhcloud.com From d00be4d951e0d6e60855cb6bd57fb75fa5ee063a Mon Sep 17 00:00:00 2001 From: Hiro Asari Date: Fri, 25 Jan 2013 09:21:32 -0500 Subject: [PATCH 28/38] Update "rhc cartridge" usage --- README | 2 +- wsgi/openshift/settings.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/README b/README index f763745..d07b890 100644 --- a/README +++ b/README @@ -24,7 +24,7 @@ of use. The following list are some common variables but far from exhaustive: os.environ['OPENSHIFT_DATA_DIR'] - For persistent storage (between pushes) os.environ['OPENSHIFT_TMP_DIR'] - Temp storage (unmodified files deleted after 10 days) -When embedding a database using 'rhc app cartridge add', you can reference environment +When embedding a database using 'rhc cartridge add', you can reference environment variables for username, host and password: If you embed MySQL, then: diff --git a/wsgi/openshift/settings.py b/wsgi/openshift/settings.py index 99be6c0..51cfad3 100644 --- a/wsgi/openshift/settings.py +++ b/wsgi/openshift/settings.py @@ -19,7 +19,7 @@ if ON_OPENSHIFT: # os.environ['OPENSHIFT_MYSQL_DB_*'] variables can be used with databases created - # with rhc app cartridge add (see /README in this git repo) + # with rhc cartridge add (see /README in this git repo) DATABASES = { 'default': { 'ENGINE': 'django.db.backends.sqlite3', # Add 'postgresql_psycopg2', 'postgresql', 'mysql', 'sqlite3' or 'oracle'. From 7382ca82b65b179219cea5f34cc4fa1eb4bece43 Mon Sep 17 00:00:00 2001 From: Hiro Asari Date: Mon, 28 Jan 2013 16:18:00 -0500 Subject: [PATCH 29/38] Have admin credential information stand out --- README.md | 43 +++++++++++++++++++++++++------------------ 1 file changed, 25 insertions(+), 18 deletions(-) diff --git a/README.md b/README.md index fefe7c8..531067d 100644 --- a/README.md +++ b/README.md @@ -4,23 +4,24 @@ 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 -backend is sqlite3 and the database runtime is @ -$OPENSHIFT_DATA_DIR/sqlite3.db. +backend is sqlite3 and the database runtime is found in +`$OPENSHIFT_DATA_DIR/sqlite3.db`. Before you push this app for the first time, you will need to change -the Django admin password (see below). Then, when you first push this +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/openshift/sqlite3.db` 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 +database that is created when `python manage.py syncdb` is run with only the admin app installed. -On subsequent pushes, a 'python manage.py syncdb' is executed to make +On subsequent pushes, a `python manage.py syncdb` is executed to make sure that any models you added are created in the DB. If you do anything that requires an alter table, you could add the alter -statements in GIT_ROOT/.openshift/action_hooks/alter.sql and then use -GIT_ROOT/.openshift/action_hooks/deploy to execute that script (make -sure to back up your database w/ 'rhc app snapshot save' first :) ) +statements in `GIT_ROOT/.openshift/action_hooks/alter.sql` and then use +`GIT_ROOT/.openshift/action_hooks/deploy` to execute that script (make +sure to back up your database w/ `rhc app snapshot save` first :) ) Running on OpenShift @@ -45,15 +46,21 @@ Add this upstream repo Then push the repo upstream git push - -**Note**: As the git push output scrolls by, keep an eye out for a - line of output that starts with 'CLIENT_MESSAGE: '. This line - contains the generated admin password that you will need to begin - administering your Django app. This is the only time the password - will be displayed, so be sure to save it somewhere! You might want - to pipe the output of the git push to a text file so you can grep for - the password later. -That's it, you can now checkout your application at: +Here, the [admin user name and password will be displayed](#admin-user-name-and-password), so pay +special attention. + +That's it. You can now checkout your application at: http://django-$yournamespace.rhcloud.com + +Admin user name and password +---------------------------- +As the `git push` output scrolls by, keep an eye out for a +line of output that starts with `CLIENT_MESSAGE: `. This line +contains the generated admin password that you will need to begin +administering your Django app. This is the only time the password +will be displayed, so be sure to save it somewhere. You might want +to pipe the output of the git push to a text file so you can grep for +the password later. + From 48f245404912b99dfcd49b68d90731cac2f2464b Mon Sep 17 00:00:00 2001 From: Hiro Asari Date: Tue, 5 Feb 2013 16:36:38 -0500 Subject: [PATCH 30/38] Bug 884934 Currently, there is no way for the Origin server to communicate with (specifically, receive information from) a quickstart application to display whatever user credentials that the application sets up. In the long term, we need to create a means to achieve it, but until then, we write to a well-known location so that console's controllers can alert the user to this fact. --- .openshift/action_hooks/deploy | 2 +- .openshift/action_hooks/secure_db.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.openshift/action_hooks/deploy b/.openshift/action_hooks/deploy index b1bdce2..6cfac8f 100755 --- a/.openshift/action_hooks/deploy +++ b/.openshift/action_hooks/deploy @@ -11,7 +11,7 @@ if [ ! -f $OPENSHIFT_DATA_DIR/sqlite3.db ] 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 - python "$OPENSHIFT_REPO_DIR".openshift/action_hooks/secure_db.py + 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 diff --git a/.openshift/action_hooks/secure_db.py b/.openshift/action_hooks/secure_db.py index faee8b4..5d36b94 100755 --- a/.openshift/action_hooks/secure_db.py +++ b/.openshift/action_hooks/secure_db.py @@ -39,4 +39,4 @@ conn.close() # Print the new password info -print "CLIENT_MESSAGE: The password for user 'admin' in your Django app is " + new_pass + " ...be sure to write this down as you will not see this message again.\n" +print "Django application credentials:\n\tuser: admin\n\t" + new_pass From 3585acc713fe32341220b7139cb57a9d1f033ee9 Mon Sep 17 00:00:00 2001 From: Glen Baker Date: Sat, 13 Apr 2013 15:32:32 -0700 Subject: [PATCH 31/38] Update settings.py Added check to set DEBUG to False on Openshift production environment and DEBUG to True for development environment --- wsgi/openshift/settings.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/wsgi/openshift/settings.py b/wsgi/openshift/settings.py index 51cfad3..8c48dd6 100644 --- a/wsgi/openshift/settings.py +++ b/wsgi/openshift/settings.py @@ -8,8 +8,10 @@ ON_OPENSHIFT = True PROJECT_DIR = os.path.dirname(os.path.realpath(__file__)) - -DEBUG = True +if ON_OPENSHIFT: + DEBUG = False +else: + DEBUG = True TEMPLATE_DEBUG = DEBUG ADMINS = ( From 82a2e477bb82658a42d7ba188c9cd098abcea394 Mon Sep 17 00:00:00 2001 From: Glen Baker Date: Sat, 13 Apr 2013 18:17:44 -0700 Subject: [PATCH 32/38] Fixed Django requirement causing Server Error 500 The previous install requirement 'Django>=1.3' was installing Django 1.5.1, which resulted in an internal server error 500. I adjusted to 'Django<=1.4', 1.4 was the most recent version I found immediately compatible when testing. --- setup.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup.py b/setup.py index ae205f3..33accc8 100755 --- a/setup.py +++ b/setup.py @@ -9,5 +9,5 @@ author='Your Name', author_email='example@example.com', url='http://www.python.org/sigs/distutils-sig/', - install_requires=['Django>=1.3'], + install_requires=['Django<=1.4'], ) From ac2e10b11e931ea0c54db73b3687431187e9af20 Mon Sep 17 00:00:00 2001 From: Mrunal Patel Date: Tue, 28 May 2013 10:36:42 -0700 Subject: [PATCH 33/38] Add v2 support. --- .openshift/action_hooks/deploy | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/.openshift/action_hooks/deploy b/.openshift/action_hooks/deploy index 6cfac8f..d121411 100755 --- a/.openshift/action_hooks/deploy +++ b/.openshift/action_hooks/deploy @@ -4,8 +4,11 @@ # up again. This script gets executed directly, so it could be python, php, # ruby, etc. -cartridge_type="python-2.6" -source $OPENSHIFT_HOMEDIR/$cartridge_type/virtenv/bin/activate +if [ -f $OPENSHIFT_HOMEDIR/python-2.6 ]; then + source $OPENSHIFT_HOMEDIR/python-2.6/virtenv/bin/activate +else + source $OPENSHIFT_HOMEDIR/python/virtenv/bin/activate +fi if [ ! -f $OPENSHIFT_DATA_DIR/sqlite3.db ] then From 9b1d8f66a72ed172e17f090f1b6b1bdc7fbc675d Mon Sep 17 00:00:00 2001 From: GetUP Cloud Date: Thu, 30 May 2013 20:46:04 -0300 Subject: [PATCH 34/38] testing dir existence According to bash help: -f FILE True if file exists and is a regular file. It is better to use -e since it can test for symlink too. --- .openshift/action_hooks/deploy | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.openshift/action_hooks/deploy b/.openshift/action_hooks/deploy index d121411..7d2a4c1 100755 --- a/.openshift/action_hooks/deploy +++ b/.openshift/action_hooks/deploy @@ -4,7 +4,7 @@ # up again. This script gets executed directly, so it could be python, php, # ruby, etc. -if [ -f $OPENSHIFT_HOMEDIR/python-2.6 ]; then +if [ -e $OPENSHIFT_HOMEDIR/python-2.6 ]; then source $OPENSHIFT_HOMEDIR/python-2.6/virtenv/bin/activate else source $OPENSHIFT_HOMEDIR/python/virtenv/bin/activate From 00e91d97dd0c00e6f315ecc206da71f28813dd54 Mon Sep 17 00:00:00 2001 From: Hiro Asari Date: Mon, 3 Jun 2013 16:08:52 -0400 Subject: [PATCH 35/38] The prefix for the password is tweaked. --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 531067d..737d2dd 100644 --- a/README.md +++ b/README.md @@ -57,7 +57,7 @@ That's it. You can now checkout your application at: Admin user name and password ---------------------------- As the `git push` output scrolls by, keep an eye out for a -line of output that starts with `CLIENT_MESSAGE: `. This line +line of output that starts with `Django application credentials: `. This line contains the generated admin password that you will need to begin administering your Django app. This is the only time the password will be displayed, so be sure to save it somewhere. You might want From ad7d736e20fa5c1792ec03b229ba8bd5fb61182b Mon Sep 17 00:00:00 2001 From: Fotios Lindiakos Date: Wed, 12 Jun 2013 16:21:47 -0400 Subject: [PATCH 36/38] Remove v1 logic --- .openshift/action_hooks/deploy | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/.openshift/action_hooks/deploy b/.openshift/action_hooks/deploy index 7d2a4c1..cbf4fb1 100755 --- a/.openshift/action_hooks/deploy +++ b/.openshift/action_hooks/deploy @@ -4,11 +4,7 @@ # up again. This script gets executed directly, so it could be python, php, # ruby, etc. -if [ -e $OPENSHIFT_HOMEDIR/python-2.6 ]; then - source $OPENSHIFT_HOMEDIR/python-2.6/virtenv/bin/activate -else - source $OPENSHIFT_HOMEDIR/python/virtenv/bin/activate -fi +source $OPENSHIFT_HOMEDIR/python/virtenv/bin/activate if [ ! -f $OPENSHIFT_DATA_DIR/sqlite3.db ] then From 4c5c627770cf296cd257de35d5234ad39cc08476 Mon Sep 17 00:00:00 2001 From: Michal Fojtik Date: Tue, 19 Nov 2013 13:17:03 +0100 Subject: [PATCH 37/38] Allow to set DEBUG environment variable --- wsgi/openshift/settings.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/wsgi/openshift/settings.py b/wsgi/openshift/settings.py index 8c48dd6..5f80a4e 100644 --- a/wsgi/openshift/settings.py +++ b/wsgi/openshift/settings.py @@ -9,7 +9,7 @@ PROJECT_DIR = os.path.dirname(os.path.realpath(__file__)) if ON_OPENSHIFT: - DEBUG = False + DEBUG = bool(os.environ.get('DEBUG', False)) else: DEBUG = True TEMPLATE_DEBUG = DEBUG From 94453721cc3f30b4f4ac71b129c024c50406117e Mon Sep 17 00:00:00 2001 From: Michal Fojtik Date: Tue, 19 Nov 2013 13:19:19 +0100 Subject: [PATCH 38/38] Updated README.md to mention DEBUG variable --- README.md | 11 +++++++++++ wsgi/openshift/settings.py | 2 ++ 2 files changed, 13 insertions(+) diff --git a/README.md b/README.md index 737d2dd..78af6bc 100644 --- a/README.md +++ b/README.md @@ -23,6 +23,17 @@ statements in `GIT_ROOT/.openshift/action_hooks/alter.sql` and then use `GIT_ROOT/.openshift/action_hooks/deploy` to execute that script (make sure to back up your database w/ `rhc app snapshot save` first :) ) +You can also turn on the DEBUG mode for Django application using the +`rhc env set DEBUG=True --app APP_NAME`. If you do this, you'll get +nicely formatted error pages in browser for HTTP 500 errors. + +Do not forget to turn this environment variable off and fully restart +the application when you finish: + +``` +$ rhc env unset DEBUG +$ rhc app stop && rhc app start +``` Running on OpenShift -------------------- diff --git a/wsgi/openshift/settings.py b/wsgi/openshift/settings.py index 5f80a4e..d4afdc8 100644 --- a/wsgi/openshift/settings.py +++ b/wsgi/openshift/settings.py @@ -10,6 +10,8 @@ PROJECT_DIR = os.path.dirname(os.path.realpath(__file__)) if ON_OPENSHIFT: DEBUG = bool(os.environ.get('DEBUG', False)) + if DEBUG: + print("WARNING: The DEBUG environment is set to True.") else: DEBUG = True TEMPLATE_DEBUG = DEBUG