Skip to content

Instantly share code, notes, and snippets.

@heycarsten
Last active December 15, 2015 00:19
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save heycarsten/7230affa5b399a84e02e to your computer and use it in GitHub Desktop.
Save heycarsten/7230affa5b399a84e02e to your computer and use it in GitHub Desktop.
Ideal development VM build.

How I manually build a Vagrant VM

Start from Vagrant supplied VMware Fusion Ubuntu base box:

http://files.vagrantup.com/precise64_vmware_fusion.box

From there I would:

Make a temporary directory to compile the shit out of things:

mkdir ~/src

Update shit:

sudo apt-get update
sudo apt-get upgrade

Then set the locale:

sudo locale-gen en_US.UTF-8
sudo update-locale LANG=en_US.UTF-8

Then set the timezone to UTC:

sudo dpkg-reconfigure tzdata

Then install Postgres 9.3:

First, I update the shit according to this article:

http://michael.otacoo.com/postgresql-2/take-care-of-kernel-memory-limitation-for-postgresql-shared-buffers/

Then:

sudo vim /etc/apt/sources.list.d/pgdg.list

And add the following line to that file:

deb http://apt.postgresql.org/pub/repos/apt/ precise-pgdg main

If you're not using precise, then run lsb_release -c to get the codename of the release you are running and substitute accordingly.

Next add the Postgres repository key:

wget --quiet -O - http://apt.postgresql.org/pub/repos/apt/ACCC4CF8.asc | sudo apt-key add -

Now we can install Postgres:

sudo apt-get update
sudo apt-get install postgresql-9.3 libpq-dev postgresql-contrib-9.3

After that I run pg_tune:

cd ~/src
wget http://pgfoundry.org/frs/download.php/2449/pgtune-0.9.3.tar.gz
tar xzf pgtune-0.9.3.tar.gz
sudo ./pgtune-0.9.3/pgtune -i /etc/postgresql/9.3/main/postgresql.conf -o /etc/postgresql/9.3/main/postgresql.conf.pgtune
sudo mv /etc/postgresql/9.3/main/postgresql.conf /etc/postgresql/9.3/main/postgresql.conf.original
sudo mv /etc/postgresql/9.3/main/postgresql.conf.pgtune /etc/postgresql/9.3/main/postgresql.conf
sudo chown postgres:postgres /etc/postgresql/9.3/main/postgresql.conf

Then create a PG superuser for the login user (vagrant):

sudo su - postgres
createuser -s vagrant
exit

Then install Redis:

cd ~/src
wget http://download.redis.io/releases/redis-2.8.4.tar.gz
tar xzf redis-2.8.4.tar.gz
cd redis-2.8.4
make
sudo make install
sudo cp redis.conf /etc/redis.conf
sudo useradd -r redis
sudo mkdir /var/lib/redis
sudo chown redis:redis /var/lib/redis
# Then I change the data directory to /var/lib/redis and I set
# it to use syslog for logging:
sudo vim /etc/redis.conf

Next I make a shitty Upstart script for Redis:

I add the following to a file at /etc/init/redis.conf

description "Redis"
start on runlevel [23]
stop on shutdown
exec sudo -u redis /usr/local/bin/redis-server /etc/redis.conf
respawn

Next I install Nginx with the upload module so we can do fancy XHR file uploads and not send massive BLOBs to Rails:

sudo apt-get install libpcre3-dev # For regex matching, might already be in base box?
cd ~/src
wget http://nginx.org/download/nginx-1.4.4.tar.gz
tar xzf nginx-1.4.4.tar.gz
cd nginx-1.4.4
./configure --with-http_ssl_module --with-http_gzip_static_module
make
sudo make install
sudo useradd -r nginx
sudo mkdir /var/log/nginx
sudo chown nginx:nginx /var/log/nginx

Now I use this as my base Nginx config which I place at /etc/nginx.conf:

worker_processes 1;
user nginx nginx;
pid /var/run/nginx.pid;

events {
  worker_connections 1024;
  use epoll;
}

http {
  client_max_body_size 1g;

  include /usr/local/nginx/conf/mime.types;

  access_log /dev/null;
  error_log /dev/null;

  upstream rack_app {
    server 127.0.0.1:3000 fail_timeout=0;
  }

  server {
    root /vagrant/public;

    try_files $uri/index.html $uri.html $uri @upstream_app;

    location @upstream_app {
      proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
      proxy_set_header Host $http_host;
      proxy_redirect off;
      proxy_pass http://rack_app;
    }
  }
}

Next I create another Upstart for Nginx at /etc/init/nginx.conf:

description "Nginx"
start on runlevel [2]
stop on runlevel [016]
console owner
exec /usr/local/nginx/sbin/nginx -c /etc/nginx.conf -g "daemon off;"
respawn

At this time I will often install Imagemagick:

sudo apt-get install imagemagick

Now is when I usually install any project specific dependencies.

Next I install RVM:

curl -L https://get.rvm.io | bash -s stable

Once it installs it shits out a bunch of crap in ~/, so I remove the zsh configs that it adds and (as it recommends) I add the following line to the top of ~/.bash_profile:

source ~/.profile

At this point I usually log out and back in, then:

rvm autolibs enable
rvm requirements

This will install all the required packages using apt, sweeeeeet!

After that I install the Rubies I want:

rvm install 1.9.3
rvm install 2.1.0

Then I set a default:

rvm use 2.1.0 --default

At this point, I restart the box, and then it's ready to start using for development.

@mmun
Copy link

mmun commented Mar 16, 2013

I printed this out and framed it on my wall.

@heycarsten
Copy link
Author

@mmun ❤️ ❤️ ❤️

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment