diff --git a/README.md b/README.md index 262f238..4522aae 100644 --- a/README.md +++ b/README.md @@ -1,28 +1,39 @@ -vagrant-django-base -=================== +Vagrant box for Django development +================================== -A Vagrant box based on Ubuntu trusty32, configured for Django development -according to Torchbox's adopted practices. Things preinstalled beyond the base -trusty32 box include: +A Vagrant box based on Ubuntu trusty32, with the dependencies for developing Django projects preinstalled. -* postgresql 9.3 (with locale fixed to create databases as UTF-8) -* virtualenv and virtualenvwrapper -* dependencies for Pillow, a drop-in replacement for the Python Imaging Library PIL -* a pip download cache pre-seeded with Django and various other common packages -* git (sometimes required for pip dependencies that aren't in PyPI) -* Node.js, CoffeeScript and LESS +Usage +----- + +This box is available on Vagrant cloud (aka Atlas) so can be used by just setting your base box to ``torchbox/django``. + +To create a new Vagrantfile that uses this box, run the following: + +``` +vagrant init torchbox/django +``` + +What's inside +------------- + + - Python 2.7.9 with virtualenv and pip + - Python 3.4.3 with pip (use bundled pyvenv for virtual environments) + - NodeJS 0.12.3 with npm 2.9.1 + - PostgreSQL 9.3.6 + - Redis 2.8.4 + - Vim, Git, GCC (with C++ support) + - Development headers for Python (2 and 3), PostgreSQL and some image libraries (libjpeg, zlib, etc) + - Prebuilt wheels for Pillow 2.8.1 and psycopg2 2.6 for both python versions (and pip configured to use them) -We use this box in conjunction with https://github.com/torchbox/vagrant-django-template -as the initial template for our Django projects. vagrant-django-template will -successfully build from a vanilla trusty32 base box, but using vagrant-django-base -instead will skip some of the time-consuming initial setup. Build instructions ------------------ + To generate the .box file: ./build.sh To install locally: - vagrant box add django-base-v2.2 django-base-v2.2.box + vagrant box add django-base-v3.0.0 django-base-v3.0.0.box diff --git a/Vagrantfile b/Vagrantfile index 6b3f0d3..b6a7efc 100644 --- a/Vagrantfile +++ b/Vagrantfile @@ -1,30 +1,10 @@ # -*- mode: ruby -*- # vi: set ft=ruby : -Vagrant::Config.run do |config| - # Every Vagrant virtual environment requires a box to build off of. - config.vm.box = "ubuntu/trusty32" - - # The url from where the 'config.vm.box' box will be fetched if it - # doesn't already exist on the user's system. - config.vm.box_url = "https://cloud-images.ubuntu.com/vagrant/trusty/current/trusty-server-cloudimg-i386-vagrant-disk1.box" - - # Boot with a GUI so you can see the screen. (Default is headless) - # config.vm.boot_mode = :gui - - # Assign this VM to a host only network IP, allowing you to access it - # via the IP. - # config.vm.network "33.33.33.10" - - # Forward a port from the guest to the host, which allows for outside - # computers to access the VM, whereas host only networking does not. - # config.vm.forward_port "http", 80, 8080 - - # Share an additional folder to the guest VM. The first argument is - # an identifier, the second is the path on the guest to mount the - # folder, and the third is the path on the host to the actual folder. - config.vm.share_folder "v-data", "/vagrant_data", "./data" - - # Enable provisioning with a shell script. - config.vm.provision :shell, :path => "install.sh" +# Vagrantfile API/syntax version. Don't touch unless you know what you're doing! +VAGRANTFILE_API_VERSION = "2" + +Vagrant.configure(VAGRANTFILE_API_VERSION) do |config| + config.vm.box = "ubuntu/trusty32" + config.vm.provision :shell, :path => "install/install.sh" end diff --git a/build.sh b/build.sh index 9f136d5..a44f439 100755 --- a/build.sh +++ b/build.sh @@ -1,9 +1,11 @@ #!/bin/bash -# to build django-base-v2.box: +# to build django-base-v3.0.0.box: +vagrant destroy vagrant up -rm -f django-base-v2.2.box -vagrant package --output django-base-v2.2.box +vagrant halt +rm -f django-base-v3.0.0.box +vagrant package --output django-base-v3.0.0.box # to install locally: -# vagrant box add django-base-v2.2 django-base-v2.2.box +# vagrant box add django-base-v3.0.0 django-base-v3.0.0.box diff --git a/data/bashrc b/data/bashrc deleted file mode 100644 index 18ba567..0000000 --- a/data/bashrc +++ /dev/null @@ -1,103 +0,0 @@ -# ~/.bashrc: executed by bash(1) for non-login shells. -# see /usr/share/doc/bash/examples/startup-files (in the package bash-doc) -# for examples - -# If not running interactively, don't do anything -[ -z "$PS1" ] && return - -# don't put duplicate lines in the history. See bash(1) for more options -# ... or force ignoredups and ignorespace -HISTCONTROL=ignoredups:ignorespace - -# append to the history file, don't overwrite it -shopt -s histappend - -# for setting history length see HISTSIZE and HISTFILESIZE in bash(1) -HISTSIZE=1000 -HISTFILESIZE=2000 - -# check the window size after each command and, if necessary, -# update the values of LINES and COLUMNS. -shopt -s checkwinsize - -# make less more friendly for non-text input files, see lesspipe(1) -[ -x /usr/bin/lesspipe ] && eval "$(SHELL=/bin/sh lesspipe)" - -# set variable identifying the chroot you work in (used in the prompt below) -if [ -z "$debian_chroot" ] && [ -r /etc/debian_chroot ]; then - debian_chroot=$(cat /etc/debian_chroot) -fi - -# set a fancy prompt (non-color, unless we know we "want" color) -case "$TERM" in - xterm-color) color_prompt=yes;; -esac - -# uncomment for a colored prompt, if the terminal has the capability; turned -# off by default to not distract the user: the focus in a terminal window -# should be on the output of commands, not on the prompt -#force_color_prompt=yes - -if [ -n "$force_color_prompt" ]; then - if [ -x /usr/bin/tput ] && tput setaf 1 >&/dev/null; then - # We have color support; assume it's compliant with Ecma-48 - # (ISO/IEC-6429). (Lack of such support is extremely rare, and such - # a case would tend to support setf rather than setaf.) - color_prompt=yes - else - color_prompt= - fi -fi - -if [ "$color_prompt" = yes ]; then - PS1='${debian_chroot:+($debian_chroot)}\[\033[01;32m\]\u@\h\[\033[00m\]:\[\033[01;34m\]\w\[\033[00m\]\$ ' -else - PS1='${debian_chroot:+($debian_chroot)}\u@\h:\w\$ ' -fi -unset color_prompt force_color_prompt - -# If this is an xterm set the title to user@host:dir -case "$TERM" in -xterm*|rxvt*) - PS1="\[\e]0;${debian_chroot:+($debian_chroot)}\u@\h: \w\a\]$PS1" - ;; -*) - ;; -esac - -# enable color support of ls and also add handy aliases -if [ -x /usr/bin/dircolors ]; then - test -r ~/.dircolors && eval "$(dircolors -b ~/.dircolors)" || eval "$(dircolors -b)" - alias ls='ls --color=auto' - #alias dir='dir --color=auto' - #alias vdir='vdir --color=auto' - - alias grep='grep --color=auto' - alias fgrep='fgrep --color=auto' - alias egrep='egrep --color=auto' -fi - -# some more ls aliases -alias ll='ls -alF' -alias la='ls -A' -alias l='ls -CF' - -# Alias definitions. -# You may want to put all your additions into a separate file like -# ~/.bash_aliases, instead of adding them here directly. -# See /usr/share/doc/bash-doc/examples in the bash-doc package. - -if [ -f ~/.bash_aliases ]; then - . ~/.bash_aliases -fi - -# enable programmable completion features (you don't need to enable -# this, if it's already enabled in /etc/bash.bashrc and /etc/profile -# sources /etc/bash.bashrc). -if [ -f /etc/bash_completion ] && ! shopt -oq posix; then - . /etc/bash_completion -fi - -export WORKON_HOME=$HOME/.virtualenvs -export PIP_DOWNLOAD_CACHE=$HOME/.pip_download_cache -source /usr/local/bin/virtualenvwrapper.sh diff --git a/data/common_requirements.txt b/data/common_requirements.txt deleted file mode 100644 index 7a83c3f..0000000 --- a/data/common_requirements.txt +++ /dev/null @@ -1,8 +0,0 @@ -Django==1.7.1 -psycopg2==2.5.4 -django-devserver==0.8.0 -django-compressor==1.4 -django-debug-toolbar==1.2.2 -Pillow==2.6.1 -gunicorn==19.1.1 -fabric==1.10.0 diff --git a/data/etc-bash.bashrc b/data/etc-bash.bashrc deleted file mode 100644 index 00d0a7b..0000000 --- a/data/etc-bash.bashrc +++ /dev/null @@ -1,68 +0,0 @@ -# System-wide .bashrc file for interactive bash(1) shells. - -# To enable the settings / commands in this file for login shells as well, -# this file has to be sourced in /etc/profile. - -# If not running interactively, don't do anything -[ -z "$PS1" ] && return - -# check the window size after each command and, if necessary, -# update the values of LINES and COLUMNS. -shopt -s checkwinsize - -# set variable identifying the chroot you work in (used in the prompt below) -if [ -z "$debian_chroot" ] && [ -r /etc/debian_chroot ]; then - debian_chroot=$(cat /etc/debian_chroot) -fi - -# set a fancy prompt (non-color, overwrite the one in /etc/profile) -PS1='${debian_chroot:+($debian_chroot)}\u@\h:\w\$ ' - -# Commented out, don't overwrite xterm -T "title" -n "icontitle" by default. -# If this is an xterm set the title to user@host:dir -#case "$TERM" in -#xterm*|rxvt*) -# PROMPT_COMMAND='echo -ne "\033]0;${USER}@${HOSTNAME}: ${PWD}\007"' -# ;; -#*) -# ;; -#esac - -# enable bash completion in interactive shells -#if [ -f /etc/bash_completion ] && ! shopt -oq posix; then -# . /etc/bash_completion -#fi - -# sudo hint -if [ ! -e "$HOME/.sudo_as_admin_successful" ] && [ ! -e "$HOME/.hushlogin" ] ; then - case " $(groups) " in *\ admin\ *) - if [ -x /usr/bin/sudo ]; then - cat <<-EOF - To run a command as administrator (user "root"), use "sudo ". - See "man sudo_root" for details. - - EOF - fi - esac -fi - -# if the command-not-found package is installed, use it -if [ -x /usr/lib/command-not-found -o -x /usr/share/command-not-found/command-not-found ]; then - function command_not_found_handle { - # check because c-n-f could've been removed in the meantime - if [ -x /usr/lib/command-not-found ]; then - /usr/bin/python /usr/lib/command-not-found -- "$1" - return $? - elif [ -x /usr/share/command-not-found/command-not-found ]; then - /usr/bin/python /usr/share/command-not-found/command-not-found -- "$1" - return $? - else - printf "%s: command not found\n" "$1" >&2 - return 127 - fi - } -fi - -export LANGUAGE=en_GB.UTF-8 -export LANG=en_GB.UTF-8 -export LC_ALL=en_GB.UTF-8 diff --git a/data/pg_hba.conf b/data/pg_hba.conf deleted file mode 100644 index 8564a9b..0000000 --- a/data/pg_hba.conf +++ /dev/null @@ -1,89 +0,0 @@ -# PostgreSQL Client Authentication Configuration File -# =================================================== -# -# Refer to the "Client Authentication" section in the -# PostgreSQL documentation for a complete description -# of this file. A short synopsis follows. -# -# This file controls: which hosts are allowed to connect, how clients -# are authenticated, which PostgreSQL user names they can use, which -# databases they can access. Records take one of these forms: -# -# local DATABASE USER METHOD [OPTIONS] -# host DATABASE USER CIDR-ADDRESS METHOD [OPTIONS] -# hostssl DATABASE USER CIDR-ADDRESS METHOD [OPTIONS] -# hostnossl DATABASE USER CIDR-ADDRESS METHOD [OPTIONS] -# -# (The uppercase items must be replaced by actual values.) -# -# The first field is the connection type: "local" is a Unix-domain socket, -# "host" is either a plain or SSL-encrypted TCP/IP socket, "hostssl" is an -# SSL-encrypted TCP/IP socket, and "hostnossl" is a plain TCP/IP socket. -# -# DATABASE can be "all", "sameuser", "samerole", a database name, or -# a comma-separated list thereof. -# -# USER can be "all", a user name, a group name prefixed with "+", or -# a comma-separated list thereof. In both the DATABASE and USER fields -# you can also write a file name prefixed with "@" to include names from -# a separate file. -# -# CIDR-ADDRESS specifies the set of hosts the record matches. -# It is made up of an IP address and a CIDR mask that is an integer -# (between 0 and 32 (IPv4) or 128 (IPv6) inclusive) that specifies -# the number of significant bits in the mask. Alternatively, you can write -# an IP address and netmask in separate columns to specify the set of hosts. -# -# METHOD can be "trust", "reject", "md5", "password", "gss", "sspi", "krb5", -# "ident", "pam", "ldap" or "cert". Note that "password" sends passwords -# in clear text; "md5" is preferred since it sends encrypted passwords. -# -# OPTIONS are a set of options for the authentication in the format -# NAME=VALUE. The available options depend on the different authentication -# methods - refer to the "Client Authentication" section in the documentation -# for a list of which options are available for which authentication methods. -# -# Database and user names containing spaces, commas, quotes and other special -# characters must be quoted. Quoting one of the keywords "all", "sameuser" or -# "samerole" makes the name lose its special character, and just match a -# database or username with that name. -# -# This file is read on server startup and when the postmaster receives -# a SIGHUP signal. If you edit the file on a running system, you have -# to SIGHUP the postmaster for the changes to take effect. You can use -# "pg_ctl reload" to do that. - -# Put your actual configuration here -# ---------------------------------- -# -# If you want to allow non-local connections, you need to add more -# "host" records. In that case you will also need to make PostgreSQL listen -# on a non-local interface via the listen_addresses configuration parameter, -# or via the -i or -h command line switches. -# - - - - -# DO NOT DISABLE! -# If you change this first entry you will need to make sure that the -# database -# super user can access the database using some other method. -# Noninteractive -# access to all databases is required during automatic maintenance -# (custom daily cronjobs, replication, and similar tasks). -# -# Database administrative login by UNIX sockets -local all postgres trust - -# TYPE DATABASE USER CIDR-ADDRESS METHOD - -# "local" is for Unix domain socket connections only -#local all all trust -# IPv4 local connections: -#host all all 127.0.0.1/32 md5 -# IPv6 local connections: -#host all all ::1/128 md5 -# This is for general access databases: -local all all trust -host all all 127.0.0.1/32 trust diff --git a/install.sh b/install.sh deleted file mode 100644 index c0c6d0f..0000000 --- a/install.sh +++ /dev/null @@ -1,73 +0,0 @@ -#!/bin/bash - -# Script to set up dependencies for Django on Vagrant. - -PGSQL_VERSION=9.3 - -# Need to fix locale so that Postgres creates databases in UTF-8 -cp -p /vagrant_data/etc-bash.bashrc /etc/bash.bashrc -locale-gen en_GB.UTF-8 -dpkg-reconfigure locales - -export LANGUAGE=en_GB.UTF-8 -export LANG=en_GB.UTF-8 -export LC_ALL=en_GB.UTF-8 - -# Install essential packages from Apt -apt-get update -y -# Python dev packages -apt-get install -y build-essential python python-dev python-setuptools python-pip -# Dependencies for image processing with Pillow (drop-in replacement for PIL) -# supporting: jpeg, tiff, png, freetype, littlecms -apt-get install -y libjpeg-dev libtiff-dev zlib1g-dev libfreetype6-dev liblcms2-dev -# Git (we'd rather avoid people keeping credentials for git commits in the repo, but sometimes we need it for pip requirements that aren't in PyPI) -apt-get install -y git - -# Postgresql -if ! command -v psql; then - apt-get install -y postgresql-$PGSQL_VERSION libpq-dev - cp /vagrant_data/pg_hba.conf /etc/postgresql/$PGSQL_VERSION/main/ - /etc/init.d/postgresql reload -fi - -# virtualenv global setup -if ! command -v pip; then - easy_install -U pip -fi -if [[ ! -f /usr/local/bin/virtualenv ]]; then - easy_install virtualenv virtualenvwrapper stevedore virtualenv-clone -fi - -# bash environment global setup -cp -p /vagrant_data/bashrc /home/vagrant/.bashrc - -# install our common Python packages in a temporary virtual env so that they'll get cached -if [[ ! -e /home/vagrant/.pip_download_cache ]]; then - su - vagrant -c "mkdir -p /home/vagrant/.pip_download_cache && \ - virtualenv /home/vagrant/yayforcaching && \ - PIP_DOWNLOAD_CACHE=/home/vagrant/.pip_download_cache /home/vagrant/yayforcaching/bin/pip install -r /vagrant_data/common_requirements.txt && \ - rm -rf /home/vagrant/yayforcaching" -fi - -# Node.js, CoffeeScript and LESS -if ! command -v npm; then - wget http://nodejs.org/dist/v0.10.0/node-v0.10.0.tar.gz - tar xzf node-v0.10.0.tar.gz - cd node-v0.10.0/ - ./configure && make && make install - cd .. - rm -rf node-v0.10.0/ node-v0.10.0.tar.gz -fi -if ! command -v coffee; then - npm install -g coffee-script -fi -if ! command -v lessc; then - npm install -g less -fi - -# Cleanup -apt-get clean - -echo "Zeroing free space to improve compression." -dd if=/dev/zero of=/EMPTY bs=1M -rm -f /EMPTY diff --git a/install/install.sh b/install/install.sh new file mode 100644 index 0000000..92672f0 --- /dev/null +++ b/install/install.sh @@ -0,0 +1,74 @@ +#!/bin/bash + +# Update APT database +apt-get update -y + +# Useful tools +apt-get install -y vim git curl gettext build-essential + +# Dependencies for PIL +apt-get install -y libjpeg-dev libtiff-dev zlib1g-dev libfreetype6-dev liblcms2-dev + +# Redis +apt-get install -y redis-server + +# PostgreSQL +apt-get install -y postgresql libpq-dev + +# Dependencies for Python +apt-get install -y libssl-dev libncurses-dev liblzma-dev libgdbm-dev libsqlite3-dev libbz2-dev tk-dev libreadline6-dev + + +# Python 2.7 +curl https://www.python.org/ftp/python/2.7.9/Python-2.7.9.tgz | tar xvz +cd Python-2.7.9 +./configure +make +make install +cd .. +rm -rf Python-2.7.9 + +python2 -m ensurepip + +pip2.7 install virtualenv wheel +su - vagrant -c "pip2.7 wheel psycopg2==2.6" +su - vagrant -c "pip2.7 wheel Pillow==2.8.1" + + +# Python 3.4 +curl https://www.python.org/ftp/python/3.4.3/Python-3.4.3.tgz | tar xvz +cd Python-3.4.3 +./configure +make +make install +cd .. +rm -rf Python-3.4.3 + +pip3.4 install wheel +su - vagrant -c "pip3.4 wheel psycopg2==2.6" +su - vagrant -c "pip3.4 wheel Pillow==2.8.1" + + +# Tell PIP where to find wheel files +echo "export PIP_FIND_LINKS=/home/vagrant/wheelhouse" >> /home/vagrant/.bashrc + + +# Create vagrant pgsql superuser +su - postgres -c "createuser -s vagrant" + + +# Install Fabric and Sphinx +pip2.7 install Fabric==1.10.1 Sphinx==1.2.3 + + +# Install NodeJS +wget http://nodejs.org/dist/v0.12.3/node-v0.12.3-linux-x86.tar.gz +cd /usr/local && tar --strip-components 1 -xzf /home/vagrant/node-v0.12.3-linux-x86.tar.gz + + +# Cleanup +apt-get clean + +echo "Zeroing free space to improve compression..." +dd if=/dev/zero of=/EMPTY bs=1M +rm -f /EMPTY