Skip to content

Instantly share code, notes, and snippets.

@jbgo
Created September 2, 2016 16:41
Show Gist options
  • Save jbgo/7948d4e97f6bb9f848c1e2afc735738b to your computer and use it in GitHub Desktop.
Save jbgo/7948d4e97f6bb9f848c1e2afc735738b to your computer and use it in GitHub Desktop.
My vagrant setup for python flask apps
SHELL = /bin/bash
WORKDIR = /vagrant
PSQL = sudo -u postgres psql
DBNAME = changeme
DBUSER = changeme_user
DBPASS = secret
db/console:
$(PSQL) $(DBNAME)
db/create: db/create/user db/create/database db/seed
db/create/database:
@echo "--> create DB"
$(PSQL) -c "CREATE DATABASE $(DBNAME) OWNER $(DBUSER);"
db/create/user:
@echo "--> create DB user"
$(PSQL) -c "CREATE USER $(DBUSER) WITH PASSWORD '$(DBPASS)';"
db/seed:
python seed.py
flask/server:
python run.py
pip/freeze:
@echo "--> saving python dependencies to requirements.txt"
pip freeze > requirements.txt
pip/update:
@echo "--> updating python dependencies from requirements.txt"
pip install -r requirements.txt
venv/setup: venv/setup_virtualenv venv/setup_shell
venv/setup_shell:
@echo "--> configuring python environment"
(test -f ~/.bash_profile && grep venv/bin/activate ~/.bash_profile) || \
echo "cd $(WORKDIR) && source venv/bin/activate" >> ~/.bash_profile
venv/setup_virtualenv:
@echo "--> creating python virtual environment"
test -d venv || virtualenv venv
# -*- mode: ruby -*-
# vi: set ft=ruby :
Vagrant.configure(2) do |config|
config.vm.box = "ubuntu/trusty64"
# Flask
config.vm.network "forwarded_port", guest: 5000, host: 5000
config.vm.provider "virtualbox" do |vb|
vb.memory = "2048"
end
# Provision python development environment
config.vm.provision "shell", inline: <<-SHELL
export HOME=/home/vagrant
sudo apt-get update
sudo apt-get install -yq \
ntp \
git \
python-dev \
python-virtualenv \
postgresql \
libpq-dev
su vagrant -c 'cd /vagrant &&
make venv/setup &&
source venv/bin/activate &&
make pip/update &&
make db/create'
SHELL
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment