Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Can now bootstrap an ec2 instance and run chef

  • Loading branch information...
commit 984bf0b512fc3f17bff61fe17414c07e72cc5052 1 parent c197511
Matthew Kocher authored
45 Capfile
View
@@ -1,6 +1,45 @@
require 'capistrano/ext/multistage'
-desc "ls root dir"
-task :ls, :role => :app do
- run "ls /"
+$:.unshift(File.expand_path('./lib', ENV['rvm_path'])) # Add RVM's lib directory to the load path.
+require "rvm/capistrano" # Load RVM's capistrano plugin.
+set :rvm_ruby_string, 'ruby-1.8.7-p299@testgemset' # Or whatever env you want it to run in.
+set :rvm_type, :user
+
+set :app_name, :foo
+set :app_dir { "/var/#{stage}/#{app_name}" }
+set :user, "mkocher"
+default_run_options[:pty] = true
+
+desc "Deploys"
+task :deploy do
+ install_base_gems
+ upload_cookbooks
+ run_chef
+end
+
+desc "Install gems that are needed for a chef run"
+task :install_base_gems do
+ run "gem list | grep soloist || gem install soloist --no-rdoc --no-ri"
+end
+
+desc "Upload cookbooks"
+task :upload_cookbooks do
+ run "sudo mkdir -p #{app_dir}"
+ run "sudo chown -R #{user} #{app_dir}"
+ upload("soloistrc", "#{app_dir}/soloistrc")
+ upload("chef/", "#{app_dir}/chef/", :via => :scp, :recursive => true)
+end
+
+desc "Run Chef"
+task :run_chef do
+ run "cd #{app_dir} && soloist"
+end
+
+desc "bootstrap"
+task :bootstrap do
+ set :user, "root"
+ set :default_shell, "/bin/bash"
+ upload "bootstrap.sh", "/root/bootstrap.sh"
+ run "chmod a+x /root/bootstrap.sh"
+ run "/root/bootstrap.sh"
end
3  Gemfile
View
@@ -1,3 +1,4 @@
source "http://rubygems.org"
gem "capistrano"
-gem "capistrano-ext"
+gem "capistrano-ext"
+gem "soloist"
42 Gemfile.lock
View
@@ -1,6 +1,8 @@
GEM
remote: http://rubygems.org/
specs:
+ abstract (1.0.0)
+ bunny (0.6.0)
capistrano (2.5.19)
highline
net-scp (>= 1.0.0)
@@ -9,7 +11,32 @@ GEM
net-ssh-gateway (>= 1.0.0)
capistrano-ext (1.2.1)
capistrano (>= 1.0.0)
+ chef (0.9.12)
+ bunny (>= 0.6.0)
+ erubis
+ extlib
+ highline
+ json (>= 1.4.4, <= 1.4.6)
+ mixlib-authentication (>= 1.1.0)
+ mixlib-cli (>= 1.1.0)
+ mixlib-config (>= 1.1.2)
+ mixlib-log (>= 1.2.0)
+ moneta
+ ohai (>= 0.5.7)
+ rest-client (>= 1.0.4, < 1.7.0)
+ uuidtools
+ erubis (2.6.6)
+ abstract (>= 1.0.0)
+ extlib (0.9.15)
highline (1.6.1)
+ json (1.4.6)
+ mime-types (1.16)
+ mixlib-authentication (1.1.4)
+ mixlib-log
+ mixlib-cli (1.2.0)
+ mixlib-config (1.1.2)
+ mixlib-log (1.2.0)
+ moneta (0.6.0)
net-scp (1.0.4)
net-ssh (>= 1.99.1)
net-sftp (2.0.5)
@@ -17,6 +44,20 @@ GEM
net-ssh (2.0.23)
net-ssh-gateway (1.0.1)
net-ssh (>= 1.99.1)
+ ohai (0.5.8)
+ extlib
+ json (>= 1.4.4, <= 1.4.6)
+ mixlib-cli
+ mixlib-config
+ mixlib-log
+ systemu
+ rest-client (1.6.1)
+ mime-types (>= 1.16)
+ soloist (0.0.7)
+ chef (= 0.9.12)
+ json (= 1.4.6)
+ systemu (1.2.0)
+ uuidtools (2.1.2)
PLATFORMS
ruby
@@ -24,3 +65,4 @@ PLATFORMS
DEPENDENCIES
capistrano
capistrano-ext
+ soloist
41 bootstrap.sh
View
@@ -0,0 +1,41 @@
+#!/bin/bash -e
+export app_user="mkocher"
+
+# perl -e 'print crypt("password", "salt"),"\n"'
+getent passwd $app_user >/dev/null 2>&1 || useradd $app_user -p sa3tHJ3/KuYvI
+
+## enable ssh password auth
+perl -p -i -e 's/PasswordAuthentication no/PasswordAuthentication yes/' /etc/ssh/sshd_config
+/etc/init.d/sshd reload
+
+# install epel
+rpm -q epel-release-5-4.noarch || rpm -Uvh http://download.fedora.redhat.com/pub/epel/5/x86_64/epel-release-5-4.noarch.rpm
+
+# install git
+yum -y install git
+
+# rvm prereqs
+yum install -y gcc-c++ patch readline readline-devel zlib zlib-devel libyaml-devel libffi-devel openssl-devel iconv-devel java
+
+# passwordless sudo
+sudo_string='ALL ALL = (ALL) NOPASSWD: ALL'
+grep "$sudo_string" /etc/sudoers || echo "$sudo_string" >> /etc/sudoers
+
+cat <<'BOOTSTRAP_AS_USER' > /home/$app_user/bootstrap_as_user.sh
+set -e
+
+bash < <( curl http://rvm.beginrescueend.com/releases/rvm-install-head )
+
+rvm_include_string='[[ -s "$HOME/.rvm/scripts/rvm" ]] && source "$HOME/.rvm/scripts/rvm"'
+grep "$rvm_include_string" ~/.bashrc || echo "$rvm_include_string" >> ~/.bashrc
+
+cat <<'RVMRC_CONTENTS' > ~/.rvmrc
+rvm_install_on_use_flag=1
+rvm_trust_rvmrcs_flag=1
+rvm_gemset_create_on_use_flag=1
+RVMRC_CONTENTS
+BOOTSTRAP_AS_USER
+
+chmod a+x /home/$app_user/bootstrap_as_user.sh
+su - $app_user /home/$app_user/bootstrap_as_user.sh
+rm /home/$app_user/bootstrap_as_user.sh
3  chef/cookbooks/joy_of_cooking/recipes/default.rb
View
@@ -0,0 +1,3 @@
+execute "Say Hello" do
+ command "echo 'its very dark' > /help_im_stuck_in_the_machine"
+end
1  config/deploy/localhost.rb
View
@@ -1 +0,0 @@
-role :app, "localhost"
1  config/deploy/other.rb
View
@@ -1 +0,0 @@
-role :app, "matthewkocher.com"
3  config/deploy/staging.rb
View
@@ -0,0 +1,3 @@
+
+
+role :app, "ec2-184-73-47-68.compute-1.amazonaws.com"
4 soloistrc
View
@@ -0,0 +1,4 @@
+cookbook_paths:
+- ./chef/cookbooks/
+recipes:
+- joy_of_cooking
Please sign in to comment.
Something went wrong with that request. Please try again.