[PATCH 2/4] vagrant: Add Vagrant-based development environment
Stephen Finucane
stephen.finucane at intel.com
Thu Feb 11 07:14:31 AEDT 2016
Integrate Vagrant by way of a Vagrantfile and a simple install script.
This follows many of the instructions found in the development guide
with the exceptions of the superuser creation, which is optional, the
loading of archives, which requires per-user authentication, and the
use of virtual environments, which are unnecessary in a teardown
environment such as this.
Signed-off-by: Stephen Finucane <stephen.finucane at intel.com>
---
Vagrantfile | 26 +++++++++++++++++
tools/install/install.sh | 75 ++++++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 101 insertions(+)
create mode 100644 Vagrantfile
create mode 100644 tools/install/install.sh
diff --git a/Vagrantfile b/Vagrantfile
new file mode 100644
index 0000000..b316d41
--- /dev/null
+++ b/Vagrantfile
@@ -0,0 +1,26 @@
+# -*- mode: ruby -*-
+# vi: set ft=ruby :
+
+Vagrant.configure(2) do |config|
+ # For a complete reference of available confguration options, please see the
+ # online documentation at https://docs.vagrantup.com.
+
+ config.vm.box = "ubuntu/trusty32"
+
+ config.vm.network "forwarded_port", guest: 8000, host: 8000
+ # Enable this if you want host-only access to the machine using the given IP
+ # config.vm.network "private_network", ip: "192.168.33.10"
+
+ # Provider-specific configuration so you can fine-tune various
+ # backing providers for Vagrant. These expose provider-specific options.
+ #
+ # config.vm.provider "virtualbox" do |vb|
+ # # Display the VirtualBox GUI when booting the machine
+ # vb.gui = true
+ #
+ # # Customize the amount of memory on the VM:
+ # vb.memory = "1024"
+ # end
+
+ config.vm.provision :shell, :path => "tools/install/install.sh"
+end
diff --git a/tools/install/install.sh b/tools/install/install.sh
new file mode 100644
index 0000000..b2a074b
--- /dev/null
+++ b/tools/install/install.sh
@@ -0,0 +1,75 @@
+#!/bin/bash
+
+# Script to set up patchwork on a Vagrant-powered Ubuntu Trusty host
+
+echo -e "\n--- Configuring environment ---\n"
+
+PROJECT_NAME=patchwork
+PROJECT_HOME=/vagrant
+WORKON_HOME=$PROJECT_HOME/.virtualenvs
+
+db_user=root
+db_pass=password
+
+export DJANGO_SETTINGS_MODULE=patchwork.settings.dev
+export DEBIAN_FRONTEND=noninteractive
+
+echo "mysql-server mysql-server/root_password password $db_pass" | debconf-set-selections
+echo "mysql-server mysql-server/root_password_again password $db_pass" | debconf-set-selections
+
+echo -e "\n--- Updating packages list ---\n"
+
+apt-get update -qq
+
+echo -e "\n--- Installing system packages ---\n"
+
+apt-get install -y python python3-dev python3-pip mysql-server \
+ libmysqlclient-dev curl > /dev/null
+
+echo -e "\n--- Installing Python dependencies ---\n"
+
+pip3 -q install virtualenv tox
+pip3 -q install -r $PROJECT_HOME/requirements-dev.txt
+
+echo -e "\n--- Configuring database ---\n"
+
+mysql -u$db_user -p$db_pass << EOF
+DROP DATABASE IF EXISTS patchwork;
+CREATE DATABASE patchwork CHARACTER SET utf8;
+GRANT ALL ON patchwork.* TO 'patchwork'@'localhost' IDENTIFIED BY 'password';
+EOF
+
+chmod a+x $PROJECT_HOME/manage.py
+
+echo -e "\n--- Loading initial data ---\n"
+
+sudo -E -u vagrant python3 $PROJECT_HOME/manage.py migrate > /dev/null
+sudo -E -u vagrant python3 $PROJECT_HOME/manage.py loaddata \
+ $PROJECT_HOME/patchwork/fixtures/default_tags.xml > /dev/null
+sudo -E -u vagrant python3 $PROJECT_HOME/manage.py loaddata \
+ $PROJECT_HOME/patchwork/fixtures/default_states.xml > /dev/null
+sudo -E -u vagrant python3 $PROJECT_HOME/manage.py loaddata \
+ $PROJECT_HOME/patchwork/fixtures/default_projects.xml > /dev/null
+
+echo -e "\n--- Configuring environment ---\n"
+
+cat >> /home/vagrant/.bashrc << EOF
+export DJANGO_SETTINGS_MODULE='patchwork.settings.dev'
+
+alias runserver='python3 /vagrant/manage.py runserver 0.0.0.0:8000'
+alias createsu='python3 /vagrant/manage.py createsuperuser'
+cd /vagrant
+EOF
+
+echo "Done."
+echo "You may now log in:"
+echo " $ vagrant ssh"
+echo "Once logged in, start the server using the 'runserver' alias:"
+echo " $ runserver"
+echo "You may wish to create a superuser for use with the admin console:"
+echo " $ createsuperuser"
+echo "For information on the above, and some examples on loading sample date,"
+echo "please refer to the documentation found in the 'doc' folder."
+echo "Alternatively, check out the docs online:"
+echo " https://patchwork.readthedocs.org/en/latest/development/"
+echo "Happy patchworking."
--
2.0.0
More information about the Patchwork
mailing list