Commit e0fa3449 authored by David Haynes's avatar David Haynes

Vagrant support for new settings structure

- uses enviornment vars
- loads script that you can source when `vagrant ssh`'d in
parent ab4e47e6
Pipeline #1192 passed with stage
in 1 minute and 1 second
......@@ -15,4 +15,5 @@ venv
htmlcov/
.idea
__pycache__/
.vscode
\ No newline at end of file
.vscode
go/sourceme.sh
......@@ -95,7 +95,7 @@ Vagrant.configure(2) do |config|
venv_path: "/vagrant/venv",
cas_url: "https://cas.srct.gmu.edu/",
app_path: "/vagrant/go",
settings_path: "/vagrant/go/settings",
sourceme_dest: "/vagrant/go/",
superuser: "dhaynes3"
}
}
......
......@@ -8,6 +8,23 @@
# - Django
- hosts: all
environment:
GO_SECRET_KEY: "{{ django['secret_key'] }}"
GO_ALLOWED_HOSTS: "{{ django['host'] }}"
GO_EMAIL_DOMAIN: "{{ django['email_domain'] }}"
GO_CAS_URL: "{{ django['cas_url'] }}"
GO_DB_NAME: "{{ mysql['db'] }}"
GO_DB_USER: "{{ mysql['user'] }}"
GO_DB_PASSWORD: "{{ mysql['pass'] }}"
GO_DB_HOST: localhost
GO_DB_PORT: 3306
GO_EMAIL_HOST: ""
GO_EMAIL_PORT: ""
GO_EMAIL_HOST_USER: ""
GO_EMAIL_HOST_PASSWORD: ""
GO_EMAIL_FROM: ""
GO_EMAIL_TO: ""
tasks:
- name: Install Python 3.4.3 and related packages
apt:
......@@ -30,6 +47,7 @@
- name: Create the virtualenv
command: virtualenv -p python3 /vagrant/venv
ignore_errors: true
- name: Install go packages
apt:
......@@ -75,17 +93,6 @@
priv: test_{{ mysql['db'] }}.*:ALL
append_privs: yes
- name: install django settings.py
template:
src: templates/settings.py.j2
dest: "{{ django['settings_path'] }}/settings.py"
backup: yes
- name: install django secret.py
template:
src: templates/secret.py.j2
dest: "{{ django['settings_path'] }}/secret.py"
- name: setup django database
django_manage:
command: "{{ item }}"
......@@ -107,5 +114,11 @@
shell: screen -ls | grep -q django && screen -X -S django quit
ignore_errors: true
- name: install env variable convenience script
template:
src: templates/sourceme.j2
dest: "{{ django['sourceme_dest'] }}/sourceme.sh"
backup: yes
- name: start django runserver (access via localhost:8000)
command: screen -dmS django bash -c "echo Starting on port {{ nginx['port'] }}; cd /vagrant/go; source ../venv/bin/activate; python3 manage.py runserver 0.0.0.0:8000;"
# Create a new file 'secret.py' and copy these contents into that file
# Please be sure to keep these variables secret in production
# You can generate a secret key from the following link: http://www.miniwebtool.com/django-secret-key-generator/
SECRET_KEY = "{{ django['secret_key'] }}"
# Use the values from the database configuration
DB_NAME = "{{ mysql['db'] }}"
DB_USER = "{{ mysql['user'] }}"
# Remember to use a strong password in production
DB_PASSWORD = "{{ mysql['pass'] }}"
# Often left blank
DB_HOST = ""
# Email configuration, if necessary
EMAIL_HOST = ""
EMAIL_PORT = ""
EMAIL_HOST_USER = ""
EMAIL_HOST_PASSWORD = ""
# Create a new file 'settings.py' and copy these contents into that file
from . import secret
import os
BASE_DIR = os.path.dirname(os.path.dirname(__file__))
# DEBUG mode is used to view more details when errors occur
# Do not have set True in production
DEBUG = {{ django['debug'] }}
ADMINS = ()
MANAGERS = ADMINS
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.mysql',
'NAME': secret.DB_NAME,
'USER': secret.DB_USER,
'PASSWORD': secret.DB_PASSWORD,
'HOST': secret.DB_HOST,
'PORT': '',
}
}
# The domains this application will be deployed on
# e.g. Which domains this app should listen to requests from.
ALLOWED_HOSTS = ['{{ django['host'] }}']
# Peoplefinder API
PF_URL = "https://api.srct.gmu.edu/pf/v1/"
TIME_ZONE = 'America/New_York'
LANGUAGE_CODE = 'en-us'
SITE_ID = 1
USE_I18N = True
USE_L10N = True
USE_TZ = True
MEDIA_URL = '/media/'
MEDIA_ROOT = ''
MEDIAFILES_DIRS = (
os.path.join(BASE_DIR, 'media/'),
)
STATIC_URL = '/static/'
STATIC_ROOT = ''
STATICFILES_DIRS = (
os.path.join(BASE_DIR, 'static/'),
)
STATICFILES_FINDERS = (
'django.contrib.staticfiles.finders.FileSystemFinder',
'django.contrib.staticfiles.finders.AppDirectoriesFinder',
)
SECRET_KEY = secret.SECRET_KEY
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [
os.path.join(BASE_DIR, 'templates')
],
'OPTIONS': {
'context_processors': [
'django.contrib.auth.context_processors.auth',
'django.template.context_processors.request'
],
'loaders': [
'django.template.loaders.app_directories.Loader'
],
'debug': DEBUG
}
}
]
MIDDLEWARE_CLASSES = (
'django.middleware.common.CommonMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
)
ROOT_URLCONF = 'settings.urls'
WSGI_APPLICATION = 'settings.wsgi.application'
INSTALLED_APPS = (
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.sites',
'django.contrib.messages',
'django.contrib.staticfiles',
'go',
'django.contrib.admin',
'qrcode',
'crispy_forms',
'bootstrap3_datetime',
)
SESSION_SERIALIZER = 'django.contrib.sessions.serializers.JSONSerializer'
LOGGING = {
'version': 1,
'disable_existing_loggers': False,
'filters': {
'require_debug_false': {
'()': 'django.utils.log.RequireDebugFalse'
}
},
'handlers': {
'mail_admins': {
'level': 'ERROR',
'filters': ['require_debug_false'],
'class': 'django.utils.log.AdminEmailHandler'
}
},
'loggers': {
'django.request': {
'handlers': ['mail_admins'],
'level': 'ERROR',
'propagate': True,
},
}
}
LOGIN_URL = '/login'
LOGOUT_URL = '/logout'
LOGIN_REDIRECT_URL = '/'
AUTHENTICATION_BACKENDS = (
'django.contrib.auth.backends.ModelBackend',
)
CAS_SERVER_URL = "{{ django['cas_url'] }}"
CAS_LOGOUT_COMPLETELY = True
CAS_PROVIDE_URL_TO_LOGOUT = True
AUTHENTICATION_BACKENDS += (
'cas.backends.CASBackend',
)
CAS_RESPONSE_CALLBACKS = (
'go.cas_callbacks.create_user',
)
INSTALLED_APPS += (
'cas',
)
MIDDLEWARE_CLASSES += (
'cas.middleware.CASMiddleware',
)
CRISPY_TEMPLATE_PACK = 'bootstrap3'
# Mail settings
EMAIL_HOST = secret.EMAIL_HOST
EMAIL_PORT = secret.EMAIL_PORT
EMAIL_HOST_USER = secret.EMAIL_HOST_USER
EMAIL_HOST_PASSWORD = secret.EMAIL_HOST_PASSWORD
EMAIL_FROM = "example@example.com"
EMAIL_TO = "to@example.com"
# Domain used to email to users. See line 231 in views.py
# ie. in Mason's case '@masonlive.gmu.edu'
EMAIL_DOMAIN = "{{ django['email_domain'] }}"
export GO_SECRET_KEY="{{ django['secret_key'] }}"
export GO_ALLOWED_HOSTS="{{ django['host'] }}"
export GO_EMAIL_DOMAIN="{{ django['email_domain'] }}"
export GO_CAS_URL="{{ django['cas_url'] }}"
export GO_DB_NAME="{{ mysql['db'] }}"
export GO_DB_USER="{{ mysql['user'] }}"
export GO_DB_PASSWORD="{{ mysql['pass'] }}"
export GO_DB_HOST=localhost
export GO_DB_PORT=3306
export GO_EMAIL_HOST=
export GO_EMAIL_PORT=
export GO_EMAIL_HOST_USER=
export GO_EMAIL_HOST_PASSWORD=
export GO_EMAIL_FROM=
export GO_EMAIL_TO=
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment