github.com/blystad/deis@v0.11.0/controller/deis/settings.py (about)

     1  """
     2  Django settings for the Deis project.
     3  """
     4  
     5  from __future__ import unicode_literals
     6  import os.path
     7  import sys
     8  import tempfile
     9  
    10  PROJECT_ROOT = os.path.normpath(os.path.join(os.path.dirname(__file__), '..'))
    11  
    12  DEBUG = False
    13  TEMPLATE_DEBUG = DEBUG
    14  
    15  ADMINS = (
    16      # ('Your Name', 'your_email@example.com'),
    17  )
    18  
    19  MANAGERS = ADMINS
    20  
    21  CONN_MAX_AGE = 60 * 3
    22  
    23  # Hosts/domain names that are valid for this site; required if DEBUG is False
    24  # See https://docs.djangoproject.com/en/1.5/ref/settings/#allowed-hosts
    25  ALLOWED_HOSTS = ['localhost']
    26  
    27  # Local time zone for this installation. Choices can be found here:
    28  # http://en.wikipedia.org/wiki/List_of_tz_zones_by_name
    29  # although not all choices may be available on all operating systems.
    30  # In a Windows environment this must be set to your system time zone.
    31  TIME_ZONE = 'America/Denver'
    32  
    33  # Language code for this installation. All choices can be found here:
    34  # http://www.i18nguy.com/unicode/language-identifiers.html
    35  LANGUAGE_CODE = 'en-us'
    36  
    37  SITE_ID = 1
    38  
    39  # If you set this to False, Django will make some optimizations so as not
    40  # to load the internationalization machinery.
    41  USE_I18N = True
    42  
    43  # If you set this to False, Django will not format dates, numbers and
    44  # calendars according to the current locale.
    45  USE_L10N = True
    46  
    47  # If you set this to False, Django will not use timezone-aware datetimes.
    48  USE_TZ = True
    49  
    50  # Absolute filesystem path to the directory that will hold user-uploaded files.
    51  # Example: "/var/www/example.com/media/"
    52  MEDIA_ROOT = ''
    53  
    54  # URL that handles the media served from MEDIA_ROOT. Make sure to use a
    55  # trailing slash.
    56  # Examples: "http://example.com/media/", "http://media.example.com/"
    57  MEDIA_URL = ''
    58  
    59  # Absolute path to the directory static files should be collected to.
    60  # Don't put anything in this directory yourself; store your static files
    61  # in apps' "static/" subdirectories and in STATICFILES_DIRS.
    62  # Example: "/var/www/example.com/static/"
    63  STATIC_ROOT = os.path.abspath(os.path.join(__file__, '..', '..', 'static'))
    64  
    65  # URL prefix for static files.
    66  # Example: "http://example.com/static/", "http://static.example.com/"
    67  STATIC_URL = '/static/'
    68  
    69  # Additional locations of static files
    70  STATICFILES_DIRS = (
    71      # Put strings here, like "/home/html/static" or "C:/www/django/static".
    72      # Always use forward slashes, even on Windows.
    73      # Don't forget to use absolute paths, not relative paths.
    74  )
    75  
    76  # List of finder classes that know how to find static files in
    77  # various locations.
    78  STATICFILES_FINDERS = (
    79      'django.contrib.staticfiles.finders.FileSystemFinder',
    80      'django.contrib.staticfiles.finders.AppDirectoriesFinder',
    81  )
    82  
    83  # Make this unique, and don't share it with anybody.
    84  SECRET_KEY = None  # @UnusedVariable
    85  
    86  # List of callables that know how to import templates from various sources.
    87  TEMPLATE_LOADERS = (
    88      'django.template.loaders.filesystem.Loader',
    89      'django.template.loaders.app_directories.Loader',
    90  )
    91  
    92  TEMPLATE_CONTEXT_PROCESSORS = (
    93      "django.contrib.auth.context_processors.auth",
    94      "django.core.context_processors.debug",
    95      "django.core.context_processors.i18n",
    96      "django.core.context_processors.media",
    97      "django.core.context_processors.request",
    98      "django.core.context_processors.static",
    99      "django.core.context_processors.tz",
   100      "django.contrib.messages.context_processors.messages",
   101      "allauth.account.context_processors.account",
   102      "deis.context_processors.site",
   103  )
   104  
   105  MIDDLEWARE_CLASSES = (
   106      'django.middleware.common.CommonMiddleware',
   107      'django.contrib.sessions.middleware.SessionMiddleware',
   108      'django.middleware.csrf.CsrfViewMiddleware',
   109      'django.contrib.auth.middleware.AuthenticationMiddleware',
   110      'django.contrib.messages.middleware.MessageMiddleware',
   111      'api.middleware.VersionMiddleware',
   112      # Uncomment the next line for simple clickjacking protection:
   113      # 'django.middleware.clickjacking.XFrameOptionsMiddleware',
   114  )
   115  
   116  ROOT_URLCONF = 'deis.urls'
   117  
   118  # Python dotted path to the WSGI application used by Django's runserver.
   119  WSGI_APPLICATION = 'deis.wsgi.application'
   120  
   121  TEMPLATE_DIRS = (
   122      # Put strings here, like "/home/html/django_templates"
   123      # or "C:/www/django/templates".
   124      # Always use forward slashes, even on Windows.
   125      # Don't forget to use absolute paths, not relative paths.
   126      PROJECT_ROOT + '/web/templates',
   127  )
   128  
   129  INSTALLED_APPS = (
   130      'django.contrib.admin',
   131      'django.contrib.auth',
   132      'django.contrib.contenttypes',
   133      'django.contrib.humanize',
   134      'django.contrib.messages',
   135      'django.contrib.sessions',
   136      'django.contrib.sites',
   137      'django.contrib.staticfiles',
   138      # Third-party apps
   139      'allauth',
   140      'allauth.account',
   141      'django_fsm',
   142      'guardian',
   143      'json_field',
   144      'gunicorn',
   145      'rest_framework',
   146      'south',
   147      # Deis apps
   148      'api',
   149      'web',
   150  )
   151  
   152  AUTHENTICATION_BACKENDS = (
   153      # Needed to login by username in Django admin, regardless of `allauth`
   154      "django.contrib.auth.backends.ModelBackend",
   155      "guardian.backends.ObjectPermissionBackend",
   156      # `allauth` specific authentication methods, such as login by e-mail
   157      "allauth.account.auth_backends.AuthenticationBackend",
   158  )
   159  
   160  ANONYMOUS_USER_ID = -1
   161  ACCOUNT_EMAIL_REQUIRED = True
   162  ACCOUNT_EMAIL_VERIFICATION = 'none'
   163  ACCOUNT_LOGOUT_ON_GET = True
   164  ACCOUNT_USERNAME_BLACKLIST = ['system']
   165  LOGIN_REDIRECT_URL = '/dashboard/'
   166  
   167  
   168  SOUTH_TESTS_MIGRATE = False
   169  
   170  REST_FRAMEWORK = {
   171      'DEFAULT_MODEL_SERIALIZER_CLASS':
   172      'rest_framework.serializers.ModelSerializer',
   173      'DEFAULT_PERMISSION_CLASSES': (
   174          'rest_framework.permissions.IsAuthenticated',
   175      ),
   176      'DEFAULT_AUTHENTICATION_CLASSES': (
   177          'rest_framework.authentication.SessionAuthentication',
   178      ),
   179      'PAGINATE_BY': 100,
   180  }
   181  
   182  # URLs that end with slashes are ugly
   183  APPEND_SLASH = False
   184  
   185  # Determine where to send syslog messages
   186  if os.path.exists('/dev/log'):           # Linux rsyslog
   187      SYSLOG_ADDRESS = '/dev/log'
   188  elif os.path.exists('/var/log/syslog'):  # Mac OS X syslog
   189      SYSLOG_ADDRESS = '/var/log/syslog'
   190  else:                                    # default SysLogHandler address
   191      SYSLOG_ADDRESS = ('localhost', 514)
   192  
   193  # A sample logging configuration. The only tangible logging
   194  # performed by this configuration is to send an email to
   195  # the site admins on every HTTP 500 error when DEBUG=False.
   196  # See http://docs.djangoproject.com/en/dev/topics/logging for
   197  # more details on how to customize your logging configuration.
   198  LOGGING = {
   199      'version': 1,
   200      'disable_existing_loggers': False,
   201      'formatters': {
   202          'verbose': {
   203              'format': '%(levelname)s %(asctime)s %(module)s %(process)d %(thread)d %(message)s'
   204          },
   205          'simple': {
   206              'format': '%(levelname)s %(message)s'
   207          },
   208      },
   209      'filters': {
   210          'require_debug_false': {
   211              '()': 'django.utils.log.RequireDebugFalse'
   212          }
   213      },
   214      'handlers': {
   215          'null': {
   216              'level': 'DEBUG',
   217              'class': 'logging.NullHandler',
   218          },
   219          'console': {
   220              'level': 'DEBUG',
   221              'class': 'logging.StreamHandler',
   222              'formatter': 'simple'
   223          },
   224          'mail_admins': {
   225              'level': 'ERROR',
   226              'filters': ['require_debug_false'],
   227              'class': 'django.utils.log.AdminEmailHandler'
   228          },
   229          'rsyslog': {
   230              'class': 'logging.handlers.SysLogHandler',
   231              'address': SYSLOG_ADDRESS,
   232              'facility': 'local0',
   233          },
   234      },
   235      'loggers': {
   236          'django': {
   237              'handlers': ['null'],
   238              'level': 'INFO',
   239              'propagate': True,
   240          },
   241          'django.request': {
   242              'handlers': ['console', 'mail_admins'],
   243              'level': 'WARNING',
   244              'propagate': True,
   245          },
   246          'api': {
   247              'handlers': ['console', 'mail_admins', 'rsyslog'],
   248              'level': 'INFO',
   249              'propagate': True,
   250          },
   251      }
   252  }
   253  TEST_RUNNER = 'api.tests.SilentDjangoTestSuiteRunner'
   254  
   255  # celery settings
   256  CELERY_ACCEPT_CONTENT = ['pickle', 'json']
   257  CELERY_IMPORTS = ('api.tasks',)
   258  BROKER_URL = 'redis://{}:{}/{}'.format(
   259               os.environ.get('CACHE_HOST', '127.0.0.1'),
   260               os.environ.get('CACHE_PORT', 6379),
   261               os.environ.get('CACHE_NAME', 0))
   262  CELERY_RESULT_BACKEND = BROKER_URL
   263  # this number should be equal to N+1, where
   264  # N is number of nodes in largest formation
   265  CELERYD_CONCURRENCY = 8
   266  
   267  # etcd settings
   268  ETCD_HOST, ETCD_PORT = os.environ.get('ETCD', '127.0.0.1:4001').split(',')[0].split(':')
   269  
   270  # default deis settings
   271  DEIS_LOG_DIR = os.path.abspath(os.path.join(__file__, '..', '..', 'logs'))
   272  LOG_LINES = 1000
   273  TEMPDIR = tempfile.mkdtemp(prefix='deis')
   274  DEFAULT_BUILD = 'deis/helloworld'
   275  
   276  # security keys and auth tokens
   277  SECRET_KEY = os.environ.get('DEIS_SECRET_KEY', 'CHANGEME_sapm$s%upvsw5l_zuy_&29rkywd^78ff(qi')
   278  BUILDER_KEY = os.environ.get('DEIS_BUILDER_KEY', 'CHANGEME_sapm$s%upvsw5l_zuy_&29rkywd^78ff(qi')
   279  
   280  # registry settings
   281  REGISTRY_MODULE = 'registry.mock'
   282  REGISTRY_URL = 'http://localhost:5000'
   283  REGISTRY_HOST = 'localhost'
   284  REGISTRY_PORT = 5000
   285  
   286  # check if we can register users with `deis register`
   287  REGISTRATION_ENABLED = True
   288  
   289  # check if we should enable the web UI module
   290  WEB_ENABLED = False
   291  
   292  # default to sqlite3, but allow postgresql config through envvars
   293  DATABASES = {
   294      'default': {
   295          'ENGINE': 'django.db.backends.' + os.environ.get('DATABASE_ENGINE', 'postgresql_psycopg2'),
   296          'NAME': os.environ.get('DATABASE_NAME', 'deis'),
   297      }
   298  }
   299  
   300  APP_URL_REGEX = '[a-z0-9-]+'
   301  
   302  # SECURITY: change this to allowed fqdn's to prevent host poisioning attacks
   303  # see https://docs.djangoproject.com/en/1.5/ref/settings/#std:setting-ALLOWED_HOSTS
   304  ALLOWED_HOSTS = ['*']
   305  
   306  # Honor HTTPS from a trusted proxy
   307  # see https://docs.djangoproject.com/en/1.6/ref/settings/#secure-proxy-ssl-header
   308  SECURE_PROXY_SSL_HEADER = ('HTTP_X_FORWARDED_PROTO', 'https')
   309  
   310  # Create a file named "local_settings.py" to contain sensitive settings data
   311  # such as database configuration, admin email, or passwords and keys. It
   312  # should also be used for any settings which differ between development
   313  # and production.
   314  # The local_settings.py file should *not* be checked in to version control.
   315  try:
   316      from .local_settings import *  # @UnusedWildImport # noqa
   317  except ImportError:
   318      pass
   319  
   320  
   321  # have confd_settings within container execution override all others
   322  # including local_settings (which may end up in the container)
   323  if os.path.exists('/templates/confd_settings.py'):
   324      sys.path.append('/templates')
   325      from confd_settings import *  # noqa