Skip to content

Commit

Permalink
Merge pull request wagtail-nest#25 from wagtail/17-vagrant-issues
Browse files Browse the repository at this point in the history
Amending initial settings
  • Loading branch information
daaray authored Feb 15, 2017
2 parents c3762e4 + 745136b commit f8b099b
Show file tree
Hide file tree
Showing 11 changed files with 34 additions and 17 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
.~*
common/CACHE
bakerydemo/media/*
bakerydemo/settings/local.py
bakerydemodb
__pycache__
.*
Expand Down
1 change: 0 additions & 1 deletion bakerydemo/settings/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +0,0 @@
from .dev import *
4 changes: 2 additions & 2 deletions bakerydemo/settings/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@
'wagtail.contrib.modeladmin',
'wagtail.wagtailcore',
'wagtail.contrib.wagtailapi',

'rest_framework',
'modelcluster',
'taggit',
Expand Down Expand Up @@ -106,7 +106,7 @@
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': 'bakerydemodb',
'NAME': os.path.join(BASE_DIR, 'bakerydemodb')
}
}

Expand Down
5 changes: 0 additions & 5 deletions bakerydemo/settings/dev.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,3 @@

# BASE_URL required for notification emails
BASE_URL = 'http://localhost:8000'

try:
from .local import *
except ImportError:
pass
2 changes: 0 additions & 2 deletions bakerydemo/settings/heroku.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@
from .base import *


DEBUG = True

# Accept all hostnames, since we don't know in advance which hostname will be used for any given Heroku instance.
# IMPORTANT: Set this to a real hostname when using this in production!
# See https://docs.djangoproject.com/en/1.10/ref/settings/#allowed-hosts
Expand Down
3 changes: 3 additions & 0 deletions bakerydemo/settings/local.py.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from bakerydemo.settings.dev import * # noqa

# Override settings here
8 changes: 7 additions & 1 deletion bakerydemo/wsgi.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,13 @@
"""

import os
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "bakerydemo.settings")

import dotenv
from django.core.wsgi import get_wsgi_application


dotenv.read_dotenv(os.path.join(os.path.dirname(os.path.dirname(__file__)), '.env'))

os.environ.setdefault("DJANGO_SETTINGS_MODULE", "bakerydemo.settings.dev")

application = get_wsgi_application()
5 changes: 5 additions & 0 deletions manage.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,12 @@
import os
import sys

import dotenv


if __name__ == "__main__":
dotenv.read_dotenv()

os.environ.setdefault("DJANGO_SETTINGS_MODULE", "bakerydemo.settings")

from django.core.management import execute_from_command_line
Expand Down
12 changes: 11 additions & 1 deletion readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,17 @@ With PIP installed run the following commands:

git clone [email protected]:wagtail/bakerydemo.git
cd wagtaildemo
pip install -r requirements/base.txt
pip install -r requirements.txt

Next, we'll set up our local environment variables. We use [django-dotenv](https://github.com/jpadilla/django-dotenv)
to help with this. It reads environment variables located in a file name .env in the top level directory of the project.
The only variable we need to start is `DJANGO_SETTINGS_MODULE`:

$ cp bakerydemo/settings/local.example.py bakerydemo/settings/local.py
$ echo "DJANGO_SETTINGS_MODULE=bakerydemo.settings.local" > .env

Execute the following commands:

./manage.py migrate
./manage.py load_initial_data
./manage.py runserver
Expand Down
1 change: 1 addition & 0 deletions requirements/base.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
Django==1.10.5
django-dotenv==1.4.1
# http://docs.wagtail.io/en/v1.8.1/topics/search/backends.html#elasticsearch-backend
# Not utilized by default; uncomment and review the above document if you require elasticsearch
# elasticsearch==5.1.0
Expand Down
9 changes: 4 additions & 5 deletions vagrant/provision.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,6 @@ PYTHON=$VIRTUALENV_DIR/bin/python
PIP=$VIRTUALENV_DIR/bin/pip


# Create database
su - vagrant -c "createdb $PROJECT_NAME"


# Virtualenv setup for project
su - vagrant -c "virtualenv --python=python3 $VIRTUALENV_DIR"
# Replace previous line with this if you are using Python 2
Expand All @@ -31,6 +27,10 @@ su - vagrant -c "$PIP install -r $PROJECT_DIR/requirements/base.txt"
# Set execute permissions on manage.py as they get lost if we build from a zip file
chmod a+x $PROJECT_DIR/manage.py

# copy local settings file
cp $PROJECT_DIR/bakerydemo/settings/local.py.example $PROJECT_DIR/bakerydemo/settings/local.py
# add .env file for django-dotenv environment variable definitions
echo DJANGO_SETTINGS_MODULE=$PROJECT_NAME.settings.local > $PROJECT_DIR/.env

# Run syncdb/migrate/load_initial_data/update_index
su - vagrant -c "$PYTHON $PROJECT_DIR/manage.py migrate --noinput && \
Expand All @@ -41,7 +41,6 @@ su - vagrant -c "$PYTHON $PROJECT_DIR/manage.py migrate --noinput && \
# Add a couple of aliases to manage.py into .bashrc
cat << EOF >> /home/vagrant/.bashrc
export PYTHONPATH=$PROJECT_DIR
export DJANGO_SETTINGS_MODULE=$PROJECT_NAME.settings.dev
alias dj="django-admin.py"
alias djrun="dj runserver 0.0.0.0:8000"
Expand Down

0 comments on commit f8b099b

Please sign in to comment.