Skip to content
This repository was archived by the owner on Jul 28, 2021. It is now read-only.

Developer Guide

Abhijith Anilkumar edited this page Jun 25, 2017 · 1 revision

Setup

Django Application

See the Installation section to quickly setup the Django Application in your local system.

Elastic Search

The project uses django-haystack which supports Elastic Search 1.x and Elastic Search 2.x. Elastic Search 5.x is not supported yet. You can use either of them to get the App Store running.

Elastic Search can be installed by following the official installation instructions in the official website. To quickly setup Elastic Search, follow these steps :

  1. Install the latest OpenJDK. In CentOS, the following command can be used :
    $ sudo yum install java-1.8.0-openjdk.x86_64

  2. Get the rpm/deb package corresponding to the Elastic Search version that you choose using wget.

  3. Install Elastic Search using dpkg/rpm depending on the Linux Distribution used. For example :
    $ sudo dpkg -i elasticsearch-2.3.1.deb (Ubuntu)
    $ sudo rpm -ivh elasticsearch-2.3.1.rpm (CentOS)

  4. Once installation is complete, setup Elastic Search as a service : $ sudo systemctl daemon-reload
    $ sudo systemctl enable elasticsearch.service

  5. To modify Elastic Search clusters to suite your needs, you can edit the /etc/elasticsearch/elasticsearch.yml file. By default, this file comes with the default settings to run the search engine. If you are an advanced user, you can edit the details to suit your requirements.

  6. Start the Elastic Search service.
    $ sudo systemctl start elasticsearch

Integrating with the Django Application

  1. Modify the settings/base.py file to add the HAYSTACK_CONNECTIONS to connect django-haystack with Elastic Search. The settings are already included in the file, uncomment it depending on the verion of Elastic Search being used.
    For Elastic Search 1.x :
   HAYSTACK_CONNECTIONS = {
       'default': {
           'ENGINE': 'haystack.backends.elasticsearch_backend.ElasticsearchSearchEngine',
           'URL': 'http://127.0.0.1:9200/',
           'INDEX_NAME': 'haystack',
       },
   }

For Elastic Search 2.x :

   HAYSTACK_CONNECTIONS = {
       'default': {
           'ENGINE': 'haystack.backends.elasticsearch2_backend.Elasticsearch2SearchEngine',
           'URL': 'http://127.0.0.1:9200/',
           'INDEX_NAME': 'haystack',
       },
   }
  1. Make sure elasticsearch python package is installed in your virtual environment. You can check this by using the command :
    $ pip freeze
    The package will be installed if you have followed the installation instructions correctly.

  2. Build your search index using the command :
    $ python manage.py rebuild_index
    This should be executed inside the src/ directory.

  3. To update the search index periodically, a cron job should be created which is executed at regular intervals. update_index command of django-haystack can be used to update the search index.

Deployment

The website can be deployed using any standard webserver, Apache2, Nginx, etc. Here, we will explain how to deploy the website using gunicorn and nginx.

Setting up gunicorn

Here, we will demonstrate how to setup gunicorn on a CentOS 7 system. Setup with other linux distributions might vary slightly.

  1. Install gunicorn using the following command :
    pip install gunicorn
  2. To setup gunicorn as a service, edit the following file : /etc/systemd/system/gunicorn.service
  3. Sample setup :
[Unit]
Description=gunicorn daemon
After=network.target

[Service]
User=username
Group=nginx
WorkingDirectory=/<path-to-appstore>/ns-3-AppStore/src
ExecStart=/<path-to-appstore>/ns-3-AppStore/venv/bin/gunicorn --workers 3 --bind unix:/<path-to-appstore>/ns-3-AppStore/src/appstore.sock appstore.wsgi:application

[Install]
WantedBy=multi-user.target

  1. Now start gunicorn service and enable it :
sudo systemctl start gunicorn
sudo systemctl enable gunicorn

Setting up nginx

Here, we will demonstrate how to setup gunicorn on a CentOS 7 system. Setup with other linux distributions might vary slightly.

  1. Install nginx using the following command :
    sudo yum install nginx
  2. To setup nginx as a service, edit the following file : /etc/nginx/nginx.conf
  3. Sample nginx.conf file :
http {
    . . .

    include /etc/nginx/conf.d/*.conf;

    server {
    listen 80;
    server_name server_domain_or_IP;

    location = /favicon.ico { access_log off; log_not_found off; }
    location /static/ {
        root /<path-to-appstore>/ns-3-AppStore/site;
    }

    location / {
        proxy_set_header Host $http_host;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header X-Forwarded-Proto $scheme;
        proxy_pass http://unix:/<path-to-appstore>/ns-3-AppStore/src/appstore.sock;
    }
}

        . . .
  1. Now manage user permissions and test nginx configuration :
sudo usermod -a -G user nginx   
chmod 710 /home/user   
sudo nginx -t
  1. Now start nginx service and enable it :
sudo systemctl start nginx   
sudo systemctl enable nginx

Setup Django for Production

By default, the Django Project setup is suitable for development. For production deployment, several changes need to be made. The project uses Edge which provides a separate production settings file. That file is used by the wsgi application.

  1. Make sure that settings.production is being used inside the wsgi file.
  2. To render the static files properly, it needs to be collected in place. This can be done by the following command :
    $ python manage.py collectstatic
    NOTE : If you receive errors regarding static root, edit the manage.py file to use settings.production rather that settings.development.
  3. In the production settings, ALLOWED_HOSTS variable needs to be modified to allow the server_name/IP. Modify the variable in settings/production.py. For example :
    ALLOWED_HOSTS = ['ns-apps.ee.washington.edu']

By following the above instructions, a production deployment of the App Store can be created. If you have any issues during setup, please raise an issue or contact the contributors.

Clone this wiki locally