From dde0c3e6a59f05e49c8a8222fa39c7c7c372be43 Mon Sep 17 00:00:00 2001 From: Matthew Somerville Date: Wed, 11 May 2016 17:51:05 +0100 Subject: [PATCH] fixup Tweaks to get it running first pass. Use install-as-user script to set up general.yml, database etc; this is made much easier by putting the checkout in /vagrant/mapit rather than /vagrant. Remove mailcatcher/varnish lines, and use of sudo. Make virtualenv self-activate, and install pyinotify to reduce CPU etc usage. --- CONTRIBUTING.md | 5 ++--- VagrantFile | 47 +++++++++++++++-------------------------------- 2 files changed, 17 insertions(+), 35 deletions(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index f688625c..5f42b6e9 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -17,15 +17,14 @@ Create, and SSH in to, the Vagrant VM: Inside the VM, run the Django dev server: - . /virtualenv-mapit/bin/activate - cd /vagrant + cd /vagrant/mapit ./manage.py runserver 0.0.0.0:8000 MapIt will be accessible at on the host machine. If you make changes to the stylesheets, you will need to recompile the Sass files: - # from /vagrant in the VM: + # from /vagrant/mapit in the VM: bin/mapit_make_css ## Full setup on your own server diff --git a/VagrantFile b/VagrantFile index 402fabf6..60f6e861 100644 --- a/VagrantFile +++ b/VagrantFile @@ -11,7 +11,8 @@ Vagrant.configure(2) do |config| config.vm.box = "ubuntu/trusty64" # Enable NFS access to the disk - config.vm.synced_folder ".", "/vagrant", :nfs => true + config.vm.synced_folder ".", "/vagrant", disabled: true + config.vm.synced_folder ".", "/vagrant/mapit", :nfs => true # NFS requires a host-only network # This also allows you to test via other devices (e.g. mobiles) on the same @@ -20,10 +21,6 @@ Vagrant.configure(2) do |config| # Django dev server config.vm.network "forwarded_port", guest: 8000, host: 8000 - # For accessing via Varnish - config.vm.network "forwarded_port", guest: 8001, host: 81 - # For mailcatcher - config.vm.network "forwarded_port", guest: 1080, host: 1080 # Give the VM a bit more power to speed things up config.vm.provider "virtualbox" do |v| @@ -33,39 +30,25 @@ Vagrant.configure(2) do |config| # Provision the vagrant box config.vm.provision "shell", inline: <<-SHELL - sudo apt-get update + apt-get update - cd /vagrant + chown vagrant:vagrant /vagrant + cd /vagrant/mapit # Install the packages from conf/packages.ubuntu-trusty - xargs sudo apt-get install -qq -y < conf/packages.ubuntu-trusty - # Install some of the other things we need that are either just for dev - # or can't come from the usual package manager - # ruby-dev for mailcatcher - # git for installing mapit from the repo directly - sudo apt-get install -qq -y ruby-dev git + xargs apt-get install -qq -y < conf/packages.ubuntu-trusty # Create a postgresql user - sudo -u postgres psql -c "CREATE USER mapit SUPERUSER CREATEDB PASSWORD 'mapit'" - # Create a database - sudo -u postgres psql -c "CREATE DATABASE mapit" - # Install the POSTGIS extensions - sudo -u postgres psql -c "CREATE EXTENSION postgis; CREATE EXTENSION postgis_topology;" -d mapit + su postgres -c 'psql -c "CREATE USER vagrant SUPERUSER CREATEDB"' - # Install mailcatcher to make dev email development easier - sudo gem install mailcatcher + # Run install-as-user to set up a database, virtualenv, python, sass etc + su vagrant -c 'bin/install-as-user vagrant mapit.mysociety.org /vagrant' - # Run post-deploy actions script to create a virtualenv, install the - # python packages we need, migrate the db and generate the sass etc - conf/post_deploy_actions.bash + # Nicer running of runserver + su vagrant -c '../virtualenv-mapit/bin/pip install pyinotify' + + # Auto-activate virtualenv on login + echo >> /home/vagrant/.bashrc "source /vagrant/virtualenv-mapit/bin/activate" SHELL - # Start mailcatcher every time we start the VM - config.vm.provision "shell", run: "always" do |s| - s.inline = <<-SHELL - mailcatcher --http-ip 0.0.0.0 - cd /vagrant - source ../virtualenv-mapit/bin/activate - SHELL - end -end \ No newline at end of file +end