Skip to content

Instantly share code, notes, and snippets.

@gnunicorn
Last active December 15, 2015 02:38
Show Gist options
  • Save gnunicorn/5188195 to your computer and use it in GitHub Desktop.
Save gnunicorn/5188195 to your computer and use it in GitHub Desktop.
*.pyc
AWS-ElasticBeanstalk-CLI*
bin/
lib/
man/
src/
include/
debug.sqlite

setup askbot on beanstalk

virtualenv setup

setup

$ mkdir askbot_on_bs
$ cd askbot_on_bs
$ git init .

create .gignore and add the following: .pyc AWS-ElasticBeanstalk-CLI bin/ lib/ man/ src/ include/ debug.sqlite

$ git add .
$ git ci -m"initial gitignore"


$ virtualenv .
$ source bin/activate
$ pip install Django==1.4.5 mysql-python
$ pip install -e git+git://github.com/ASKBOT/askbot-devel.git#egg=askbot
$ askbot-setup

-> choose 'mysite' as directory. choose mysql and name DB all to 'none', we'll be replacing it in just a second

commit it

$ git add .
$ git ci -m"intial askbot setup"

Change configuration to work on Beanstalk

Open settings.py and replace the Database setup with:

if LIVE:
    DATABASE_OPTIONS = {'init_command': 'SET storage_engine = MyISAM'}

    DATABASES = {
        'default': {
            'ENGINE': 'django.db.backends.mysql',
            'NAME': os.environ['RDS_DB_NAME'],
            'USER': os.environ['RDS_USERNAME'],
            'PASSWORD': os.environ['RDS_PASSWORD'],
            'HOST': os.environ['RDS_HOSTNAME'],
            'PORT': os.environ['RDS_PORT'],
            "OPTIONS": {
                'init_command': 'SET storage_engine = MyISAM'
            }
        }
    }
else:
    DEBUG = True
    DATABASES = {
        'default': {
            'ENGINE': 'django.db.backends.sqlite3',
            'NAME': 'debug.sqlite'
        }
    }

And you probably also want to set DEBUG = False on top (it is automatically re-activated with the database setup on non Beanstalk as you can see)

$ python manage.py syncdb
$ python manage.py migrate
$ python manage.py runserver

And then check at http://localhost:8000/ if it worked.

(if any of those give you a 'str_to_unicode'-error, you unintentionally installed django 1.5 - uninstall it and reinstall django 1.4.5 , see http://askbot.org/en/question/10016/error-importerror-cannot-import-name-str_to_unicode/)

commit it

$ git add .
$ git ci -m"intial askbot configuration"

Set requirements

$ pip freeze > requirements.txt

Open the file and make sure the the line for askbot looks like this (you probably have to replace it): -e git+git://github.com/ASKBOT/askbot-devel.git#egg=askbot

note: this applies to askbot <= 0.7.48 because there is a bug in those which do not let us migrate the database on the mysql-systems beanstalk will be setting up for us.

commit it

$ git add requirements.txt
$ git ci -m"add requirements"

fix django.wsgi for devel egg:

The default django.wsi doesn't have our devel in there. So open the file and replace the content with:

import os
import sys

current_directory = os.path.dirname(__file__)
parent_directory = os.path.dirname(current_directory)
module_name = os.path.basename(current_directory)

sys.path.append(parent_directory)
sys.path.append(os.path.join(parent_directory, 'src'))
sys.path.append(current_directory)
os.environ['DJANGO_SETTINGS_MODULE'] = '%s.settings' % module_name
import django.core.handlers.wsgi
application = django.core.handlers.wsgi.WSGIHandler()

commit it

AWS Beanstalk setup

$ wget https://s3.amazonaws.com/elasticbeanstalk/cli/AWS-ElasticBeanstalk-CLI-2.2.zip
$ unzip AWS-ElasticBeanstalk-CLI-2.2.zip
$ ln -s ../AWS-ElasticBeanstalk-CLI-2.2/eb/linux/python2.7/eb bin/eb

$ eb init

-> follow setup as described unter "to configure AWS elastic bean" at http://docs.aws.amazon.com/elasticbeanstalk/latest/dg/create_deploy_Python_django.html

start the beanstalk

$ eb start

that might takes a while ...

open .elasticbeanstalk/askbot.config (attached) and change the setup as follows:

packages:
  yum:
    git: []

container_commands:
  001_collectstatic:
    command: "python mysite/manage.py collectstatic --noinput"
  01_syncdb:
    command: "python mysite/manage.py syncdb --noinput"
    leader_only: true
  03_migrate:
    command: "python mysite/manage.py migrate "
    leader_only: true
    
option_settings:
  "aws:elasticbeanstalk:container:python":
    WSGIPath: mysite/django.wsgi
    NumProcesses: 3
    NumThreads: 20
  "aws:elasticbeanstalk:container:python:staticfiles":
    "/static/" : "mysite/static/"
  "aws:elasticbeanstalk:application:environment":
    "DJANGO_SETTINGS_MODULE": "settings"

commit it

$ git add .
$ git ci -m"intial askbot aws configuration"

deploy first version

To deploy on aws we can use git directly:

$ git aws.push

Further configuration

  • Coming soon

Email-Configuration

S3 for Statics

packages:
yum:
git: []
container_commands:
001_collectstatic:
command: "python mysite/manage.py collectstatic --noinput"
01_syncdb:
command: "python mysite/manage.py syncdb --noinput"
leader_only: true
03_migrate:
command: "python mysite/manage.py migrate "
leader_only: true
option_settings:
"aws:elasticbeanstalk:container:python":
WSGIPath: mysite/django.wsgi
NumProcesses: 3
NumThreads: 20
"aws:elasticbeanstalk:container:python:staticfiles":
"/static/" : "mysite/static/"
"aws:elasticbeanstalk:application:environment":
"DJANGO_SETTINGS_MODULE": "settings"
import os
import sys
current_directory = os.path.dirname(__file__)
parent_directory = os.path.dirname(current_directory)
module_name = os.path.basename(current_directory)
sys.path.append(parent_directory)
sys.path.append(os.path.join(parent_directory, 'src'))
sys.path.append(current_directory)
os.environ['DJANGO_SETTINGS_MODULE'] = '%s.settings' % module_name
import django.core.handlers.wsgi
application = django.core.handlers.wsgi.WSGIHandler()
Coffin==0.3.7
Django==1.4.5
Jinja2==2.6
South==0.7.6
Unidecode==0.04.12
akismet==0.2.0
amqp==1.0.9
amqplib==1.0.2
anyjson==0.3.3
beautifulsoup4==4.1.3
billiard==2.7.3.22
boto==2.8.0
celery==3.0.16
chardet==2.1.1
django-celery==3.0.11
django-countries==1.0.5
django-followit==0.0.3
django-keyedcache==1.4-6
django-kombu==0.9.4
django-picklefield==0.3.0
django-recaptcha-works==0.3.4
django-robots==0.9.1
django-storages==1.1.6
django-threaded-multihost==1.4-1
django-tinymce==1.5.1b4
mysql-python==1.2.3
html5lib==0.90
httplib2==0.8
kombu==2.5.7
lamson==1.3.4
lockfile==0.9.1
longerusername==0.4
markdown2==2.1.0
mock==1.0.1
nose==1.2.1
oauth2==1.5.211
pyparsing==1.5.7
pystache==0.3.1
python-daemon==1.6
python-dateutil==1.5
python-modargs==1.6
python-openid==2.2.5
pytz==2012j
sanction==0.3
six==1.2.0
wsgiref==0.1.2
-e git+git://github.com/ASKBOT/askbot-devel.git#egg=askbot
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment