Initial app commit

This commit is contained in:
Felipe Martín 2015-06-02 23:35:27 +02:00
parent 2e5bd39557
commit 8b1d533c03
45 changed files with 428 additions and 0 deletions

6
.gitignore vendored
View File

@ -55,3 +55,9 @@ docs/_build/
# PyBuilder
target/
# Vagrant
.vagrant
# Virtualenv
.virtualenv

24
Vagrantfile vendored Normal file
View File

@ -0,0 +1,24 @@
# -*- mode: ruby -*-
# vi: set ft=ruby :
VAGRANTFILE_API_VERSION = "2"
Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
config.vm.define "globalwishlist-backend" do |web|
web.vm.box = "ubuntu/trusty64"
#web.vm.network "private_network", type: "dhcp"
web.vm.network "forwarded_port", guest: 22, host: 2201
web.vm.network "forwarded_port", guest: 8000, host: 8080
web.vm.provider "virtualbox" do |vb|
vb.customize ["modifyvm", :id, "--memory", "512"]
end
web.vm.provision "ansible" do |ansible|
ansible.limit = 'all'
ansible.playbook = "provision/playbook.yml"
ansible.inventory_path = "provision/hosts"
end
end
end

0
amiibofindr/__init__.py Normal file
View File

View File

View File

View File

@ -0,0 +1,102 @@
"""
Django settings for amiibofindr project.
Generated by 'django-admin startproject' using Django 1.8.2.
For more information on this file, see
https://docs.djangoproject.com/en/1.8/topics/settings/
For the full list of settings and their values, see
https://docs.djangoproject.com/en/1.8/ref/settings/
"""
# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
import os
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
# Quick-start development settings - unsuitable for production
# See https://docs.djangoproject.com/en/1.8/howto/deployment/checklist/
# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = '0101010101'
# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = True
ALLOWED_HOSTS = []
# Application definition
INSTALLED_APPS = (
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
)
MIDDLEWARE_CLASSES = (
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.auth.middleware.SessionAuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware',
'django.middleware.security.SecurityMiddleware',
)
ROOT_URLCONF = 'amiibofindr.urls'
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [],
'APP_DIRS': True,
'OPTIONS': {
'context_processors': [
'django.template.context_processors.debug',
'django.template.context_processors.request',
'django.contrib.auth.context_processors.auth',
'django.contrib.messages.context_processors.messages',
],
},
},
]
WSGI_APPLICATION = 'amiibofindr.wsgi.application'
# Database
# https://docs.djangoproject.com/en/1.8/ref/settings/#databases
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
}
}
# Internationalization
# https://docs.djangoproject.com/en/1.8/topics/i18n/
LANGUAGE_CODE = 'en-us'
TIME_ZONE = 'UTC'
USE_I18N = True
USE_L10N = True
USE_TZ = True
# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/1.8/howto/static-files/
STATIC_URL = '/static/'

View File

@ -0,0 +1,4 @@
# coding: utf-8
from __future__ import unicode_literals
from .base import *

21
amiibofindr/urls.py Normal file
View File

@ -0,0 +1,21 @@
"""amiibofindr URL Configuration
The `urlpatterns` list routes URLs to views. For more information please see:
https://docs.djangoproject.com/en/1.8/topics/http/urls/
Examples:
Function views
1. Add an import: from my_app import views
2. Add a URL to urlpatterns: url(r'^$', views.home, name='home')
Class-based views
1. Add an import: from other_app.views import Home
2. Add a URL to urlpatterns: url(r'^$', Home.as_view(), name='home')
Including another URLconf
1. Add an import: from blog import urls as blog_urls
2. Add a URL to urlpatterns: url(r'^blog/', include(blog_urls))
"""
from django.conf.urls import include, url
from django.contrib import admin
urlpatterns = [
url(r'^admin/', include(admin.site.urls)),
]

16
amiibofindr/wsgi.py Normal file
View File

@ -0,0 +1,16 @@
"""
WSGI config for amiibofindr project.
It exposes the WSGI callable as a module-level variable named ``application``.
For more information on this file, see
https://docs.djangoproject.com/en/1.8/howto/deployment/wsgi/
"""
import os
from django.core.wsgi import get_wsgi_application
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "amiibofindr.settings.local")
application = get_wsgi_application()

10
manage.py Executable file
View File

@ -0,0 +1,10 @@
#!/usr/bin/env python
import os
import sys
if __name__ == "__main__":
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "amiibofindr.settings")
from django.core.management import execute_from_command_line
execute_from_command_line(sys.argv)

View File

@ -0,0 +1,4 @@
# PostgreSQL config
postgresql_version: 9.3
postgresql_database_name: amiibofindr
postgresql_database_user: amiibofindr

View File

@ -0,0 +1,4 @@
---
postgresql_version: 9.3
postgresql_database_name: amiibofindr
postgresql_database_user: amiibofindr

4
provision/hosts Normal file
View File

@ -0,0 +1,4 @@
default ansible_ssh_host=127.0.0.1 ansible_ssh_user=vagrant ansible_ssh_port=2201
[localdev]
default

19
provision/playbook.yml Normal file
View File

@ -0,0 +1,19 @@
---
- name: Common Tasks
hosts: all
roles:
- system
- base
- python
- nodejs
- postgresql
- name: LocalDev Tasks
hosts: localdev
roles:
- app_localdev
- name: Production Tasks
hosts: production
roles:
- app_production

View File

@ -0,0 +1,9 @@
---
- name: Ensure (runserver) alias
lineinfile: dest=~/.bash_profile state=present line='alias runserver="python /vagrant/manage.py runserver 0.0.0.0:8000"'
- name: Ensure (runserver_plus) alias
lineinfile: dest=~/.bash_profile state=present line='alias runserver_plus="python /vagrant/manage.py runserver_plus 0.0.0.0:8000"'
- name: Ensure (shell) alias
lineinfile: dest=~/.bash_profile state=present line='alias shell="python /vagrant/manage.py shell"'
- name: Ensure (shell_plus) alias
lineinfile: dest=~/.bash_profile state=present line='alias shell_plus="python /vagrant/manage.py shell_plus"'

View File

@ -0,0 +1,15 @@
---
- name: Install requirements
pip: requirements=/vagrant/requirements/local.txt virtualenv=~/.virtualenv
sudo: yes
sudo_user: vagrant
# - name: Install nodejs requirements
# npm: path=/vagrant
# sudo: yes
# sudo_user: vagrant
- name: Ensure vagrant user have a .bash_profile
file: path=~/.bash_profile state=touch
- name: Ensure directory is changed on login
lineinfile: dest=~/.bash_profile state=present line='cd /vagrant'
- name: Ensure DJANGO_SETTINGS_MODULE environment variable
lineinfile: dest=~/.bash_profile state=present line='export DJANGO_SETTINGS_MODULE="local_settings"'

View File

@ -0,0 +1,5 @@
---
- include: python.yml
- include: postgresql.yml
- include: deploy.yml
- include: aliases.yml

View File

@ -0,0 +1,16 @@
---
- name: Ensure vagrant as postgresql user
postgresql_user: name=vagrant role_attr_flags=SUPERUSER
sudo_user: postgres
sudo: true
- name: Ensure database is present
postgresql_db: name={{ postgresql_database_name }} owner=vagrant
sudo: true
sudo_user: postgres
- name: Ensure vagrant database user is created
postgresql_user: db={{ postgresql_database_name }} name=vagrant password=NULL priv=ALL state=present
sudo_user: postgres
sudo: true
- name: Ensure vagrant user can access
lineinfile: dest=/etc/postgresql/{{ postgresql_version }}/main/pg_hba.conf state=present line='local all postgres trust'
sudo: true

View File

@ -0,0 +1,22 @@
---
# Check if virtualenv is created
- shell: if [ -e .virtualenv ]; then echo yes; else echo no; fi;
register: virtualenv_exists
always_run: True
sudo: true
sudo_user: vagrant
# Create virtualenv
- name: Ensure virtualenv is created
when: virtualenv_exists.stdout == 'no'
command: 'virtualenv .virtualenv'
sudo: true
sudo_user: vagrant
# Auto activate on ssh
- name: Ensure vagrant user have a .bash_profile
file: path=~/.bash_profile state=touch
sudo: true
sudo_user: vagrant
- name: Ensure virtualenv is enabled on login
lineinfile: dest=~/.bash_profile state=present line='. ~/.virtualenv/bin/activate'
sudo: true
sudo_user: vagrant

View File

@ -0,0 +1 @@
- include: ntp.yml

View File

@ -0,0 +1,2 @@
- name: restart ntp
service: name=ntp state=restarted

View File

@ -0,0 +1,2 @@
---
- include: ntp.yml

View File

@ -0,0 +1,8 @@
---
- name: ensure ntpd is at the latest version
apt: pkg={{ item }} state=latest
sudo: true
with_items:
- ntp
notify:
- restart ntp

View File

@ -0,0 +1,3 @@
---
- include: nodejs.yml
- include: tools.yml

View File

@ -0,0 +1,11 @@
---
- name: Ensure nodejs is installed
apt: pkg={{ item }} state=latest
sudo: true
with_items:
- nodejs
- npm
- name: Ensure symlink node to nodejs
file: src=/usr/bin/nodejs dest=/usr/bin/node state=link
sudo: true

View File

@ -0,0 +1,7 @@
---
- name: Ensure nodejs tools are installed
npm: name={{ item }} global=yes
sudo: true
with_items:
- grunt-cli
- bower

View File

@ -0,0 +1,3 @@
postgresql_database_name: amiibofindr
postgresql_database_user: amiibofindr
postgresql_database_port: 5432

View File

@ -0,0 +1,2 @@
---
- include: postgresql.yml

View File

@ -0,0 +1,4 @@
---
- name: start postgresql
service: name=postgresql state=started
sudo: yes

View File

@ -0,0 +1,7 @@
---
- name: Ensure database is created
postgresql_db: name={{ postgresql_database_name }}
encoding='UTF-8'
state=present
sudo_user: postgres
sudo: true

View File

@ -0,0 +1,9 @@
---
- name: Ensure the database user is present
postgresql_user: db={{ postgresql_database_name }} name={{ postgresql_database_user }} password=NULL priv=ALL state=present
sudo_user: postgres
sudo: true
- name: Ensure user dont have unnecesary privileges
postgresql_user: name={{ postgresql_database_user }} role_attr_flags=NOSUPERUSER,CREATEDB
sudo_user: postgres
sudo: true

View File

@ -0,0 +1,6 @@
- name: Install PostgreSQL libraries
apt: pkg=libpq-dev state=latest
sudo: true
- name: Install python psycopg2 library
apt: pkg=python-psycopg2 state=latest
sudo: true

View File

@ -0,0 +1,5 @@
---
- include: libs.yml
- include: postgresql.yml
- include: create_db.yml
- include: create_user.yml

View File

@ -0,0 +1,10 @@
---
- name: Install PostgreSQL
apt: pkg={{ item }} state=latest
sudo: true
with_items:
- postgresql
- postgresql-client
- postgresql-contrib
notify:
- start postgresql

View File

@ -0,0 +1,7 @@
---
- name: Ensure scrapping libraries are installed
apt: pkg={{ item }} state=latest
sudo: true
with_items:
- libxml2-dev
- libxslt1-dev

View File

@ -0,0 +1,4 @@
---
- include: libs.yml
- include: python.yml
- include: tools.yml

View File

@ -0,0 +1,9 @@
---
- name: Install python
apt: pkg={{ item }} state=latest
with_items:
- python
- python-dev
- python-pip
- python-virtualenv
sudo: true

View File

@ -0,0 +1,6 @@
---
- name: Ensure debug tools are installed
pip: name={{ item }}
sudo: true
with_items:
- ipdb

View File

@ -0,0 +1,6 @@
---
- name: Update and Upgrade
apt: update_cache=yes upgrade=dist
sudo: true
- include: tools.yml

View File

@ -0,0 +1,5 @@
---
- name: Ensure locale is en_US.UTF-8
lineinfile: dest=/etc/environment line=LANG=en_US.utf-8
lineinfile: dest=/etc/environment line=LC_ALL=en_US.utf-8
sudo: true

View File

@ -0,0 +1,11 @@
CREATE EXTENSION hstore;
CREATE OR REPLACE FUNCTION idx(anyarray, anyelement)
RETURNS int AS
$$
SELECT i FROM (
SELECT generate_series(array_lower($1,1),array_upper($1,1))
) g(i)
WHERE $1[i] = $2
LIMIT 1;
$$ LANGUAGE sql IMMUTABLE;

18
requirements/base.txt Normal file
View File

@ -0,0 +1,18 @@
# Base Django
Django==1.8.2
# Tasks
celery==3.1.18
django-celery==3.1.16
# Utils
django-extensions==1.5.5
# Model versioning
django-reversion==1.8.7
# Admin
django-suit==0.2.13
# NoSQL
redis==2.10.3

1
requirements/local.txt Normal file
View File

@ -0,0 +1 @@
-r base.txt