Skip to content

Commit c72678c

Browse files
author
David George
committed
initial commit
0 parents  commit c72678c

26 files changed

Lines changed: 387 additions & 0 deletions

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
2+
.vagrant
3+

Vagrantfile

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
# -*- mode: ruby -*-
2+
# vi: set ft=ruby :
3+
4+
# Vagrantfile API/syntax version. Don't touch unless you know what you're doing!
5+
VAGRANTFILE_API_VERSION = "2"
6+
7+
Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
8+
config.vm.box = "ubuntu/trusty64"
9+
10+
# local box
11+
config.vm.define :local, primary: true do |local|
12+
local.vm.box_url = "https://vagrantcloud.com/ubuntu/trusty64"
13+
local.vm.hostname = "local"
14+
15+
# Django runserver networking
16+
local.vm.network "forwarded_port", guest: 8888, host: 8888
17+
local.vm.network "forwarded_port", guest: 80, host: 8989
18+
local.vm.network "forwarded_port", guest: 4000, host: 4000
19+
20+
local.vm.provision "shell",
21+
path:"./scripts/server-setup.sh", args: ["dev", "vagrant"]
22+
23+
# VirtualBox Provider config
24+
local.vm.provider "virtualbox" do |vb|
25+
vb.customize ["modifyvm", :id, "--memory", "512"]
26+
end
27+
end
28+
29+
end

config/dev.sh

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#!/bin/bash
2+
# Dev environment-specific settings
3+
4+
DB_NAME="lecodetest"
5+
DB_USER="devuser"
6+
DB_PASS="devpass"

fabfile.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
from fabric.api import local
2+
3+
4+
def run_manage(command):
5+
local('/home/vagrant/.virtualenvs/le-code-test/bin/python /vagrant/testsite/manage.py %s' % command)
6+
7+
8+
def web():
9+
run_manage('runserver 0.0.0.0:8888')
10+
11+
def migrate():
12+
run_manage('migrate')
13+
14+
def make_migrations():
15+
run_manage('makemigrations')
16+
17+
def requirements():
18+
local('/home/vagrant/.virtualenvs/le-code-test/bin/pip install -r requirements.txt ')

requirements.txt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
Django==1.7.2
2+
ecdsa==0.11
3+
Fabric==1.10.1
4+
paramiko==1.15.2
5+
Pillow==2.7.0
6+
psycopg2==2.5.4
7+
pycrypto==2.6.1

scripts/server-setup-user.sh

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
#!/bin/bash
2+
# VirtualEnv and Django setup
3+
#
4+
# This is a distinct file as it's meant to be run as the primary user we SSH in as
5+
6+
# Grab the environment var, default to 'dev'
7+
ENV=${1-dev}
8+
# ... and pick up related vars
9+
source /vagrant/config/$ENV.sh
10+
11+
# Grab the user var, default to 'vagrant'
12+
USER=${2-vagrant}
13+
14+
echo -e "\033[0;34m > Running main-user setup script, with the following parameters:\033[0m"
15+
echo -e "\033[0;34m > Environment: $ENV\033[0m"
16+
echo -e "\033[0;34m > Main User: $USER\033[0m"
17+
18+
# Set up virtualenv directory for the user if required
19+
if [ ! -d /home/$USER/.virtualenvs ]; then
20+
echo -e "\033[0;31m > Creating .virtualenvs folder"
21+
mkdir /home/$USER/.virtualenvs
22+
fi
23+
24+
# write all the profile stuff for the user if required
25+
grep -q WORKON /home/$USER/.bashrc
26+
if [ $? -ne 0 ]; then
27+
echo -e "\033[0;31m > Updating profile file\033[0m"
28+
echo "export WORKON_HOME=~/.virtualenvs" >> /home/$USER/.bashrc
29+
echo "source /usr/local/bin/virtualenvwrapper.sh" >> /home/$USER/.bashrc
30+
echo "export PIP_VIRTUALENV_BASE=~/.virtualenvs" >> /home/$USER/.bashrc
31+
echo "workon le-code-test" >> /home/$USER/.bashrc
32+
echo "cd /vagrant/" >> /home/$USER/.bashrc
33+
fi
34+
35+
echo -e "\033[0;34m > Setting up virtualenv\033[0m"
36+
export WORKON_HOME=/home/$USER/.virtualenvs
37+
source /usr/local/bin/virtualenvwrapper.sh
38+
export PIP_VIRTUALENV_BASE=/home/$USER/.virtualenvs
39+
mkvirtualenv le-code-test
40+
workon le-code-test

scripts/server-setup.sh

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
#!/bin/bash
2+
# Server Setup
3+
#
4+
# Script to install all the requirements for the server-side part of the Infinity Health project
5+
6+
# Note that we may want to tighten it up a little for production - e.g. better DB user privs.
7+
8+
# Grab the environment var, default to 'dev'
9+
ENV=${1-dev}
10+
# ... and pick up related vars
11+
source /vagrant/config/$ENV.sh
12+
13+
# Grab the user var, default to 'vagrant'
14+
USER=${2-vagrant}
15+
16+
echo -e "\033[0;34m > Provisioning Vagrant server, with the following parameters:\033[0m"
17+
echo -e "\033[0;34m > Environment: $ENV\033[0m"
18+
echo -e "\033[0;34m > Main User: $USER\033[0m"
19+
20+
# Housekeeping
21+
apt-get update
22+
apt-get install -y git vim
23+
24+
# Python environment and tools
25+
apt-get install -y python-setuptools python2.7 build-essential python-dev libncurses5-dev fabric
26+
easy_install pip
27+
pip install virtualenv virtualenvwrapper
28+
29+
# Postgres DB setup
30+
apt-get install -y postgresql-9.3 postgresql-client-9.3 postgresql-server-dev-9.3
31+
echo -e "\033[0;34m > Setting up DB. If it already exists this will generate warnings, but no harm will be done.\033[0m"
32+
sudo -u postgres psql -c "CREATE DATABASE $DB_NAME ENCODING='UTF8' TEMPLATE=template0;"
33+
sudo -u postgres psql -c "CREATE USER $DB_USER WITH PASSWORD '$DB_PASS';"
34+
sudo -u postgres psql -c "GRANT ALL PRIVILEGES ON DATABASE $DB_NAME TO $DB_USER;"
35+
if [ $ENV == 'dev' -o $ENV == 'test' ]
36+
then
37+
sudo -u postgres psql -c "ALTER USER $DB_USER CREATEDB;"
38+
fi
39+
40+
echo -e "\033[0;34m > Installing all the image support libs for pillow.\033[0m"
41+
sudo apt-get install -y libjpeg62-dev zlib1g-dev libfreetype6-dev liblcms1-dev
42+
43+
# do the rest as the user we'll be logging in as through SSH
44+
chmod +x /vagrant/scripts/server-setup-user.sh
45+
sudo -u $USER /vagrant/scripts/server-setup-user.sh $ENV $USER
46+
47+
# install requirements
48+
echo -e "\033[0;34m > Installing the pip requirements.\033[0m"
49+
sudo -H -u vagrant /home/vagrant/.virtualenvs/le-code-test/bin/pip install -r /vagrant/requirements.txt

testsite/items/__init__.py

Whitespace-only changes.

testsite/items/admin.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
from django.contrib import admin
2+
3+
from models import PhotoItem, TweetItem
4+
5+
admin.site.register(PhotoItem)
6+
admin.site.register(TweetItem)
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
# -*- coding: utf-8 -*-
2+
from __future__ import unicode_literals
3+
4+
from django.db import models, migrations
5+
from django.conf import settings
6+
7+
8+
class Migration(migrations.Migration):
9+
10+
dependencies = [
11+
migrations.swappable_dependency(settings.AUTH_USER_MODEL),
12+
]
13+
14+
operations = [
15+
migrations.CreateModel(
16+
name='PhotoItem',
17+
fields=[
18+
('id', models.AutoField(verbose_name='ID', serialize=False, auto_created=True, primary_key=True)),
19+
('created_at', models.DateTimeField()),
20+
('image', models.ImageField(upload_to=b'')),
21+
('user', models.ForeignKey(to=settings.AUTH_USER_MODEL)),
22+
],
23+
options={
24+
'abstract': False,
25+
},
26+
bases=(models.Model,),
27+
),
28+
migrations.CreateModel(
29+
name='TweetItem',
30+
fields=[
31+
('id', models.AutoField(verbose_name='ID', serialize=False, auto_created=True, primary_key=True)),
32+
('created_at', models.DateTimeField()),
33+
('text', models.CharField(max_length=150)),
34+
('user', models.ForeignKey(to=settings.AUTH_USER_MODEL)),
35+
],
36+
options={
37+
'abstract': False,
38+
},
39+
bases=(models.Model,),
40+
),
41+
]

0 commit comments

Comments
 (0)