Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Make it possible to install on OpenShift
Requires Python 2.7 Cartrige with Postgres database
- Loading branch information
Showing
12 changed files
with
208 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
#!/bin/bash | ||
# 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 | ||
echo "Execute 'build' script" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
#!/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. | ||
echo "Execute 'deploy' script" | ||
|
||
MANAGE="python ${OPENSHIFT_REPO_DIR}manage.py" | ||
SYNC_DB="$MANAGE syncdb --migrate --noinput" | ||
COLLECTSTATIC="$MANAGE collectstatic --noinput" | ||
|
||
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/opt/rh/postgresql92/root/usr/lib64/ | ||
|
||
echo "Copying settings_local..." | ||
cp "${OPENSHIFT_REPO_DIR}venelin/settings_openshift.py" "${OPENSHIFT_REPO_DIR}settings_local.py" | ||
|
||
echo "Activate enviroment" | ||
source $OPENSHIFT_HOMEDIR/python/virtenv/bin/activate | ||
|
||
echo "Executing '$SYNC_DB'" | ||
$SYNC_DB | ||
|
||
echo "Executing '$COLLECTSTATIC'" | ||
$COLLECTSTATIC |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
#!/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. | ||
echo "Execute 'post_deploy' script" | ||
|
||
echo "Link static folders" | ||
ln -s ${OPENSHIFT_DATA_DIR}static ${OPENSHIFT_REPO_DIR}wsgi/static |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
#!/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. | ||
echo "Execute 'pre_build' script" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
#!/bin/bash | ||
echo "Execute pre_start_python" | ||
|
||
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/opt/rh/postgresql92/root/usr/lib64/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
#!/usr/bin/env python | ||
import os | ||
|
||
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "venelin.settings") | ||
|
||
from django.core.wsgi import get_wsgi_application | ||
from django.conf import settings | ||
from dj_static import Cling | ||
|
||
IP = os.environ.get('OPENSHIFT_PYTHON_IP', '0.0.0.0') | ||
PORT = int(os.environ.get('OPENSHIFT_PYTHON_PORT', 8080)) | ||
|
||
|
||
class MediaCling(Cling): | ||
""" | ||
This class is copied from https://github.com/kennethreitz/dj-static/ | ||
When this changes came to pypi then this class can be imported from there | ||
""" | ||
def __init__(self, application, base_dir=None): | ||
super(MediaCling, self).__init__(application, base_dir=base_dir) | ||
# override callable attribute with method | ||
self.debug_cling = self._debug_cling | ||
|
||
def _debug_cling(self, environ, start_response): | ||
environ = self._transpose_environ(environ) | ||
return self.cling(environ, start_response) | ||
|
||
def get_base_dir(self): | ||
return settings.MEDIA_ROOT | ||
|
||
def get_base_url(self): | ||
return settings.MEDIA_URL | ||
|
||
|
||
def run_gevent_server(app, ip='0.0.0.0', port=8080): | ||
from gevent.pywsgi import WSGIServer | ||
http_address = '%s:%s' % (ip, port) | ||
print("Start gevent wsgi server at %s" % http_address) | ||
WSGIServer((ip, port), app).serve_forever() | ||
|
||
|
||
def run_simple_wsgi_server(app, ip='0.0.0.0', port=8080): | ||
from wsgiref.simple_server import make_server | ||
http_address = '%s:%s' % (ip, port) | ||
print("Start WSGI server at %s" % http_address) | ||
make_server(ip, port, app).serve_forever() | ||
|
||
|
||
def main(): | ||
application = MediaCling(Cling(get_wsgi_application())) | ||
try: | ||
run_gevent_server(application, IP, PORT) | ||
except ImportError: | ||
run_simple_wsgi_server(application, IP, PORT) | ||
|
||
|
||
if __name__ == '__main__': | ||
try: | ||
main() | ||
except KeyboardInterrupt: | ||
print("\nServer stopped") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
#!/usr/bin/env python | ||
import hashlib, os | ||
|
||
|
||
def get_openshift_secret_token(): | ||
""" | ||
Gets the secret token provided by OpenShift | ||
or generates one (this is slightly less secure, but good enough for now) | ||
""" | ||
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 | ||
|
||
|
||
def openshift_secure(value): | ||
""" | ||
Pass a value and try to secure it with openshift secret token if available | ||
""" | ||
secret_token = get_openshift_secret_token() | ||
|
||
if secret_token: | ||
return hashlib.sha256(secret_token + '-' + value).hexdigest() | ||
return value |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
#!/usr/bin/env python | ||
|
||
from setuptools import setup | ||
|
||
setup( | ||
name='venelins_site', | ||
version='1.0', | ||
description='venelin.sytes.net', | ||
author='Venelin Stoykov', | ||
author_email='vkstoykov@gmail.com', | ||
url='http://venelin.sytes.net/', | ||
install_requires=[ | ||
'Django>=1.5.2', | ||
'Pillow>=2.1.0', | ||
'South>=0.8.2', | ||
'django-extensions>=1.2.0', | ||
'django-tinymce>=1.5.1', | ||
'django-disqus>=0.4.1', | ||
'django-imagekit>=3.0.3', | ||
'django-admin-tools', | ||
'pygments', | ||
'gevent', | ||
'dj-static', | ||
'psycopg2', | ||
], | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import os | ||
from openshiftlibs import openshift_secure | ||
|
||
DATA_DIR = os.environ['OPENSHIFT_DATA_DIR'] | ||
|
||
STATIC_ROOT = os.path.join(DATA_DIR, 'static/') | ||
MEDIA_ROOT = os.path.join(DATA_DIR, 'media/') | ||
|
||
DEBUG = False | ||
TEMPLATE_DEBUG = DEBUG | ||
|
||
ALLOWED_HOSTS = [ | ||
'*', | ||
] | ||
|
||
DATABASES = { | ||
'sqlite': { | ||
'ENGINE': 'django.db.backends.sqlite3', | ||
'NAME': os.path.join(DATA_DIR, 'site.db'), | ||
}, | ||
'postgres': { | ||
'ENGINE': 'django.db.backends.postgresql_psycopg2', | ||
'NAME': os.environ['OPENSHIFT_APP_NAME'], | ||
'USER': os.environ['OPENSHIFT_POSTGRESQL_DB_USERNAME'], | ||
'PASSWORD': os.environ['OPENSHIFT_POSTGRESQL_DB_PASSWORD'], | ||
'HOST': os.environ['OPENSHIFT_POSTGRESQL_DB_HOST'], | ||
'PORT': os.environ['OPENSHIFT_POSTGRESQL_DB_PORT'], | ||
} | ||
} | ||
DATABASES['default'] = DATABASES['postgres'] | ||
|
||
DISQUS_WEBSITE_SHORTNAME = 'venelin' | ||
|
||
SERVER_EMAIL = DEFAULT_FROM_EMAIL = 'webmaster@venelin.sytes.net' | ||
|
||
SECRET_KEY = openshift_secure('qi!k%l+n@hs8l8%)t@j2bl6_jj_x2q-g^em=i!6m17(7x1^$9r') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters