Skip to content

One of the interesting projects I have work on during summer 2014

Notifications You must be signed in to change notification settings

kimyu92/wc-code-sample

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

SWE Fun Project

Fifa World Cup'2014

General development environment setup:

  1. setup the environment below
  2. install dependencies
  3. setup db refer to postgres-kimchi-reference
  4. python manage.py runscripts generate-secret-key
  5. setup the SECRET_KEY environment
  6. run 3 data scripts eg. python manage.py runscripts insert-whatever-data
  7. python3 manage.py runserver 8000

Test model (Deprecated)

preq: setup the model mentioned above location: test_Model.py python3 manage.py test

Setup fulltext search with django-watson

  1. comment out app from settings.py
  2. since django 1.8 AppConfig is required and configured to app.apps.WorldCupWatsonConfig in INSTALLED_APP and init.py in app folder
  3. python manage.py buildwatson
  4. index should have been updated

Template debug on rendering html

{% load debug_tags %} 
  • eg. render to simulate the template rendering and available command such as details and variables
render('{% if item.magical %}A magical item {% endif %}')
  • caveat: iterable object have to be passed to html and eg of direct accessing list using VardotIndex

Python Environment

Mac

  1. brew install pyenv
  2. add below to .bash_profile
export PYENV_ROOT="$HOME/.pyenv"
export PATH="$PYENV_ROOT/bin:$PATH"
eval "$(pyenv init -)"
  1. brew install pyvenv
  2. pyenv install 3.4.3 (or any version)
  3. go to project directory and pyvenv my-env
  4. source my-env/bin/activate
  5. python or python3 --version should point to 3.4.3
  6. pip install -U pip

Ubuntu

  1. sudo apt-get install virtualenv
  2. virtualenv my-env -p /usr/bin/python3
  3. source my-env/bin/activate
  4. python --version
  5. pip install -U pip

Ultimate Deployment Gunicorn + Nginx

Quick command for testing

  1. gunicorn --bind 0.0.0.0:8000 myproject.wsgi:application

Gunicorn setup

  1. sudo vim /etc/init/gunicorn.conf
description "Gunicorn application server handling myproject"

start on runlevel [2345]
stop on runlevel [!2345]

respawn
setuid user
setgid www-data
chdir /home/user/myproject

exec myprojectenv/bin/gunicorn --workers 3 --bind unix:/home/user/myproject/myproject.sock myproject.wsgi:application
  1. sudo service gunicorn start

Nginx setup

  1. sudo vim /etc/nginx/sites-available/myproject
server {
    listen 80;
    server_name server_domain_or_IP;

    location = /favicon.ico { access_log off; log_not_found off; }
    location /static/ {
        root /home/user/myproject;
    }

    location / {
        include proxy_params;
        proxy_pass http://unix:/home/user/myproject/myproject.sock;
    }
}
  1. sudo ln -s /etc/nginx/sites-available/myproject /etc/nginx/sites-enabled
  2. sudo nginx -t # Test Nginx configuration for syntax errors
  3. sudo service nginx restart

Slim down version of deployment Gunicorn Daemon and Nginx

  • Setup everything and please do not use root user
* python manage.py collectstatic
* gunicorn worldcup.wsgi:application --bind=127.0.0.1:8001 --daemon
  • nginx setup like below on eg /etc/nginx/sites-enabled/worldcup
server {
  listen 80; 
  server_name server_ip_or_address_domain;
  location / { 
    proxy_pass http://127.0.0.1:8001;
  }

  location /static/ {
    alias /home/whateverUser...../swe-worldcup/src/worldcup/staticfiles/;
  }
}

Better? Deployment staticfiles with whitenoise in future

Dependencies

  1. Python 3.4+
  2. Django 1.8.7
  3. Postgres 9.4
  4. PyJade 3.1
  5. Twitter Bootstrap
  6. jQuery
  7. Gunicorn
  8. Nginx
  9. and more ...

Author:

  • Kim Yu Ng

About

One of the interesting projects I have work on during summer 2014

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published