Introduction
Building an REST API with Django using Vagrant and Puppet or standalone on Ubuntu 14.04.
Without vagrant
- Install mysql server
- Install python and pip
- Install virtualenv and virtualenvwrapper
- Create a virtualenv
- Activate the virtualenv with the following command
source (virtualenv)/bin/activate
- Run the command:
pip install -r puppet/provision/modules/language/files/local.txt
- Verify all the packages with yolk:
yolk -l
- Modify manage.py like 'Run the application' section
Using Vagrant
Prerequisites
Modules for puppet:
- puppetlabs-apache v1.5.0
- puppetlabs-apt v2.1.1
- puppetlabs-mysql v3.4.0
- puppetlabs-reboot v1.1.0
To install puppet modules, execute the following command:
puppet module install puppetlabs-apache
puppet module install puppetlabs-apt
puppet module install puppetlabs-mysql
puppet module install puppetlabs-reboot
To install vagrant plugins, execute the following command:
vagrant plugin install vagrant-bindfs
vagrant plugin install vagrant-puppet-install
vagrant plugin install vagrant-vbguest
Getting Started
This is a fairly simple project to get up and running. The procedure for starting up is as follows:
- Clone the project. (There’s only master branch.)
- Modify parameters in config.yaml such as:
- USER
- PASSWORD
- PROJECT
- DOMAIN_NAME
- HOSTNAME
- public_ip according your network connection.
- Run the command
vagrant up
from the directory
For standalone configuration: 4. Open your browser to http://localhost:8000 For vagrant configuration: 4. Open your browser to http://localhost:9834
Run the application
- Modify the following line at manage.py:
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "agenda.settings")
For local development:os.environ.setdefault("DJANGO_SETTINGS_MODULE", "agenda.settings.local")
For production:os.environ.setdefault("DJANGO_SETTINGS_MODULE", "agenda.settings.production")
For changing this manual change, we need to use virtualenvwrapper.
-
For running the application the first time:
python manage.py migrate
-
For running django server
python manage.py runserver 0.0.0.0:8000
Heroku Deployment Supported
Added the require files to deploy on Heroku:
requirements.txt
Procfile
On Heroku:
heroku config:set DJANGO_SETTINGS_MODULE=agenda.settings.production
Config mysql database:
heroku addons:create cleardb:ignite
heroku config | grep CLEARDB_DATABASE_URL
Copy the message result:
heroku config:set DATABASE_URL='mysql://xxxxxxxx:yyyyyy@zzzzzzzz/heroku_db?reconnect=true'
Create super user:
heroku run python manage.py createsuperuser