From 8a5a1fa94fb1a13f623a5b679971bfd78c5d2449 Mon Sep 17 00:00:00 2001 From: Marc Aymerich Date: Thu, 1 Oct 2015 17:11:05 +0000 Subject: [PATCH] Fixes on deployment --- TODO.md | 3 +- .../project_template/project_name/settings.py | 117 +++++++++--------- orchestra/contrib/saas/backends/moodle.py | 6 +- .../management/commands/restartservices.py | 4 +- orchestra/management/commands/setuplog.py | 4 +- .../management/commands/startservices.py | 5 +- orchestra/management/commands/stopservices.py | 4 +- orchestra/settings.py | 16 +-- 8 files changed, 78 insertions(+), 81 deletions(-) diff --git a/TODO.md b/TODO.md index 986f1f32..e0165e31 100644 --- a/TODO.md +++ b/TODO.md @@ -390,8 +390,7 @@ Case deploy --dev deploy.sh and deploy-dev.sh autoupgrade -chown orchestra:orchestra /home/orchestra/panel/orchestra.log -orchestra home autocomplete +orchestra home autocomplete skeleton short URLS: https://github.com/rsvp/gitio diff --git a/orchestra/conf/project_template/project_name/settings.py b/orchestra/conf/project_template/project_name/settings.py index 7ddeafbc..441c4600 100644 --- a/orchestra/conf/project_template/project_name/settings.py +++ b/orchestra/conf/project_template/project_name/settings.py @@ -51,7 +51,9 @@ INSTALLED_APPS = [ 'orchestra.contrib.bills', 'orchestra.contrib.payments', 'orchestra.contrib.tasks', - + 'orchestra.contrib.mailer', + 'orchestra.contrib.history', + # Third-party apps 'django_extensions', 'djcelery', @@ -65,9 +67,8 @@ INSTALLED_APPS = [ 'rest_framework.authtoken', 'passlib.ext.django', 'django_countries', -# 'django_mailer', # 'debug_toolbar', - + # Django.contrib 'django.contrib.auth', 'django.contrib.contenttypes', @@ -75,28 +76,13 @@ INSTALLED_APPS = [ 'django.contrib.messages', 'django.contrib.staticfiles', 'django.contrib.admin.apps.SimpleAdminConfig', - + # Last to load 'orchestra.contrib.resources', 'orchestra.contrib.settings', ] -MIDDLEWARE_CLASSES = [ - 'django.contrib.sessions.middleware.SessionMiddleware', - 'django.middleware.common.CommonMiddleware', - 'django.middleware.csrf.CsrfViewMiddleware', - 'django.contrib.auth.middleware.AuthenticationMiddleware', - 'django.contrib.auth.middleware.SessionAuthenticationMiddleware', - 'django.contrib.messages.middleware.MessageMiddleware', - 'django.middleware.clickjacking.XFrameOptionsMiddleware', - 'django.middleware.security.SecurityMiddleware', - 'orchestra.core.caches.RequestCacheMiddleware', - # also handles transations, ATOMIC_REQUESTS does not wrap middlewares - 'orchestra.contrib.orchestration.middlewares.OperationsMiddleware', -] - - ROOT_URLCONF = '{{ project_name }}.urls' TEMPLATES = [ @@ -173,6 +159,22 @@ LOCALE_PATHS = ( ORCHESTRA_SITE_NAME = '{{ project_name }}' +MIDDLEWARE_CLASSES = ( + 'django.contrib.sessions.middleware.SessionMiddleware', + 'corsheaders.middleware.CorsMiddleware', + 'django.middleware.common.CommonMiddleware', + 'django.middleware.csrf.CsrfViewMiddleware', + 'django.contrib.auth.middleware.AuthenticationMiddleware', + 'django.contrib.auth.middleware.SessionAuthenticationMiddleware', + 'django.contrib.messages.middleware.MessageMiddleware', + 'django.middleware.clickjacking.XFrameOptionsMiddleware', + 'django.middleware.security.SecurityMiddleware', + 'orchestra.core.caches.RequestCacheMiddleware', + # also handles transations, ATOMIC_REQUESTS does not wrap middlewares + 'orchestra.contrib.orchestration.middlewares.OperationsMiddleware', +) + + AUTH_USER_MODEL = 'accounts.Account' @@ -182,48 +184,7 @@ AUTHENTICATION_BACKENDS = [ ] -LOGGING = { - 'version': 1, - 'disable_existing_loggers': False, - 'formatters': { - 'simple': { - 'format': '%(asctime)s %(name)s %(levelname)s %(message)s' - }, - }, - 'filters': { - 'require_debug_false': { - '()': 'django.utils.log.RequireDebugFalse', - }, - 'require_debug_true': { - '()': 'django.utils.log.RequireDebugTrue', - }, - }, - 'handlers': { - 'file': { - 'level': 'DEBUG', - 'class': 'logging.FileHandler', - 'filename': os.path.join(BASE_DIR, 'orchestra.log'), - 'formatter': 'simple' - }, - 'console': { - 'level': 'INFO', - 'filters': ['require_debug_true'], - 'class': 'logging.StreamHandler', - }, - }, - 'loggers': { - 'orchestra': { - 'handlers': ['file', 'console'], - 'level': 'INFO', - 'propagate': True, - }, - 'orm': { - 'handlers': ['file',], - 'level': 'INFO', - 'propagate': True, - }, - }, -} +EMAIL_BACKEND = 'orchestra.contrib.mailer.backends.EmailBackend' ################################# @@ -242,3 +203,37 @@ FLUENT_DASHBOARD_ICON_THEME = '../orchestra/icons' import djcelery djcelery.setup_loader() CELERYBEAT_SCHEDULER = 'djcelery.schedulers.DatabaseScheduler' + + +# rest_framework +REST_FRAMEWORK = { + 'DEFAULT_PERMISSION_CLASSES': ( + 'orchestra.permissions.api.OrchestraPermissionBackend', + ), + 'DEFAULT_AUTHENTICATION_CLASSES': ( + 'rest_framework.authentication.SessionAuthentication', + 'rest_framework.authentication.TokenAuthentication', + ), + 'DEFAULT_FILTER_BACKENDS': ( + ('rest_framework.filters.DjangoFilterBackend',) + ), +} + + +# Use a UNIX compatible hash +PASSLIB_CONFIG = ( + "[passlib]\n" + "schemes = sha512_crypt, django_pbkdf2_sha256, django_pbkdf2_sha1, " + " django_bcrypt, django_bcrypt_sha256, django_salted_sha1, des_crypt, " + " django_salted_md5, django_des_crypt, hex_md5, bcrypt, phpass\n" + "default = sha512_crypt\n" + "deprecated = django_pbkdf2_sha1, django_salted_sha1, django_salted_md5, " + " django_des_crypt, des_crypt, hex_md5\n" + "all__vary_rounds = 0.05\n" + "django_pbkdf2_sha256__min_rounds = 10000\n" + "sha512_crypt__min_rounds = 80000\n" + "staff__django_pbkdf2_sha256__default_rounds = 12500\n" + "staff__sha512_crypt__default_rounds = 100000\n" + "superuser__django_pbkdf2_sha256__default_rounds = 15000\n" + "superuser__sha512_crypt__default_rounds = 120000\n" +) diff --git a/orchestra/contrib/saas/backends/moodle.py b/orchestra/contrib/saas/backends/moodle.py index 98ddafc9..99831b0f 100644 --- a/orchestra/contrib/saas/backends/moodle.py +++ b/orchestra/contrib/saas/backends/moodle.py @@ -18,17 +18,19 @@ class MoodleMuBackend(ServiceController): // "" => ["", ""], ); - wwwroot = "https://{$site}-courses.pangea.org"; $site = getenv("SITE"); + $wwwroot = "https://{$site}-courses.pangea.org"; if ( $site == '' ) { - http_host = $_SERVER['HTTP_HOST']; + $http_host = $_SERVER['HTTP_HOST']; if (array_key_exists($http_host, $site_map)) { $site = $site_map[$http_host][0]; $wwwroot = $site_map[$http_host][1]; } elseif (strpos($http_host, '-courses.') !== false) { $site = array_shift((explode("-courses.", $http_host))); + $wwwroot = "https://{$site}-courses.pangea.org"; } else { $site = array_shift((explode(".", $http_host))); + $wwwroot = "https://{$site}-courses.pangea.org"; } } $CFG->prefix = "${site}_"; diff --git a/orchestra/management/commands/restartservices.py b/orchestra/management/commands/restartservices.py index 9c17d59b..63754897 100644 --- a/orchestra/management/commands/restartservices.py +++ b/orchestra/management/commands/restartservices.py @@ -1,11 +1,11 @@ from django.core.management.base import BaseCommand +from orchestra import settings from orchestra.management.commands.startservices import ManageServiceCommand -from orchestra.settings import ORCHESTRA_RESTART_SERVICES class Command(ManageServiceCommand): - services = ORCHESTRA_RESTART_SERVICES + services = settings.ORCHESTRA_RESTART_SERVICES action = 'restart' option_list = BaseCommand.option_list help = 'Restart all related services. Usefull for reload configuration and files.' diff --git a/orchestra/management/commands/setuplog.py b/orchestra/management/commands/setuplog.py index 4092b9c8..99bd4c9f 100644 --- a/orchestra/management/commands/setuplog.py +++ b/orchestra/management/commands/setuplog.py @@ -38,7 +38,9 @@ class Command(BaseCommand): 'LOGGING': settings_parser.Remove(), }) setuplogrotate = textwrap.dedent("""\ - mkdir %(log_dir)s && chown $(ls -dl %(site_dir)s|awk {'print $3":"$4'}) %(log_dir)s + mkdir %(log_dir)s && chown -reference=%(site_dir)s %(log_dir)s + touch %(log_path)s + chown --reference=%(log_dir)s %(log_path)s echo '%(log_dir)s/*.log { copytruncate daily diff --git a/orchestra/management/commands/startservices.py b/orchestra/management/commands/startservices.py index 1099802d..4764ce60 100644 --- a/orchestra/management/commands/startservices.py +++ b/orchestra/management/commands/startservices.py @@ -2,7 +2,7 @@ from optparse import make_option from django.core.management.base import BaseCommand -from orchestra.settings import ORCHESTRA_START_SERVICES +from orchestra import settings from orchestra.utils.sys import run, check_root @@ -27,7 +27,6 @@ def flatten(nested, depth=0): yield nested - class ManageServiceCommand(BaseCommand): def __init__(self, *args, **kwargs): super(ManageServiceCommand, self).__init__(*args, **kwargs) @@ -53,7 +52,7 @@ class ManageServiceCommand(BaseCommand): class Command(ManageServiceCommand): - services = ORCHESTRA_START_SERVICES + services = settings.ORCHESTRA_START_SERVICES action = 'start' option_list = BaseCommand.option_list help = 'Start all related services. Usefull for reload configuration and files.' diff --git a/orchestra/management/commands/stopservices.py b/orchestra/management/commands/stopservices.py index 67c026ad..ac0e6583 100644 --- a/orchestra/management/commands/stopservices.py +++ b/orchestra/management/commands/stopservices.py @@ -1,11 +1,11 @@ from django.core.management.base import BaseCommand +from orchestra import settings from orchestra.management.commands.startservices import ManageServiceCommand -from orchestra.settings import ORCHESTRA_STOP_SERVICES class Command(ManageServiceCommand): - services = ORCHESTRA_STOP_SERVICES + services = settings.ORCHESTRA_STOP_SERVICES action = 'stop' option_list = BaseCommand.option_list help = 'Stop all related services. Usefull for reload configuration and files.' diff --git a/orchestra/settings.py b/orchestra/settings.py index 563a3498..9aa2d436 100644 --- a/orchestra/settings.py +++ b/orchestra/settings.py @@ -36,9 +36,9 @@ ORCHESTRA_SITE_VERBOSE_NAME = Setting('ORCHESTRA_SITE_VERBOSE_NAME', ORCHESTRA_START_SERVICES = Setting('ORCHESTRA_START_SERVICES', default=( 'postgresql', - 'celeryevcam', - 'celeryd', - 'celerybeat', +# 'celeryevcam', +# 'celeryd', +# 'celerybeat', ('uwsgi', 'nginx'), ), ) @@ -46,8 +46,8 @@ ORCHESTRA_START_SERVICES = Setting('ORCHESTRA_START_SERVICES', ORCHESTRA_RESTART_SERVICES = Setting('ORCHESTRA_RESTART_SERVICES', default=( - 'celeryd', - 'celerybeat', +# 'celeryd', +# 'celerybeat', 'uwsgi' ), ) @@ -56,9 +56,9 @@ ORCHESTRA_RESTART_SERVICES = Setting('ORCHESTRA_RESTART_SERVICES', ORCHESTRA_STOP_SERVICES = Setting('ORCHESTRA_STOP_SERVICES', default=( ('uwsgi', 'nginx'), - 'celerybeat', - 'celeryd', - 'celeryevcam', +# 'celerybeat', +# 'celeryd', +# 'celeryevcam', 'postgresql' ), )