Commit a145a2d

mo khan <mo@mokhan.ca>
2015-08-01 18:01:59
convert vagrant shell script to chef apply.
1 parent e1a469e
bin/bootstrap-vagrant-user.sh
@@ -1,20 +0,0 @@
-set -e
-cd $HOME
-git clone https://github.com/sstephenson/rbenv.git $HOME/.rbenv
-echo 'export PATH="$HOME/.rbenv/bin:$PATH"' >> $HOME/.bash_profile
-echo 'eval "$(rbenv init -)"' >> $HOME/.bash_profile
-source $HOME/.bash_profile
-git clone https://github.com/sstephenson/ruby-build.git $HOME/.rbenv/plugins/ruby-build
-git clone https://github.com/rkh/rbenv-update.git $HOME/.rbenv/plugins/rbenv-update
-git clone https://github.com/sstephenson/rbenv-gem-rehash.git $HOME/.rbenv/plugins/rbenv-gem-rehash
-rbenv update
-rbenv install 2.2.2
-rbenv global 2.2.2
-gem install bundler --no-ri --no-rdoc
-cd /vagrant
-createdb
-if [ ! -f .env.local ]; then
-  cp .env.example .env.local
-fi
-bin/setup
-RAILS_ENV=test bundle exec rake db:create db:migrate db:seed
bin/bootstrap.sh
@@ -1,54 +0,0 @@
-#!/usr/bin/env bash
-apt-get update -y
-apt-get upgrade -y
-apt-get -y install curl git-core software-properties-common python-software-properties imagemagick libmagickwand-dev memcached
-apt-get -y install build-essential
-apt-get -y install tklib
-apt-get -y install zlib1g-dev libssl-dev
-apt-get -y install libreadline-gplv2-dev
-apt-get -y install libxml2 libxml2-dev libxslt1-dev
-apt-get -y install gawk libreadline6-dev libyaml-dev libsqlite3-dev sqlite3 autoconf libgdbm-dev libncurses5-dev automake libtool bison pkg-config libffi-dev
-apt-get -y install build-essential
-apt-get -y install tklib
-apt-get -y install zlib1g-dev libssl-dev
-apt-get -y install libreadline-gplv2-dev
-apt-get -y install libxml2 libxml2-dev libxslt1-dev
-apt-get -y install curl libcurl3 libcurl3-gnutls libcurl4-openssl-dev
-apt-get -y install exuberant-ctags
-apt-get -y install unzip
-apt-get -y install redis-server
-apt-get -y autoremove
-
-PHANTOM_VERSION="phantomjs-1.9.8"
-ARCH=$(uname -m)
-PHANTOM_JS="$PHANTOM_VERSION-linux-$ARCH"
-
-apt-get install build-essential chrpath libssl-dev libxft-dev -y
-apt-get install libfreetype6 libfreetype6-dev -y
-apt-get install libfontconfig1 libfontconfig1-dev -y
-
-cd ~
-wget https://bitbucket.org/ariya/phantomjs/downloads/$PHANTOM_JS.tar.bz2
-tar xvjf $PHANTOM_JS.tar.bz2
-
-mv $PHANTOM_JS /usr/local/share
-ln -sf /usr/local/share/$PHANTOM_JS/bin/phantomjs /usr/local/bin
-
-add-apt-repository -y ppa:nginx/stable
-apt-get -y update
-apt-get -y install nginx
-
-echo "deb http://apt.postgresql.org/pub/repos/apt/ $(lsb_release -cs)-pgdg main" > /etc/apt/sources.list.d/pgdg.list
-wget --quiet -O - https://www.postgresql.org/media/keys/ACCC4CF8.asc | apt-key add -
-apt-get -y update
-apt-get install -y postgresql-9.4 libpq-dev
-apt-get install -y postgresql-contrib-9.4
-
-curl -sL https://deb.nodesource.com/setup | bash -
-apt-get -y update
-apt-get -y install nodejs
-
-su postgres<<EOF
-createuser -s -e -w vagrant
-EOF
-su -c "source /vagrant/bin/bootstrap-vagrant-user.sh" vagrant
config/chef_apply.rb
@@ -0,0 +1,143 @@
+execute "apt-get_update" do
+  command "apt-get update -y"
+end
+
+execute "apt-get_upgrade" do
+  command "apt-get upgrade -y"
+end
+
+packages = %w{
+  build-essential
+  curl
+  exuberant-ctags
+  git-core
+  libcurl4-openssl-dev
+  libffi-dev
+  libreadline-dev
+  libsqlite3-dev
+  libssl-dev
+  libxml2-dev
+  libxslt1-dev
+  libyaml-dev
+  memcached
+  python-software-properties
+  redis-server
+  software-properties-common
+  sqlite3
+  unzip
+  zlib1g-dev
+}
+
+package packages do
+  action :install
+end
+
+execute "add-apt-repository_nginx" do
+  command "add-apt-repository -y ppa:nginx/stable"
+end
+
+package "nginx" do
+  action :install
+end
+
+remote_file "/tmp/phantomjs-1.9.8-linux-x86_64.tar.bz2" do
+  source "https://bitbucket.org/ariya/phantomjs/downloads/phantomjs-1.9.8-linux-x86_64.tar.bz2"
+  action :create
+end
+
+bash "install_phantomjs" do
+  user "root"
+  cwd "/tmp"
+  not_if { ::File.exist?("/usr/local/bin/phantomjs") }
+  command <<-SCRIPT
+    tar xvjf phantomjs-1.9.8-linux-x86_64.tar.bz2
+    mv phantomjs-1.9.8-linux-x86_64 /usr/local/share
+  SCRIPT
+end
+
+link "/usr/local/bin/phantomjs" do
+  to "/usr/local/share/bin/phantomjs"
+end
+
+bash "install postgres" do
+  not_if { ::File.exist?("/etc/apt/sources.list.d/pgdg.list") }
+  command <<-SCRIPT
+    echo "deb http://apt.postgresql.org/pub/repos/apt/ $(lsb_release -cs)-pgdg main" > /etc/apt/sources.list.d/pgdg.list
+    wget --quiet -O - https://www.postgresql.org/media/keys/ACCC4CF8.asc | apt-key add -
+    apt-get update -y
+    apt-get install -y postgresql-9.4 libpq-dev postgresql-contrib-9.4
+  SCRIPT
+end
+
+bash "create_vagrant_db" do
+  user "vagrant"
+  command <<-SCRIPT
+    createdb
+  SCRIPT
+end
+
+execute "install_node" do
+  command "curl -sL https://deb.nodesource.com/setup | bash -"
+end
+
+package ['nodejs'] do
+  action :install
+end
+
+bash "create_postgres_user" do
+  command <<-SCRIPT
+    createuser -s -e -w vagrant
+  SCRIPT
+end
+
+git "/usr/local/rbenv" do
+  repository "https://github.com/sstephenson/rbenv.git"
+  action :sync
+end
+
+bash "install_rbenv" do
+  user "root"
+  cwd "/tmp"
+  not_if { ::File.exist?("/etc/profile.d/rbenv.sh") }
+  code <<-EOH
+    echo 'export RBENV_ROOT="/usr/local/rbenv"' >> /etc/profile.d/rbenv.sh
+    echo 'export PATH="/usr/local/rbenv/bin:$PATH"' >> /etc/profile.d/rbenv.sh
+    echo 'eval "$(rbenv init -)"' >> /etc/profile.d/rbenv.sh
+  EOH
+end
+
+directory "/usr/local/rbenv/plugins" do
+  action :create
+end
+
+git "/usr/local/rbenv/plugins/ruby-build" do
+  repository "https://github.com/sstephenson/ruby-build.git"
+  action :sync
+end
+
+bash "install_ruby" do
+  user "root"
+  not_if { ::File.exist?("/usr/local/rbenv/shims/ruby") }
+  code <<-EOH
+    source /etc/profile.d/rbenv.sh
+    rbenv install 2.2.2
+    rbenv global 2.2.2
+  EOH
+end
+
+bash "install_bundler" do
+  user "root"
+  code <<-EOH
+    source /etc/profile.d/rbenv.sh
+    gem install bundler --no-ri --no-rdoc
+  EOH
+end
+
+bash "copy_env_local" do
+  user "vagrant"
+  cwd "/vagrant"
+  not_if { ::File.exist?("/vagrant/.env.local") }
+  code <<-EOH
+    cp .env.example .env.local
+  EOH
+end
Procfile
@@ -1,2 +1,2 @@
-web: bin/rails s -p 5000 -b 0.0.0.0
+web: bin/rails s -p 3000 -b 0.0.0.0
 worker: bundle exec sidekiq
Vagrantfile
@@ -3,43 +3,18 @@
 
 Vagrant.configure("2") do |config|
   config.vm.box = "phusion/ubuntu-14.04-amd64"
-
-  # Create a forwarded port mapping which allows access to a specific port
-  # within the machine from a port on the host machine. In the example below,
-  # accessing "localhost:8080" will access port 80 on the guest machine.
-  #config.vm.network :forwarded_port, guest: 80, host: 8080
-  config.vm.network :forwarded_port, guest: 5000, host: 3000
-  config.vm.provision :shell, :path => 'bin/bootstrap.sh'
-  config.ssh.forward_agent = true
-
-  # Create a private network, which allows host-only access to the machine
-  # using a specific IP.
-  #config.vm.network :private_network, ip: "192.168.33.10"
-
-  # Create a public network, which generally matched to bridged network.
-  # Bridged networks make the machine appear as another physical device on
-  # your network.
-  # config.vm.network :public_network
-
-  # Share an additional folder to the guest VM. The first argument is
-  # the path on the host to the actual folder. The second argument is
-  # the path on the guest to mount the folder. And the optional third
-  # argument is a set of non-required options.
-  # config.vm.synced_folder "../data", "/vagrant_data"
-
-  # Provider-specific configuration so you can fine-tune various
-  # backing providers for Vagrant. These expose provider-specific options.
-  # Example for VirtualBox:
-  #
-  # config.vm.provider :virtualbox do |vb|
-  #   # Don't boot with headless mode
-  #   vb.gui = true
-  #
-  #   # Use VBoxManage to customize the VM. For example to change memory:
-  #   vb.customize ["modifyvm", :id, "--memory", "1024"]
-  # end
+  config.vm.network :forwarded_port, guest: 3000, host: 3000
+  config.vm.provision :chef_apply do |chef|
+    chef.recipe = File.read("config/chef_apply.rb")
+    chef.version = :latest
+  end
   config.vm.provider :vmware_workstation do |vm|
     vm.gui = false
     vm.vmx["displayname"] = "stronglifters"
   end
+  config.vm.provider :vmware_fusion do |v|
+    v.vmx["memsize"] = "2048"
+    v.vmx["numvcpus"] = "2"
+  end
+  config.ssh.forward_agent = true
 end