Skip to content

Commit

Permalink
re-configure things, smoother workflow. ONLY for postgres atm.
Browse files Browse the repository at this point in the history
  • Loading branch information
ccurtin committed Oct 1, 2016
1 parent 45f8356 commit 42b855b
Show file tree
Hide file tree
Showing 9 changed files with 422 additions and 511 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Vagrant-Python-Django VM

A Vagrantfile utilizing Ubuntu 14.04/Trusty to get you started with self-contained Python/Django projects quickly via VirtualEnv.
Create contained environments within the VM via `. init_python_project [PROJECT_NAME] [PYTHON_VER] [DJANGO_VER]`
Create contained environments within the VM via `. init_python_env [PROJECT_NAME] [PYTHON_VER] [DJANGO_VER]`

## Installation
- install [VirtualBox](https://www.virtualbox.org/wiki/Downloads)(_recommended_) or VMWare for [MAC](https://my.vmware.com/web/vmware/info?slug=desktop_end_user_computing/vmware_fusion/8_0), [Windows](http://www.vmware.com/products/workstation.html) or [Linux](http://www.vmware.com/products/workstation-for-linux.html) on your host machine.
Expand All @@ -13,7 +13,7 @@ Create contained environments within the VM via `. init_python_project [PROJECT_

- login to machine `vagarnt ssh` and run `sudo su` for privileged commands. (virtualenvwrapper will create necessary files in the root sync folder )
- make sure you are in the synced_folder directory before running the command below. Default directory here is: `/vagrant/www/`
- run the command `. init_python_project [PROJECT_NAME] [PYTHON_VERSION] [DJANGO_VERSION]` to create a new Python Environment so projects/packages are contained. **All python environments will be initialized in the synced_folder (`/vagrant/www/` by default). Notice the preceding period. This will automatically cd into the project directory after setup.**
- run the command `. init_python_env [PROJECT_NAME] [PYTHON_VERSION] [DJANGO_VERSION]` to create a new Python Environment so projects/packages are contained. **All python environments will be initialized in the synced_folder (`/vagrant/www/` by default). Notice the preceding period. This will automatically cd into the project directory after setup.**
- VirtualEnv is _not_ a VM container, it is simply to create self-contained python environments. Think of it as a sandbox, not a full fledged VM. Plus, we already have the VM!
- Run `python -V` and `django-admin --version` to make sure everything checked out.
- run `deactivate` to exit virtualenv environment or `workon [PROJECT_NAME]` to activate it. Alternatively, just navigate to the project folder to activate the environment.
Expand Down
39 changes: 35 additions & 4 deletions Vagrantfile
Original file line number Diff line number Diff line change
Expand Up @@ -97,10 +97,40 @@ Vagrant.configure(2) do |config|
config.vm.provision "shell", privileged: true, inline: <<-SHELL
sudo sed -i '/tty/!s/mesg n/tty -s \\&\\& mesg n/' /root/.profile
SHELL
# run script to improve PS1 prompt. Display virtualenv and current branch(*)
config.vm.provision :shell, :privileged => true, :path => "./bootstrap/better_ps1.sh"
# run script to quickly add Python/Django environments
config.vm.provision :shell, :privileged => true, :path => "./bootstrap/init_python_project.sh"

# it is IMPORTANT that this is NOT run as root, but by the user "vagrant" with privileged commands.
# Bootstrap folder is owned and accessible by "vagrant" user. Otherwise unable to copy bootstrap files over to VM bin.
config.vm.provision "shell", privileged: false, inline: <<-SHELL
# import Colors variables.
sudo touch /bin/colors
sudo chmod a+x /bin/colors
sudo cp /vagrant/bootstrap/colors.sh /bin/colors
sudo sed -i 's/\r//' /bin/colors
# run script to improve PS1 prompt. Display virtualenv and current branch(*)
sudo touch /bin/better_ps1
sudo chmod a+x /bin/better_ps1
sudo cp /vagrant/bootstrap/better_ps1.sh /bin/better_ps1
sudo sed -i 's/\r//' /bin/better_ps1
# run script to quickly add Python/Django environments
sudo touch /bin/init_python_env
sudo chmod a+x /bin/init_python_env
sudo cp /vagrant/bootstrap/init_python_env.sh /bin/init_python_env
sudo sed -i 's/\r//' /bin/init_python_env
sudo touch /bin/manage_django_db
sudo chmod a+x /bin/manage_django_db
sudo cp /vagrant/bootstrap/manage_django_db.sh /bin/manage_django_db
sudo sed -i 's/\r//' /bin/manage_django_db
sudo touch /bin/manage_django_db_postgres
sudo chmod a+x /bin/manage_django_db_postgres
sudo cp /vagrant/bootstrap/manage_django_db_postgres.sh /bin/manage_django_db_postgres
sudo sed -i 's/\r//' /bin/manage_django_db_postgres
SHELL

# run Shell commands, passing config variables to script.
config.vm.provision :shell, :path => "./bootstrap/bootstrap.sh", :args => [
vagrant_config['synced_folder']['host'],
Expand All @@ -109,4 +139,5 @@ Vagrant.configure(2) do |config|
vagrant_config['git_user_email']
]


end
26 changes: 11 additions & 15 deletions bootstrap/better_ps1.sh
Original file line number Diff line number Diff line change
@@ -1,21 +1,18 @@
#!/bin/bash
sudo touch /bin/better_ps1
sudo chmod +x /bin/better_ps1
echo '#!/bin/bash
# Thanks to Jeff Hull for this!
# Colors
RED="'"\[\033[31m\]"'"
GREEN="'"\[\033[32m\]"'"
YELLOW="'"\[\033[33m\]"'"
BLUE="'"\[\033[34m\]"'"
PURPLE="'"\[\033[35m\]"'"
CYAN="'"\[\033[36m\]"'"
WHITE="'"\[\033[37m\]"'"
NIL="'"\[\033[00m\]"'"
RED='\[\033[31m\]'
GREEN='\[\033[32m\]'
YELLOW='\[\033[33m\]'
BLUE='\[\033[34m\]'
PURPLE='\[\033[35m\]'
CYAN='\[\033[36m\]'
WHITE='\[\033[37m\]'
NIL='\[\033[00m\]'

# Hostname styles
FULL="'"\H"'"
SHORT="'"\h"'"
FULL='\H'
SHORT='\h'

# System => color/hostname map:
# UC: username color
Expand Down Expand Up @@ -73,5 +70,4 @@ function set_prompt() {
export PS1="${myuser}${path}\n${venv}${branch} ${end}"
}

export PROMPT_COMMAND=set_prompt
' >> /bin/better_ps1.sh
export PROMPT_COMMAND=set_prompt
Loading

0 comments on commit 42b855b

Please sign in to comment.