Last active
March 12, 2017 02:26
-
-
Save cstrap/ed7eaeec0594f8e05abe to your computer and use it in GitHub Desktop.
Python, virtualenvwrapper, pyenv and PostgreSQL - Vagrantfile
This file contains hidden or 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
# -*- mode: ruby -*- | |
# vi: set ft=ruby : | |
Vagrant.configure(2) do |config| | |
config.vm.box = "ubuntu/trusty64" | |
config.vm.box_check_update = false | |
config.vm.hostname = 'brespio.local' | |
config.vm.network "private_network", type: "dhcp" | |
config.vm.synced_folder '.', '/vagrant', nfs: true | |
# PostgreSQL | |
config.vm.network "forwarded_port", guest: 5432, host: 5432 | |
# Apps | |
(8000..8050).each do |port| | |
config.vm.network "forwarded_port", guest: "#{port}", host: "#{port}" | |
end | |
config.vm.provider "virtualbox" do |vb| | |
vb.memory = "2048" | |
vb.name = "PythonDev" | |
end | |
$script = <<SCRIPT | |
#!/bin/bash | |
echo "Distro packages update" | |
sudo apt-get update | |
sudo apt-get install -y python-virtualenv virtualenvwrapper git mercurial build-essential python-dev zlib1g-dev \ | |
zlib1g zlibc libtool libffi-dev libssl-dev libpq-dev libgeoip-dev libxml2-dev libxslt1-dev libbz2-dev \ | |
libsqlite3-dev libreadline-dev libjpeg-dev postgresql postgresql-contrib postgresql-client | |
echo "Configuring virtualenvwrapper ..." | |
printf '\n%s\n%s\n%s\n%s\n%s\n%s\n%s\n' 'export PIP_REQUIRE_VIRTUALENV=true' \ | |
'export WORKON_HOME=/vagrant/.virtualenvs' \ | |
'export PROJECT_HOME=/vagrant' \ | |
'export VIRTUALENVWRAPPER_PYTHON=/usr/bin/python' \ | |
'export VIRTUALENVWRAPPER_VIRTUALENV=/usr/bin/virtualenv' \ | |
'source /usr/share/virtualenvwrapper/virtualenvwrapper.sh' >> /home/vagrant/.bashrc | |
echo "Setting aliases" | |
echo "alias pippa='pip install -r requirements.txt -U --allow-all-external --process-dependency-links --trusted-host bitbucket.org --trusted-host github.com --no-cache-dir'" >> /home/vagrant/.bashrc | |
echo "alias pipssl='pip install -U pip pyopenssl'" >> /home/vagrant/.bashrc | |
echo "alias pip-outdated='pip list --outdated'" | |
echo "Python environment settings" | |
echo "export PYTHONDONTWRITEBYTECODE=true" >> /home/vagrant/.bashrc | |
echo "rmpyc='find . -type f -name "*.pyc" -print -delete'" >> /home/vagrant/.bashrc | |
echo "Installing pyenv ..." | |
export PYENV_ROOT="/home/vagrant/.pyenv" | |
curl -sL https://raw.githubusercontent.com/yyuu/pyenv-installer/master/bin/pyenv-installer | bash &> /dev/null | |
chown -R vagrant.vagrant /home/vagrant/.pyenv/ | |
printf '\n%s\n%s\n%s' 'export PATH="/home/vagrant/.pyenv/bin:$PATH"' \ | |
'eval "$(pyenv init -)"' \ | |
'# eval "$(pyenv virtualenv-init -)"' >> /home/vagrant/.bashrc | |
echo "Configurint PostgreSQL" | |
PG_CONF="/etc/postgresql/9.3/main/postgresql.conf" | |
PG_HBA="/etc/postgresql/9.3/main/pg_hba.conf" | |
echo "listen_addresses = '*'" >> "$PG_CONF" | |
echo "client_encoding = utf8" >> "$PG_CONF" | |
echo "host all all all md5" >> "$PG_HBA" | |
echo "======================================================================" | |
echo "| Remember to configure PostgreSQL |" | |
echo "======================================================================" | |
echo "In a terminal type:" | |
echo "$ sudo -u postgres psql postgres" | |
echo "Set a password for the postgres database role using the command:" | |
echo "psql# \password postgres" | |
echo "Then exit and grant all to vagrant user" | |
echo "sudo -u postgres createuser --superuser vagrant" | |
echo "======================================================================" | |
echo "Create an $USER" | |
echo "======================================================================" | |
echo "$ sudo -u postgres createuser --superuser $USER" | |
echo "$ sudo -u postgres psql" | |
echo "postgres=# \password $USER" | |
echo "Doc: https://help.ubuntu.com/community/PostgreSQL" | |
echo "======================================================================" | |
echo "$ sudo service postgresql restart" | |
echo "======================================================================" | |
echo "Help: https://help.ubuntu.com/community/PostgreSQL" | |
echo "======================================================================" | |
SCRIPT | |
config.vm.provision "shell", inline: $script | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment