Skip to content
This repository has been archived by the owner on Sep 19, 2024. It is now read-only.

Deployment Guide

Ashwin Shenoy edited this page Mar 8, 2019 · 13 revisions

Heroku Deployment

AWS Deployment

01. Server Configuration

A. Create AWS EC2 Instance & Connect to Server

  • Amazon EC2 Instance - 1GB RAM / Dedicated IP
  • OS: Ubuntu 18.04.2 LTS (GNU/Linux 4.15.0-1032-aws x86_64)
  • Download .pem key to access the server.
$ ssh -i "<FILE_NAME>.pem"  [email protected]

B. Install Requirments for GNU/Linux

$ sudo apt-get install binutils git libpq-dev python-dev python-setuptools python-virtualenv postgresql postgresql-contrib gdal-bin nginx supervisor memcached build-essential

C. Clone the Code

$ sudo git clone https://gitlab.com/amfoss/cms.git

02. Database Configuration

A. Create Application User

$ sudo su - postgres
postgres@ip-xxx-xx-xx-xxx: ~ $ createuser --interactive -P
Enter name of role to add: amfoss
Enter password for new role:
Enter it again:
Shall the new role be a superuser? (y/n) n
Shall the new role be allowed to create databases? (y/n) n
Shall the new role be allowed to create more new roles? (y/n) n

B. Create Database

postgres@ip-xxx-xx-xx-xxx: ~ $ createdb --owner=cms amfoss
postgres@ip-xxx-xx-xx-xxx: ~ $ logout

C. Set Directory Permissions

$ sudo groupadd --system amfoss
$ sudo useradd --system --gid amfoss --shell /bin/bash --home /var/www/cms/ amfoss

D. Set DB in Django Settings

Update the Database configuration in settings.py

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.postgresql_psycopg2',
        'NAME': 'cms',
        'USER': 'amfoss',
        'PASSWORD': '<YOUR PASSWORD HERE>',
        'HOST': 'localhost',
        'PORT': '',  # Set to empty string for default.
    }
}

03. Django Configuration

A. Create Virtual Environment

$ sudo su - amfoss
amfoss@ip-xxx-xx-xx-xxx:~$ cd /var/www/cms/
amfoss@ip-xxx-xx-xx-xxx: /var/www/cms $ virtualenv -p python3 .

B. Install Django Requirements

amfoss@ip-xxx-xx-xx-xxx: /var/www/cms $ source bin/activate
(cms) amfoss@ip-xxx-xx-xx-xxx: /var/www/cms $ pip install -r requirements.txt

C. Set Configuration Variables

Copy from sample environment configuration variables in .env.example, or create a new .env file, and update/add all configuration details

(cms) amfoss@ip-xxx-xx-xx-xxx: /var/www/cms $ cp .env.example .env

D. Make Database Migrations

(cms) amfoss@ip-xxx-xx-xx-xxx: /var/www/cms $ python manage.py migrate
(cms) amfoss@ip-xxx-xx-xx-xxx: /var/www/cms $ python manage.py makemigrations activity blog gsoc gallery pages members status
(cms) amfoss@ip-xxx-xx-xx-xxx: /var/www/cms $ python manage.py migrate

E. Collect Static Files

(cms) amfoss@ip-xxx-xx-xx-xxx: /var/www/cms $ python manage.py collectstatic

F. Test Virtual Environment

(cms) amfoss@ip-xxx-xx-xx-xxx: /var/www/cms $ python manage.py runserver 0.0.0.0:8000

04. Gunicorn Configuration

A. Open gunicorn_start in editor

(cms) amfoss@ip-xxx-xx-xx-xxx: /var/www/cms $ vim /var/www/cms/bin/gunicorn_start

B. Configure gunicorn_start

#!/bin/bash
NAME="framework"                          
DJANGODIR=/var/www/cms                   
SOCKFILE=/var/www/cms/run/gunicorn.sock   
USER=amfoss                                         
GROUP=amfoss                                       
NUM_WORKERS=5                                 
DJANGO_SETTINGS_MODULE=framework.settings      
DJANGO_WSGI_MODULE=framework.wsgi               

echo "Starting $NAME as `whoami`"

# Activate the virtual environment
cd $DJANGODIR
source ./bin/activate
export DJANGO_SETTINGS_MODULE=$DJANGO_SETTINGS_MODULE
export PYTHONPATH=$DJANGODIR:$PYTHONPATH

# Create the run directory if it doesn't exist
RUNDIR=$(dirname $SOCKFILE)
test -d $RUNDIR || mkdir -p $RUNDIR

# Start your Django Unicorn
# Programs meant to be run under supervisor should not daemonize themselves (do not use --daemon)
exec ./bin/gunicorn ${DJANGO_WSGI_MODULE}:application \
  --name $NAME \
  --workers $NUM_WORKERS \
  --user=$USER --group=$GROUP \
  --bind=unix:$SOCKFILE \
  --log-level=debug \
  --log-file=-

C. Run gunicorn_start

(cms) amfoss@ip-xxx-xx-xx-xxx: /var/www/cms $ /var/www/cms/bin/gunicorn_start

05. Superviser Configuration

B. Create the file to store log

$ mkdir -p /var/www/cms/logs/
$ touch /var/www/cms/logs/gunicorn_supervisor.log

C. Start App

$ sudo supervisorctl reread
amfoss: available
$ sudo supervisorctl update
amfoss: added process group

06. Ngnix Configuration

Clone this wiki locally