Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,6 @@ venv
.idea

students/data.sqlite

# vagrant
.vagrant
16 changes: 16 additions & 0 deletions Vagrantfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# -*- mode: ruby -*-
# vi: set ft=ruby :

VAGRANTFILE_API_VERSION = "2"

Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
config.vm.box_url = "https://cloud-images.ubuntu.com/vagrant/precise/current/precise-server-cloudimg-i386-vagrant-disk1.box"
config.vm.box = "precise64"

# Create a private network, which allows host-only access to the machine
# using a specific IP.
config.vm.network "private_network", ip: "192.168.10.11"

# Setup web server
config.vm.provision "shell", path: 'install_script.sh', args: '/vagrant', privileged: false
end
27 changes: 27 additions & 0 deletions install_script.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#!/bin/bash

# install web server dependencies
sudo apt-get update
sudo apt-get -y install python python-virtualenv nginx supervisor

# install application (source location in $1)
mkdir /home/vagrant/student
cp -R $1/student/* /home/vagrant/student/

# create a virtualenv and install dependencies
virtualenv /home/vagrant/student/venv
/home/vagrant/student/venv/bin/pip install -r /home/vagrant/student/requirements.txt

# configure supervisor
sudo cp /vagrant/student.conf /etc/supervisor/conf.d/
sudo mkdir /var/log/student
sudo supervisorctl reread
sudo supervisorctl update

# configure nginx
sudo cp /vagrant/student.nginx /etc/nginx/sites-available/student
sudo rm -f /etc/nginx/sites-enabled/default
sudo ln -s /etc/nginx/sites-available/student /etc/nginx/sites-enabled/
sudo service nginx restart

echo Application deployed to http://192.168.10.11/
9 changes: 9 additions & 0 deletions student.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
; supervisor configuration

[program:student]
command=/home/vagrant/student/venv/bin/gunicorn -b 127.0.0.1:5000 -w 4 --chdir /home/vagrant/student --log-file - student:app
user=vagrant
autostart=true
autorestart=true
stderr_logfile=/var/log/student/stderr.log
stdout_logfile=/var/log/student/stdout.log
21 changes: 21 additions & 0 deletions student.nginx
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# nginx reverse proxy configuration

server {
listen 80;
server_name _;
access_log /var/log/nginx/student.access.log;
error_log /var/log/nginx/student.error.log;
location / {
proxy_pass http://127.0.0.1:5000;
proxy_redirect off;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
location /static {
alias /home/vagrant/student/static;
}
location /favicon.ico {
alias /home/vagrant/student/static/favicon.ico;
}
}