Skip to content

Instantly share code, notes, and snippets.

@datakop
Last active August 29, 2015 14:06
Show Gist options
  • Save datakop/20880a6adc98638bea6d to your computer and use it in GitHub Desktop.
Save datakop/20880a6adc98638bea6d to your computer and use it in GitHub Desktop.
Ramp up TROOD on vagrant.

Ramp up TROOD on vagrant.

vagrant - free and open-source software for creating and configuring virtual development environments. Get it from here.

Put vagrant file into root directory from the gist. Change --memory and --cpu if needed.

# On host
vagrant up
vagrant ssh

Basic installations

# On VM as vagrant
sudo apt-get update && sudo apt-get upgrade
sudo apt-get install curl vim git python-software-properties

Install oh-my-zsh

# On VM as vagrant
sudo apt-get install zsh
curl -L http://install.ohmyz.sh | sh
chsh -s /bin/zsh
# pass:vagrant
zsh # use zsh

Postgres

1. download

Create pgdg.list file and add deb http://apt.postgresql.org/pub/repos/apt/ precise-pgdg main

# On VM as vagrant
sudo echo "deb http://apt.postgresql.org/pub/repos/apt/ precise-pgdg main" >> \
/etc/apt/sources.list.d/pgdg.list

Add key to apt-get repository

# On VM as vagrant
wget --quiet -O - https://www.postgresql.org/media/keys/ACCC4CF8.asc | sudo apt-key add -
sudo apt-get update && sudo apt-get upgrade

2. install

# On VM as vagrant
sudo apt-get install postgresql-9.3

Change postgres user pass

# On VM as vagrant
sudo passwd postgres
# pass: postgres

3. create cluster

# On VM as vagrant
su postgres
# On VM as postgres
cd /var/lib/postgresql/9.3/main
mkdir /var/lib/postgresql/data
exit

4. update environment variables.

Append to PATH :/usr/lib/postgresql/9.3/bin and append from new line PGDATA="/var/lib/postgresql/data" in /etc/environment file.

# On VM as vagrant
sudo vim /etc/environment

5. cluster initialization

su postgres
initdb
exit

6. update psql config

Comment (add #) in /etc/postgresql/9.3/main/postgresql.conf following lines:

data_directory = '/var/lib/postgresql/9.1/main

hba_file = '/etc/postgresql/9.1/main/pg_hba.conf

ident_file = '/etc/postgresql/9.1/main/pg_ident.conf

external_pid_file = '/var/run/postgresql/9.1-main.pid

# On VM as vagrant
sudo vim /etc/postgresql/9.3/main/postgresql.conf

6. make psql run on vm stratup

Add su -c 'pg_ctl start' postgres line before 'exit'

# On VM as vagrant
sudo vim /etc/rc.local
exit

7. restart vagrant

# On HOST
vagrant halt
vagrant up
vagrant ssh

8. Make psql dbs UTF-8 encoded

Got from http://stackoverflow.com/a/17565205/1094316

a. Create a file:

# On VM as vagrant
sudo vim /etc/profile.d/lang.sh

b. Add the following:

export LANGUAGE="en_US.UTF-8"

export LANG="en_US.UTF-8"

export LC_ALL="en_US.UTF-8"

c. Restart shell

# On VM as vagrant
zsh

d. Reconfigure psql template so the encoding can be UTF8:

# On VM as vagrant
su postgres
# On VM as postgres
psql

In psql console execute following:

# In psql console
update pg_database set datistemplate=false where datname='template1';
drop database Template1;
create database template1 with owner=postgres encoding='UTF-8'

  lc_collate='en_US.utf8' lc_ctype='en_US.utf8' template template0;

update pg_database set datistemplate=true where datname='template1';
\q
exit

TROOD configurations

Create TROOD db

  1. Login to psql console
# On VM as vagrant
psql -U postgres
  1. In psql console execute following:
# In psql console
create database trood;
\l+
\q

All rows of trood db should be UTF-8.

Install trood dependencies

# On VM as vagrant
sudo apt-get install python-virtualenv
sudo apt-get install postgresql-server-dev-9.3
sudo apt-get install python-dev
sudo apt-get install libtiff4-dev libjpeg8-dev zlib1g-dev libfreetype6-dev liblcms2-dev libwebp-dev tcl8.5-dev tk8.5-dev python-tk

sudo apt-add-repository ppa:chris-lea/node.js
sudo apt-get update && sudo apt-get upgrade
sudo apt-get install nodejs

Ramp-up environment

# On VM as vagrant
cd /vagrant
# On VM as vagrant
./buildenv.sh

OR if you want to ramp-up environment out of the project:

# On VM as vagrant
cd
virtualenv .env
./.env/bin/pip install --upgrade -r /vagrant/requirements.txt
cd /vagrant
mkdir -p node_modules
npm install less
# On VM as vagrant
. ./.env/bin/activate

or

# On VM as vagrant
. ~/.env/bin/activate

Replace 'default' base in local_dev.py file with:

'default': {
    'ENGINE': 'django.db.backends.postgresql_psycopg2',
    'NAME': 'trood',
    'HOST': 'localhost',
    'USER': 'postgres',
    'PASSWORD': 'postgres',
    'PORT': '',
}

Sync and run server:

# On VM as vagrant
fab sync
python manage.py runserver 0.0.0.0:8000

Go to 127.0.0.1:8080 on HOST and get the app, congrats!

How to load dump data

To load dump data into db use following commands:

I. Kill/Drop the base:

psql -U postgres
drop database trood;
create database trood;
\q

II. Load dump:

psql trood -U postgres -f trood.schema.sql
psql trood -U postgres -f trood.data.sql

Articles:

https://www.vagrantup.com/downloads https://github.com/dotless-de/vagrant-vbguest https://docs.vagrantup.com/v2/getting-started/index.html

http://hexvolt.blogspot.ru/2012/11/postgresql-91-ubuntu-1204.html http://www.postgresql.org/download/linux/ubuntu/ http://stackoverflow.com/a/17565205/1094316

created by Boris Kopin with dillinger.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment