Skip to content

Commit 4414f32

Browse files
author
Pierre Guillemot
committed
Moving code to github
0 parents  commit 4414f32

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

78 files changed

+3996
-0
lines changed

.gitignore

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

CHANGELOG

Whitespace-only changes.

README

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
# Ideas
2+
3+
## How to
4+
5+
* Launch the VM and provision it: `vagrant up ideas`
6+
* SSH into the VM: `vagrant ssh ideas`
7+
* Load the virtualenv: `source env/bin/activate`
8+
* Initialize the db: `python manage.py migrate`
9+
* Launch the app: `python manage.py runserver 0.0.0.0:8000`
10+
* Access the application on your host browser: http://localhost:8000/ideas for development
11+
* Access the application on your host browser: http://192.168.33.10/ideas/ for production
12+
* Make sure the supervisor job is running: `sudo supervisorctl start ideas`
13+
* The port 80 is not forwarded to the host, so you need to use the machine IP
14+
* Create a super user: `python manage.py createsuperuser`
15+
* Access the DB: sudo su postgres && psql && \c ideas && \d && \q
16+
17+
## Oauth login
18+
19+
This application supports Facebook and Google login, you need to export the keys and secrets:
20+
21+
```
22+
export IDEAS_FACEBOOK_KEY='facebook-key'
23+
export IDEAS_FACEBOOK_SECRET='facebook-secret'
24+
export IDEAS_GOOGLE_KEY='google-key'
25+
export IDEAS_GOOGLE_SECRET='google-secret'
26+
```
27+
28+
## Webapp access
29+
30+
The port 8000 is forwarded to the host, you HAVE to access the website using this URL: `http://localhost:8000` otherwise the login won't work
31+
32+
## EC2 deployment
33+
34+
## Provisioning the machine
35+
36+
* `ssh -i aws-key.pem [email protected]`
37+
* `export AWS_ACCESS_KEY="..."`
38+
* `export AWS_SECRET_KEY="..."`
39+
* `ansible-playbook -i inventory --sudo playbook-ec2.yml --ask-sudo-pass`
40+
41+
## Jenkins job
42+
43+
This is not a best practice, as we should use parameterized jobs to deploy on different environments,
44+
but I am using a deployment/ folder at the root of the project, which contains 'live' configurations.
45+
Here is the jenkins job to deploy the application:
46+
47+
```
48+
#!/bin/bash
49+
cd /opt/ideas
50+
virtualenv env --no-site-package
51+
source env/bin/activate
52+
pip install -r requirements.txt
53+
pip install gunicorn
54+
cp deployment/settings.py ideas/ideas/settings.py
55+
cp deployment/gunicorn_config.py env
56+
cd ideas
57+
python manage.py migrate
58+
sudo service nginx restart
59+
sudo supervisorctl restart ideas
60+
```
61+
62+
## Unit tests
63+
64+
Run the following command: `python manage.py test`
65+
66+
## TODO
67+
68+
### INFRA
69+
70+
* Enable production mode (http://stackoverflow.com/questions/5836674/why-does-debug-false-setting-make-my-django-static-files-access-fail)
71+
* Use the normal workspace and THEN move the package to /opt
72+
* Create parameterized builds and use templating instead of hardcoded deployment/
73+
* Investigate the use of loggers (rsyslog impl)
74+
75+
### FEATURES
76+
77+
* Functionnal tests (https://docs.djangoproject.com/en/1.8/intro/tutorial05/)
78+
* Fix the admin pages CSS
79+
* Change index title (should not be 10, but 8)
80+
* Add '*' next to compulsory fields on the form page
81+
* Add a cancel button (go back to previous page) on the form page
82+
* Add a Delete Idea feature in the action bar of the details page
83+
* Add the tag feature (postgres text array + api)
84+
* Use purecss, jquery and quill libs locally (so that later we can minify them)

Vagrantfile

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
# -*- mode: ruby -*-
2+
# vi: set ft=ruby :
3+
VAGRANTFILE_API_VERSION = "2"
4+
Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
5+
config.vm.box = "https://cloud-images.ubuntu.com/vagrant/trusty/current/trusty-server-cloudimg-amd64-vagrant-disk1.box"
6+
config.ssh.insert_key = false
7+
config.vm.provider :virtualbox do |v|
8+
v.name = "ideas"
9+
v.memory = 1024
10+
v.cpus = 2
11+
v.customize ["modifyvm", :id, "--natdnshostresolver1", "on"]
12+
v.customize ["modifyvm", :id, "--ioapic", "on"]
13+
end
14+
config.vm.hostname = "ideas"
15+
config.vm.network :private_network, ip: "192.168.33.10"
16+
config.vm.network "forwarded_port", guest: 8000, host: 8000
17+
# Set the name of the VM. See: http://stackoverflow.com/a/17864388/100134
18+
config.vm.define :ideas do |ideas|
19+
end
20+
# Ansible provisioner.
21+
config.vm.provision "ansible" do |ansible|
22+
ansible.playbook = "provisioning/playbook.yml"
23+
ansible.inventory_path = "provisioning/inventory"
24+
ansible.sudo = true
25+
end
26+
end

deployment/gunicorn_config.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
command = '/opt/ideas/env/bin/gunicorn'
2+
pythonpath = '/opt/ideas/ideas'
3+
bind = '127.0.0.1:8000'
4+
workers = 3
5+
user = 1000

deployment/settings.py

Lines changed: 138 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,138 @@
1+
"""
2+
Django settings for ideas project.
3+
4+
Generated by 'django-admin startproject' using Django 1.8.4.
5+
6+
For more information on this file, see
7+
https://docs.djangoproject.com/en/1.8/topics/settings/
8+
9+
For the full list of settings and their values, see
10+
https://docs.djangoproject.com/en/1.8/ref/settings/
11+
"""
12+
13+
# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
14+
import os
15+
16+
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
17+
18+
19+
# Quick-start development settings - unsuitable for production
20+
# See https://docs.djangoproject.com/en/1.8/howto/deployment/checklist/
21+
22+
# SECURITY WARNING: keep the secret key used in production secret!
23+
SECRET_KEY = 'm_wfyp(q^!$7&p)4*p@jzhwiz-yvicsp19q&fplcbgd+2ftq(s'
24+
25+
# SECURITY WARNING: don't run with debug turned on in production!
26+
# In production, set DEBUG = False as well as the ALLOWED_HOSTS
27+
DEBUG = True
28+
29+
ALLOWED_HOSTS = []
30+
31+
32+
# Application definition
33+
34+
INSTALLED_APPS = (
35+
'django.contrib.admin',
36+
'django.contrib.auth',
37+
'django.contrib.contenttypes',
38+
'django.contrib.sessions',
39+
'django.contrib.messages',
40+
'django.contrib.staticfiles',
41+
'social.apps.django_app.default',
42+
'idea',
43+
'users',
44+
)
45+
46+
AUTHENTICATION_BACKENDS = (
47+
'social.backends.facebook.FacebookOAuth2',
48+
'social.backends.google.GoogleOAuth2',
49+
'django.contrib.auth.backends.ModelBackend',
50+
)
51+
52+
MIDDLEWARE_CLASSES = (
53+
'django.contrib.sessions.middleware.SessionMiddleware',
54+
'django.middleware.common.CommonMiddleware',
55+
'django.middleware.csrf.CsrfViewMiddleware',
56+
'django.contrib.auth.middleware.AuthenticationMiddleware',
57+
'django.contrib.auth.middleware.SessionAuthenticationMiddleware',
58+
'django.contrib.messages.middleware.MessageMiddleware',
59+
'django.middleware.clickjacking.XFrameOptionsMiddleware',
60+
'django.middleware.security.SecurityMiddleware',
61+
)
62+
63+
ROOT_URLCONF = 'ideas.urls'
64+
65+
TEMPLATES = [
66+
{
67+
'BACKEND': 'django.template.backends.django.DjangoTemplates',
68+
'DIRS': [],
69+
'APP_DIRS': True,
70+
'OPTIONS': {
71+
'context_processors': [
72+
'django.template.context_processors.debug',
73+
'django.template.context_processors.request',
74+
'django.contrib.auth.context_processors.auth',
75+
'django.contrib.messages.context_processors.messages',
76+
],
77+
},
78+
},
79+
]
80+
81+
TEMPLATES_CONTEXT_PROCESSORS = (
82+
'social.apps.django_app.context_processors.backends',
83+
'social.apps.django_app.context_processors.login_redirect',
84+
)
85+
86+
WSGI_APPLICATION = 'ideas.wsgi.application'
87+
88+
89+
# Database
90+
# https://docs.djangoproject.com/en/1.8/ref/settings/#databases
91+
DATABASES = {
92+
'default': {
93+
'ENGINE': 'django.db.backends.postgresql_psycopg2',
94+
'NAME': 'ideas',
95+
'USER': 'ideas_user',
96+
'PASSWORD': 'ideas_user',
97+
'HOST': 'localhost',
98+
'PORT': '',
99+
}
100+
}
101+
102+
103+
# Internationalization
104+
# https://docs.djangoproject.com/en/1.8/topics/i18n/
105+
106+
LANGUAGE_CODE = 'en-us'
107+
108+
TIME_ZONE = 'UTC'
109+
110+
USE_I18N = True
111+
112+
USE_L10N = True
113+
114+
USE_TZ = True
115+
116+
117+
# Static files (CSS, JavaScript, Images)
118+
# https://docs.djangoproject.com/en/1.8/howto/static-files/
119+
120+
STATIC_URL = '/static/'
121+
122+
STATICFILES_DIRS = (
123+
os.path.join(BASE_DIR, 'static'),
124+
)
125+
126+
# This URL get called when the user tries to access a URL which requires
127+
# authentication.
128+
LOGIN_URL = '/users/login'
129+
130+
# Facebook App secret settings from the dashboard
131+
SOCIAL_AUTH_FACEBOOK_KEY = os.environ.get('IDEAS_FACEBOOK_KEY', '')
132+
SOCIAL_AUTH_FACEBOOK_SECRET = os.environ.get('IDEAS_FACEBOOK_SECRET', '')
133+
134+
# Google App secret settings
135+
SOCIAL_AUTH_GOOGLE_OAUTH2_KEY = os.environ.get('IDEAS_GOOGLE_KEY', '')
136+
SOCIAL_AUTH_GOOGLE_OAUTH2_SECRET = os.environ.get('IDEAS_GOOGLE_SECRET', '')
137+
138+
USE_X_FORWARDED_HOST = True

ideas/idea/__init__.py

Whitespace-only changes.

ideas/idea/admin.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
from django.contrib import admin
2+
from idea.models import Category
3+
4+
admin.site.register(Category)

0 commit comments

Comments
 (0)