Last active
October 18, 2015 09:45
-
-
Save nathanielvarona/3d4bdcc7883bd1eaa101 to your computer and use it in GitHub Desktop.
DurianPy[3] IaaS and Paravirtualization | Application Deployment with DigitalOcean http://bit.ly/1VYN87j
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Adding a User and Assign a System Level Privileges | |
sudo adduser ubuntu | |
sudo adduser ubuntu sudo | |
sudo nano /etc/sudoers | |
# or | |
sudo /usr/sbin/visudo | |
# Then change the following | |
# %sudo ALL=(ALL:ALL) NOPASSWD: ALL |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Auto Loggin with Self Signed Certificates | |
# Client Side | |
# Generate Private and Public Key | |
ssh-keygen -t dsa | |
pbcopy < ~/.ssh/id_dsa.pub | |
# Server Side | |
# Add the Public Key to ~/.ssh/authorized_keys | |
mkdir ~/.ssh | |
cd ~/.ssh | |
nano authorized_keys |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Install OS Dependencies (Packages, Libraries, Compilers) | |
sudo apt-get update | |
sudo apt-get dist-upgrade | |
# Then Reboot before invoking this command | |
sudo apt-get install linux-headers-$(uname -r) make build-essential git | |
# Building/Compiling Python Source Dependencies | |
sudo apt-get install libssl-dev zlib1g-dev libbz2-dev libreadline-dev sqlite3 libsqlite3-dev python-dev | |
# Psycopg Package Building/Compiling with PostgreSQL Dependencies | |
sudo nano /etc/apt/source.list | |
# Then add this a the bottom of file | |
deb http://apt.postgresql.org/pub/repos/apt/ trusty-pgdg main | |
# Add the Repository Certificate | |
wget --quiet -O - https://www.postgresql.org/media/keys/ACCC4CF8.asc | sudo apt-key add -; sudo apt-get update | |
# Install the Postgres Server, Client, and Development Libraries | |
sudo apt-get install postgresql-9.3 postgresql-client-9.3 postgresql-server-dev-9.3 | |
# Nginx Building/Compiling Dependencies | |
sudo apt-get install build-essential libpcre3-dev libssl-dev | |
Create an Isolated Python Environment (Project, Platform) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Clone Python Environment | |
git clone git://github.com/yyuu/pyenv.git ~/.pyenv | |
cd ~/.pyenv/plugins | |
git clone https://github.com/andersoncardoso/pyenv-autoenv.git | |
git clone https://github.com/yyuu/pyenv-virtualenvwrapper.git |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Bash Profile | |
if [[ -d $HOME/.pyenv ]];then | |
export PYENV_ROOT="$HOME/.pyenv" | |
export PATH="$PYENV_ROOT/bin:$PATH" | |
if which pyenv > /dev/null; then eval "$(pyenv init -)"; fi | |
source $PYENV_ROOT/plugins/pyenv-autoenv/bin/pyenv-autoenv | |
pyenv virtualenvwrapper | |
fi | |
#Virtual Environment | |
export WORKON_HOME=/home/ubuntu/.virtualenvs | |
#Pip Downnlaod Cache | |
export PIP_DOWNLOAD_CACHE=/home/ubuntu/.pip |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Create an Isolated Python Version (Operating System) | |
# Install and Activate User Level Python Version | |
pyenv install 2.7.7 --verbose | |
pyenv local 2.7.7 | |
# Verifiy if Python Version was correctly Installed | |
python -c 'from distutils.sysconfig import get_python_lib; print(get_python_lib())' | |
# Output Result | |
# /home/ubuntu/.pyenv/versions/2.7.7/lib/python2.7/site-packages |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Create an Isolated Python Environment (Project, Platform) | |
# Make a Virtual Environment for your Application | |
mkvirtualenv utancart_fl010_py2777 | |
# Verify if Vertual Environment was correctly Installed | |
python -c 'from distutils.sysconfig import get_python_lib; print(get_python_lib())' | |
# Output Result | |
# /home/ubuntu/.virtualenvs/utancart_f010_py277/lib/python2.7/site-packages | |
# Structure your project | |
mkdir -p ~/utancart/{cfg,log} | |
cd ~/utancart | |
git clone https://github.com/ralphleyga/utan-cart.git src | |
# Install Project Requirements | |
pip install -r requirements.txt --verbose | |
# Verify if Project Requirements was correctly Installed | |
pip freeze | |
# Output Result | |
# Flask==0.10 | |
# Flask-SQLAlchemy==1.0 | |
# Jinja2==2.7.3 | |
# MarkupSafe==0.23 | |
# SQLAlchemy==0.9.6 | |
# Werkzeug==0.9.6 | |
# ipython==2.1.0 | |
# itsdangerous==0.24 | |
# psycopg2==2.5.3 | |
# requests==2.3.0 | |
# stripe==1.18.0 | |
# wsgiref==0.1.2 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Configure the Application (Application Server, Database) | |
# Create a PostgreSQL Database | |
sudo -u postgres createdb -E UTF8 -e durianpy_utancart_db | |
# Change Password | |
sudo -u postgres psql postgres | |
# Then at postgres=# | |
\password | |
# Enter new password: | |
# Enter it again: | |
# Configure your Application | |
nano ~/utancart/src/utan.py | |
# Change | |
DB_NAME = 'durianpy_utancart_db' | |
DB_USER = 'postgrespassword' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# nano /home/ubuntu/utancart/syncdb.py | |
#!/usr/bin/env python | |
import os | |
import readline | |
from pprint import pprint | |
from flask import * | |
from utan import * | |
os.environ['PYTHONINSPECT'] = 'True' | |
db.create_all() | |
exit() | |
#python syncdb.py |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# mkdir /home/ubuntu/utancart/cfg/vassals/ | |
# nano /home/ubuntu/utancart/cfg/vassals/utancart_app.ini | |
[uwsgi] | |
# variables | |
proj_name = utancart | |
envs_name = utancart_fl010_py277 | |
proj_dir = /home/ubuntu/%(proj_name) | |
proj_src = %(proj_dir)/src | |
envs_dir = /home/ubuntu/.virtualenvs/%(envs_name) | |
# config | |
home = %(envs_dir) | |
pythonpath = %(proj_src) | |
module = utan:app | |
socket = 0.0.0.0:3031 | |
processes = 1 | |
threads = 1 | |
harakiri = 60 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# nano /home/ubuntu/utancart/cfg/utancart.conf | |
# sudo /home/ubuntu/utancart/cfg/utancart.conf /etc/init/ | |
description "UtanCart uWSGI Emperor" | |
start on (filesystem and net-device-up IFACE=lo) | |
stop on runlevel [!2345] | |
respawn | |
env LOGTO=/home/ubuntu/utan/log/uwsgi.log | |
exec /home/ubuntu/.virtualenvs/utancart_fl010_py277/bin/uwsgi --emperor /home/ubuntu/utancart/cfg/vassals --master --uid ubuntu --gid ubuntu --logto $LOGTO |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Connect the Application to Web Server (Web Server) | |
# Clone, Building/Compiling NGINX from Source | |
mkdir ~/packages | |
cd ~/packages | |
git clone https://github.com/nginx/nginx.git | |
cd nginx | |
./configure | |
make | |
sudo make install | |
# Configure NGINX to Support Multiple DNS request (Multiple Application) | |
sudo mkdir /usr/local/nginx/sites-enabled/ | |
sudo nano /usr/local/nginx/conf/nginx.conf | |
# Add this inside `http` block | |
include /usr/local/nginx/sites-enabled/*; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# /home/ubuntu/utancart/cfg/nginx.conf | |
# sudo ln -s /home/ubuntu/utancart/cfg/nginx.conf /usr/local/nginx/sites-enabled/utancart | |
upstream utancart_application { | |
server 127.0.0.1:3031; | |
} | |
server { | |
server_name utancart.domain; | |
access_log /home/ubuntu/utancart/log/nginx.access.log; | |
error_log /home/ubuntu/utancart/log/nginx.error.log; | |
location / { try_files $uri @utancart; } | |
location @utancart { | |
include uwsgi_params; | |
uwsgi_pass utancart_application; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
sudo initctl start utancart | |
sudo initctl start nginx | |
sudo invoke-rc.d postgresql restart |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment