From b5ff0607f24f8f070460f1d94d594f06c8c73ac5 Mon Sep 17 00:00:00 2001 From: Sergio Orbe Date: Sat, 2 Apr 2016 07:01:40 -0300 Subject: [PATCH] settings para deploy en openshift --- .openshift/action_hooks/deploy | 24 ++ eventoL/settings.py | 80 +++---- manager/initial_data/initial_data.json | 45 ---- wsgi.py | 296 +------------------------ wsgi/static/.gitkeep | 0 5 files changed, 66 insertions(+), 379 deletions(-) create mode 100644 .openshift/action_hooks/deploy create mode 100644 wsgi/static/.gitkeep diff --git a/.openshift/action_hooks/deploy b/.openshift/action_hooks/deploy new file mode 100644 index 00000000..c17b67e4 --- /dev/null +++ b/.openshift/action_hooks/deploy @@ -0,0 +1,24 @@ +#!/bin/bash + +source $OPENSHIFT_HOMEDIR/python/virtenv/bin/activate + +echo "Executing 'python $OPENSHIFT_REPO_DIR/manage.py migrate --noinput'" +python "$OPENSHIFT_REPO_DIR"/manage.py migrate --noinput + +echo "Executing 'python $OPENSHIFT_REPO_DIR/manage.py syncdb --noinput'" +python "$OPENSHIFT_REPO_DIR"/manage.py syncdb --noinput + +echo "Executing 'python $OPENSHIFT_REPO_DIR/manage.py collectstatic --noinput'" +python "$OPENSHIFT_REPO_DIR"/manage.py collectstatic --noinput + +echo "Executing 'python $OPENSHIFT_REPO_DIR/manage.py loaddata manager/initial_data/initial_data.json --noinput'" +python "$OPENSHIFT_REPO_DIR"/manage.py loaddata manager/initial_data/initial_data.json --noinput + +echo "Executing 'python $OPENSHIFT_REPO_DIR/manage.py loaddata manager/initial_data/social.json --noinput'" +python "$OPENSHIFT_REPO_DIR"/manage.py loaddata manager/initial_data/social.json --noinput + +echo "Executing 'django-admin makemessages --locale=es'" +django-admin makemessages --locale=es + +echo "Executing 'django-admin compilemessages'" +django-admin compilemessages \ No newline at end of file diff --git a/eventoL/settings.py b/eventoL/settings.py index d1530a05..f040f21f 100644 --- a/eventoL/settings.py +++ b/eventoL/settings.py @@ -7,6 +7,8 @@ For the full list of settings and their values, see https://docs.djangoproject.com/en/1.6/ref/settings/ """ +import socket + import django.conf.global_settings as DEFAULT_SETTINGS from easy_thumbnails.conf import Settings as thumbnail_settings # Build paths inside the project like this: os.path.join(BASE_DIR, ...) @@ -15,22 +17,25 @@ BASE_DIR = os.path.dirname(os.path.dirname(__file__)) -MEDIA_ROOT = os.path.join(BASE_DIR, 'media') +ON_OPENSHIFT = 'OPENSHIFT_REPO_DIR' in os.environ -MEDIA_URL = '/media/' +SECRET_KEY = os.environ.get('OPENSHIFT_SECRET_TOKEN', default='!a44%)(r2!1wp89@ds(tqzpo#f0qgfxomik)a$16v5v@b%)ecu') -# Quick-start development settings - unsuitable for production -# See https://docs.djangoproject.com/en/1.6/howto/deployment/checklist/ +# SECURITY WARNING: don't run with debug turned on in production! +DEBUG = not ON_OPENSHIFT -# SECURITY WARNING: keep the secret key used in production secret! -SECRET_KEY = '!a44%)(r2!1wp89@ds(tqzpo#f0qgfxomik)a$16v5v@b%)ecu' +if ON_OPENSHIFT and DEBUG: + print("*** Warning - Debug mode is on ***") -# SECURITY WARNING: don't run with debug turned on in production! -DEBUG = True +TEMPLATE_DEBUG = not ON_OPENSHIFT -TEMPLATE_DEBUG = True +if ON_OPENSHIFT: + ALLOWED_HOSTS = [os.environ['OPENSHIFT_APP_DNS'], socket.gethostname()] +else: + ALLOWED_HOSTS = [] -ALLOWED_HOSTS = [] +# Quick-start development settings - unsuitable for production +# See https://docs.djangoproject.com/en/1.6/howto/deployment/checklist/ # Application definition @@ -85,11 +90,11 @@ DATABASES = { 'default': { 'ENGINE': 'django.db.backends.postgresql_psycopg2', - 'NAME': 'eventol', - 'USER': 'eventol', - 'PASSWORD': 'secret', - 'HOST': 'localhost', - 'PORT': '5432', + 'NAME': os.environ.get('OPENSHIFT_APP_NAME', default='eventol'), + 'USER': os.environ.get('OPENSHIFT_POSTGRESQL_DB_USERNAME', default='eventol'), + 'PASSWORD': os.environ.get('OPENSHIFT_POSTGRESQL_DB_PASSWORD', default='secret'), + 'HOST': os.environ.get('OPENSHIFT_POSTGRESQL_DB_HOST', default='localhost'), + 'PORT': os.environ.get('OPENSHIFT_POSTGRESQL_DB_PORT', default='5432'), } } @@ -123,24 +128,23 @@ # https://docs.djangoproject.com/en/1.6/howto/static-files/ STATIC_URL = '/static/' -STATIC_ROOT = os.path.join(BASE_DIR, '..', 'manager', 'static') -TEMPLATE_CONTEXT_PROCESSORS = DEFAULT_SETTINGS.TEMPLATE_CONTEXT_PROCESSORS + ( - 'django.core.context_processors.request', -) +if 'OPENSHIFT_REPO_DIR' in os.environ: + STATIC_ROOT = os.path.join(os.environ.get('OPENSHIFT_REPO_DIR'), 'wsgi', 'static') +else: + STATIC_ROOT = os.path.join(BASE_DIR, '..', 'manager', 'static') -CITIES_FILES = { - 'city': { - 'filename': 'AR.zip', - 'urls': ['http://download.geonames.org/export/dump/' + '{filename}'] - }, -} -CITIES_LOCALES = ['es-AR'] +if 'OPENSHIFT_DATA_DIR' in os.environ: + MEDIA_ROOT = os.path.join(os.environ.get('OPENSHIFT_REPO_DIR'), 'wsgi', 'static', 'media') +else: + MEDIA_ROOT = os.path.join(BASE_DIR, 'media') -CITIES_POSTAL_CODES = ['ARG'] +MEDIA_URL = '/media/' -CITIES_PLUGINS = [] +TEMPLATE_CONTEXT_PROCESSORS = DEFAULT_SETTINGS.TEMPLATE_CONTEXT_PROCESSORS + ( + 'django.core.context_processors.request', +) LOGGING = { 'version': 1, @@ -158,11 +162,6 @@ }, }, 'loggers': { - 'cities': { - 'handlers': ['log_to_stdout'], - 'level': 'INFO', - 'propagate': True, - }, 'django': { 'handlers': ['log_to_stdout'], 'propagate': True, @@ -171,12 +170,13 @@ } } -EMAIL_HOST = 'smtp.gmail.com' -EMAIL_PORT = '587' -EMAIL_HOST_USER = 'YOUR USERNAME' -EMAIL_HOST_PASSWORD = 'YOUR PASSWORD' -EMAIL_USE_TLS = True -EMAIL_FROM = 'FROM@YOURACCOUNT' +EMAIL_HOST = os.environ.get('EVENTOL_EMAIL_HOST', default='smtp.gmail.com') +EMAIL_PORT = os.environ.get('EVENTOL_EMAIL_PORT', default='587') +EMAIL_HOST_USER = os.environ.get('EVENTOL_EMAIL_HOST_USER', default='YOUR USERNAME') +EMAIL_HOST_PASSWORD = os.environ.get('EVENTOL_EMAIL_HOST_PASSWORD', default='YOUR PASSWORD') +EMAIL_USE_TLS = os.environ.get('EVENTOL_EMAIL_USE_TLS', default=True) +EMAIL_FROM = os.environ.get('EVENTOL_EMAIL_FROM', default='FROM@YOURACCOUNT') + LOGIN_URL = '/accounts/login/' OptimizeSettings.THUMBNAIL_OPTIMIZE_COMMAND = { @@ -185,7 +185,7 @@ 'jpg': '/usr/bin/jpegoptim {filename}' } -GRAPPELLI_ADMIN_TITLE = 'Flisol 2015' +GRAPPELLI_ADMIN_TITLE = 'FLISoL 2016' STATICFILES_FINDERS = ( 'django.contrib.staticfiles.finders.FileSystemFinder', diff --git a/manager/initial_data/initial_data.json b/manager/initial_data/initial_data.json index 7606047f..3571ef2b 100644 --- a/manager/initial_data/initial_data.json +++ b/manager/initial_data/initial_data.json @@ -78,50 +78,5 @@ "icon_class": "fa-google-plus-square", "validate": "1" } - }, - { - "model": "manager.Event", - "fields": { - "name": "FLISol-CABA", - "date": "2016-04-25", - "limit_proposal_date": "2016-04-22", - "slug": "caba", - "email": "flisol@gmail.com", - "place": "{}" - }, - "pk": 1 - }, - { - "fields": { - "event": 1, - "name": "Sala Blanca" - }, - "model": "manager.Room", - "pk": 1 - }, - { - "fields": { - "event": 1, - "title": "Linux para tu familia entera", - "long_description": "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec a diam lectus. Sed sit amet ipsum mauris. Maecenas congue ligula ac quam viverra nec consectetur ante hendrerit. Donec et mollis dolor. Praesent et diam eget libero egestas mattis sit amet vitae augue. Nam tincidunt congue enim, ut porta lorem lacinia consectetur. Donec ut libero sed arcu vehicula ultricies a non tortor. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Aenean ut gravida lorem. Ut turpis felis, pulvinar a semper sed, adipiscing id dolor. Pellentesque auctor nisi id magna consequat sagittis. Curabitur dapibus enim sit amet elit pharetra tincidunt feugiat nisl imperdiet. Ut convallis libero in urna ultrices accumsan. Donec sed odio eros. Donec viverra mi quis quam pulvinar at malesuada arcu rhoncus. Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. In rutrum accumsan ultricies. Mauris vitae nisi at sem facilisis semper ac in est.", - "abstract": "Vivamus fermentum semper porta. Nunc diam velit, adipiscing ut tristique vitae, sagittis vel odio. Maecenas convallis ullamcorper ultricies.", - "room":1, - "start_date": "2016-04-25T08:30:00", - "end_date": "2016-04-25T09:00:00" - }, - "model": "manager.Activity", - "pk":1 - }, - { - "fields": { - "activity": 1, - "level": 2, - "type":1, - "speakers_names": "Sergio Orbe, Agustín Ignacio Guido Croce Villanustre", - "speakers_email": "reyiyo@gmail.com, agustin.crocevillanustre@gmail.com", - "labels": "Linux, Software Libre, It's Free" - }, - "model": "manager.talkproposal", - "pk": 1 } ] diff --git a/wsgi.py b/wsgi.py index c443581a..795ead33 100644 --- a/wsgi.py +++ b/wsgi.py @@ -7,301 +7,9 @@ execfile(virtualenv, dict(__file__=virtualenv)) except IOError: pass + # # IMPORTANT: Put any additional includes below this line. If placed above this # line, it's possible required libraries won't be in your searchable path # - -def application(environ, start_response): - - ctype = 'text/plain' - if environ['PATH_INFO'] == '/health': - response_body = "1" - elif environ['PATH_INFO'] == '/env': - response_body = ['%s: %s' % (key, value) - for key, value in sorted(environ.items())] - response_body = '\n'.join(response_body) - else: - ctype = 'text/html' - response_body = ''' - - - - - Welcome to OpenShift - - - -
-
-

Welcome to your Python application on OpenShift

-
- -
-
-
-

Deploying code changes

-

OpenShift uses the Git version control system for your source code, and grants you access to it via the Secure Shell (SSH) protocol. In order to upload and download code to your application you need to give us your public SSH key. You can upload it within the web console or install the RHC command line tool and run rhc setup to generate and upload your key automatically.

- -

Working in your local Git repository

-

If you created your application from the command line and uploaded your SSH key, rhc will automatically download a copy of that source code repository (Git calls this 'cloning') to your local system.

- -

If you created the application from the web console, you'll need to manually clone the repository to your local system. Copy the application's source code Git URL and then run:

- -
$ git clone <git_url> <directory_to_create>
-
-# Within your project directory
-# Commit your changes and push to OpenShift
-
-$ git commit -a -m 'Some commit message'
-$ git push
- - -
- -
-
- -

Managing your application

- -

Web Console

-

You can use the OpenShift web console to enable additional capabilities via cartridges, add collaborator access authorizations, designate custom domain aliases, and manage domain memberships.

- -

Command Line Tools

-

Installing the OpenShift RHC client tools allows you complete control of your cloud environment. Read more on how to manage your application from the command line in our User Guide. -

- -

Development Resources

- - -
-
- - -
- -''' - - status = '200 OK' - response_headers = [('Content-Type', ctype), ('Content-Length', str(len(response_body)))] - # - start_response(status, response_headers) - return [response_body] - -# -# Below for testing only -# -if __name__ == '__main__': - from wsgiref.simple_server import make_server - httpd = make_server('localhost', 8051, application) - # Wait for a single request, serve it and quit. - httpd.handle_request() +from eventoL.wsgi import application diff --git a/wsgi/static/.gitkeep b/wsgi/static/.gitkeep new file mode 100644 index 00000000..e69de29b