Create a gist now

Instantly share code, notes, and snippets.

@koseki /README.md
Last active Aug 29, 2015

What would you like to do?
vagrant-layout: Django

Vagrant Layout - Django

This is configuration of vagrant-layout plugin. Based on python layout.

Installation

$ vagrant plugin install vagrant-layout
$ mkdir my-project && cd my-project
$ vagrant layout init https://gist.github.com/koseki/b7670fc1576a3129e4f7

Double click sandbox/osx/manage/start.command or start.bat. Wait a while, and access http://localhost:8080/.

Feel free to fork and create your own layout.


base: https://github.com/koseki/vagrant-layout/commit/29afc290c04be3c138306bc302c315224e28b807

diff --git a/sandbox/Procfile b/sandbox/Procfile
index a60cbb3..768b5dc 100644
--- a/sandbox/Procfile
+++ b/sandbox/Procfile
@@ -1,2 +1,3 @@
nginx: ./bin/nginx.sh
+django: sh -c 'cd ../sample_app && python manage.py runserver'
error.log: tail -n 0 -f logs/error.log
diff --git a/sandbox/bin/boot.sh b/sandbox/bin/boot.sh
index 4c475b2..c37b362 100644
--- a/sandbox/bin/boot.sh
+++ b/sandbox/bin/boot.sh
@@ -1,8 +1,29 @@
#! /bin/sh
set -e
-cd `dirname $0`/..
+cd `dirname $0`/../..
+. $HOME/.virtualenv/python2.7/bin/activate
+
+# Remove these lines after creating application.
+if [ ! -d sample_app ]; then
+ mysql -u root -e 'create database sample_app default character set utf8'
+ django-admin startproject sample_app
+ cat <<'EOF' >> sample_app/sample_app/settings.py
+
+DATABASES = {
+ 'default': {
+ 'ENGINE': 'django.db.backends.mysql',
+ 'NAME': 'sample_app',
+ 'USER':'root',
+ 'PASSWORD':'',
+ 'HOST':'',
+ }
+}
+EOF
+fi
+
+cd sandbox
touch logs/error.log
./bin/shoreman
diff --git a/sandbox/bin/provision.sh b/sandbox/bin/provision.sh
index db25048..f6d9728 100755
--- a/sandbox/bin/provision.sh
+++ b/sandbox/bin/provision.sh
@@ -85,3 +85,13 @@ if [ $CURRENT_VERSION -lt $VERSION ]; then
echo $VERSION > $VERSION_FILE
fi
+
+VERSION=`expr $VERSION + 1`
+if [ $CURRENT_VERSION -lt $VERSION ]; then
+ echo "--- $VERSION: django ---"
+
+ sudo -u vagrant /home/vagrant/.virtualenv/python2.7/bin/pip install django
+ sudo -u vagrant /home/vagrant/.virtualenv/python2.7/bin/pip install mysql-python
+
+ echo $VERSION > $VERSION_FILE
+fi
diff --git a/sandbox/config/nginx.conf.src b/sandbox/config/nginx.conf.src
index a933399..619738f 100644
--- a/sandbox/config/nginx.conf.src
+++ b/sandbox/config/nginx.conf.src
@@ -30,9 +30,15 @@ http {
server_name project.local;
client_max_body_size 8M;
index index.html index.htm;
+ root PROJECT_ROOT/static/htdocs;
- location / {
- root PROJECT_ROOT/static/htdocs;
+ try_files $uri $uri/index.html @django;
+
+ location @django {
+ proxy_set_header X-Real-IP $remote_addr;
+ proxy_set_header X-Forwarded_For $proxy_add_x_forwarded_for;
+ proxy_set_header Host $http_host;
+ proxy_pass http://localhost:8000;
}
location /favicon.ico {
diff --git a/static/htdocs/index.html b/static/htdocs/index.html
deleted file mode 100644
index 1b3c9a8..0000000
--- a/static/htdocs/index.html
+++ /dev/null
@@ -1 +0,0 @@
-This is static/htdocs/index.html.
diff --git a/static/htdocs/test.html b/static/htdocs/test.html
new file mode 100644
index 0000000..1b3c9a8
--- /dev/null
+++ b/static/htdocs/test.html
@@ -0,0 +1 @@
+This is static/htdocs/index.html.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment