AWS Setup¶
Amazon Web Services (AWS) provides the preferred hosting for SEED.
seed is a Django project and Django’s documentation is an excellent place to general understanding of this project’s layout.
Pre-requisites¶
Ubuntu server 13.10 or newer, with the following list of aptitude packages
installed. prerequisites.txt
Copy the prerequisites.txt files to the server and install the dependencies:
$ sudo dpkg --set-selections < ./prerequisites.txt
$ sudo apt-get dselect-upgrade
or with a single command as su
# aptitude install $(cat ./prerequisites.txt | awk '{print $1}')
Note
postgresql server is not included above, and it is assumed that the system will use the AWS RDS postgresql service
Note
postgresql >=9.3
is required to support JSON Type
A smaller list of packages to get going:
$ sudo apt-get install python-pip python-dev libatlas-base-dev gfortran \
python-dev build-essential g++ npm libxml2-dev libxslt1-dev \
postgresql-devel postgresql-9.3 postgresql-server-dev-9.3 libpq-dev \
libmemcached-dev openjdk-7-jre-headless
Amazon Web Services (AWS) Dependencies¶
The following AWS services are used for seed:
- RDS (PostgreSQL >=9.3)
- ElastiCache (redis)
- SES
- S3
Python Dependencies¶
clone the seed repository from github
$ git clone git@github.com:SEED-platform/seed.git
enter the repo and install the python dependencies from requirements.txt
$ cd seed
$ sudo pip install -r requirements.txt
JavaScript Dependencies¶
npm
is required to install the JS dependencies. The bin/install_javascript_dependencies.sh
script will download all JavaScript dependencies and build them. bower
and
grunt-cli
will be installed globally by the
install_javascript_dependencies
script. The Ubuntu version 13.10
requires a cusomt install of nodejs/npm, and an install scrpt (
bin/node-and-npm-in-30s.sh
) is provided to download a stable release and
install npm
assuming the prerequisites are met.
$ sudo apt-get install build-essential
$ sudo apt-get install libssl-dev
$ sudo apt-get install curl
$ . bin/node-and-npm-in-30s.sh
$ bin/install_javascript_dependencies.sh
Database Configuration¶
Copy the local_untracked.py.dist
file in the config/settings
directory
to config/settings/local_untracked.py
, and add a DATABASES
configuration
with your database username, password, host, and port. Your database configuration
can point to an AWS RDS instance or a postgresql 9.3 database instance you have
manually installed within your infrastructure.
# Database
DATABASES = {
'default': {
'ENGINE':'django.db.backends.postgresql_psycopg2',
'NAME': 'seed',
'USER': '',
'PASSWORD': '',
'HOST': '',
'PORT': '',
}
}
Note
other databases could be used such as MySQL, but are not supported due to the postgres-specific JSON Type
In in the above database configuration, seed
is the database name, this
is arbitrary and any valid name can be used as long as the database exists.
create the database within the postgres psql
shell:
postgres-user=# CREATE DATABASE seed;
or from the command line:
$ createdb seed
create the database tables and migrations:
$ python manage.py syncdb
$ python manage.py migrate
Note
running migrations can be shortened into a one-liner ./manage.py syncdb
--migrate
create a superuser to access the system
$ python manage.py create_default_user --username=demo@example.com --organization=example --password=demo123
Note
Every user must be tied to an organization, visit /app/#/profile/admin
as the superuser to create parent organizations and add users to them.
cache and message broker¶
The SEED project relies on redis for both cache and message brokering, and
is available as an AWS ElastiCache service.
local_untracked.py
should be updated with the CACHES
and BROKER_URL
settings.
CACHES = {
'default': {
'BACKEND': 'redis_cache.cache.RedisCache',
'LOCATION': "seed-core-cache.ntmprk.0001.usw2.cache.amazonaws.com:6379",
'OPTIONS': { 'DB': 1 },
'TIMEOUT': 300
}
}
BROKER_URL = 'redis://seed-core-cache.ntmprk.0001.usw2.cache.amazonaws.com:6379/1'
Note
The popular memcached
can also be used as a cache back-end, but is not
supported and redis has a different cache key format, which could cause
breakage and isn’t tested.
Likewise, rabbitmq
or AWS SQS
are alternative message brokers,
which could cause breakage and is not tested.
running celery the background task worker¶
Celery is used for background tasks (saving data, matching, creating
projects, etc) and must be connected to the message broker queue. From the
project directory, celery
can be started:
$ python manage.py celery worker -B -c 2 --loglevel=INFO -E --maxtasksperchild=1000
running the development web server¶
The Django dev server (not for production use) can be a quick and easy way to get an instance up and running. The dev server runs by default on port 8000 and can be run on any port. See Django’s runserver documentation for more options.
$ python manage.py runserver
running a production web server¶
Our recommended web server is uwsgi sitting behind nginx. The
bin/start_uwsgi.sh
script can been created to start uwsgi
assuming
your Ubuntu user is named ubuntu
.
Also, static assets will need to be moved to S3 for production use. The
bin/post_compile
script contains a list of commands to move assets to S3.
$ bin/post_compile
$ bin/start_uwsgi
The following environment variables can be set within the ~/.bashrc
file to
override default Django settings.
export SENTRY_DSN=https://xyz@app.getsentry.com/123
export DEBUG=False
export ONLY_HTTPS=True