Skip to content

Commit

Permalink
initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
mikegreiling committed Feb 9, 2015
0 parents commit 157db04
Show file tree
Hide file tree
Showing 18 changed files with 1,001 additions and 0 deletions.
7 changes: 7 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
.DS_Store
packer_cache/
.vagrant/
*.box
*.iso
*.tar.gz
output-*
71 changes: 71 additions & 0 deletions Rakefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@

# first is default
BOXES = %w( ubuntu1404 ubuntu1204 ).freeze

# namespace for each provider
provider_builder = lambda do |provider|
namespace provider do
desc "Build a box for #{provider} using packer (default: #{BOXES.first})"
task :build, [:box] do | t, args| build_box box_arg(args), provider; end

desc "Install a #{provider} box with vagrant (default: #{BOXES.first})"
task :install, [:box] do | t, args| install_box box_arg(args), provider; end

desc "Remove an installed vagrant box for #{provider} (default: #{BOXES.first})"
task :remove, [:box] do | t, args| remove_box box_arg(args), provider; end

desc "Build all boxes for #{provider} using packer"
task 'build-all' do BOXES.each { |box| build_box box, provider }; end

desc "Install all #{provider} boxes with vagrant"
task 'install-all' do BOXES.each { |box| install_box box, provider }; end

desc "Remove all #{provider} boxes from vagrant"
task 'remove-all' do BOXES.each { |box| remove_box box, provider }; end
end
end

provider_builder.call(:virtualbox)
provider_builder.call(:vmware)

desc "Remove compiled assets and cached files"
task :clean do
sh 'rm -f build/*.box && rm -rf packer_cache'
end

# shortcuts to virtualbox tasks with no namespace
task :build, [:box] => 'virtualbox:build'
task :install, [:box] => 'virtualbox:install'
task :remove, [:box] => 'virtualbox:remove'

# build a box for the specified provider
def build_box(box, provider)
log "Building #{box} for #{provider}"
sh "rm -f build/#{box}-opsworks-#{provider}.box && packer build -only=#{provider}-iso template/#{box}.json"
end

# build a box with vagrant
def install_box(box, provider)
file = "build/#{box}-opsworks-#{provider}.box"
build_box(box, provider) unless File.exists?(file)

log "Installing #{box}-opsworks for #{provider} with vagrant"
sh "vagrant box add #{file} --force --name=#{box}-opsworks"
end

# remove a box from vagrant
def remove_box(box, provider)
log "Removing #{box} for #{provider}"
provider = 'vmware_desktop' if provider.to_s == 'vmware'
sh "vagrant box remove #{box} --provider=#{provider}"
end

# validate input for tasks with optional parameters
def box_arg(args)
abort "Invalid box provided" if args[:box] && !BOXES.include?(args[:box])
args[:box] || BOXES.first
end

def log(msg)
puts "==> Rake: #{msg}"
end
1 change: 1 addition & 0 deletions build/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
*.box
11 changes: 11 additions & 0 deletions opsworks/Vagrantfile.template
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@

# require vagrant version 1.7.0 to allow for the named provisioners syntax
Vagrant.require_version(">= 1.7.0")
box_root = File.dirname(__FILE__)

Vagrant.configure("2") do |config|
config.vm.synced_folder box_root, '/tmp/vagrant-opsworks'
config.vm.provision 'opsworks', type: 'shell' do |shell|
shell.inline = '/bin/bash /tmp/vagrant-opsworks/opsworks "$@"'
end
end
16 changes: 16 additions & 0 deletions opsworks/client.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# opsworks chef client config file
# /var/lib/aws/opsworks/client.yml
---

:local_mode: true
:log_level: :info
:ohai_plugin_path: /opt/aws/opsworks/current/plugins
:cookbook_path: ["/opt/aws/opsworks/current/merged-cookbooks"]
:default_cookbooks_path: /opt/aws/opsworks/current/cookbooks
:site_cookbooks_path: /opt/aws/opsworks/current/site-cookbooks
:merged_cookbooks_path: /opt/aws/opsworks/current/merged-cookbooks
:berkshelf_cookbooks_path: /opt/aws/opsworks/current/berkshelf-cookbooks
:berkshelf_cache_path: /var/lib/aws/opsworks/berkshelf_cache
:file_cache_path: /var/lib/aws/opsworks/cache
:search_nodes_path: /var/lib/aws/opsworks/data/nodes
:data_bag_path: /var/lib/aws/opsworks/data/data_bags
51 changes: 51 additions & 0 deletions opsworks/opsworks
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
#!/bin/bash

# exit if no arguments provided
if [[ $# -eq 0 ]]; then
echo "Nothing to do..."
exit
fi

# install opsworks agent if not already available
if [[ ! -f /opt/aws/opsworks/current/VERSION ]]; then

# decide which agent version to install
if [[ -z $OPSWORKS_AGENT_VERSION ]]; then
OPSWORKS_AGENT_VERSION='33200020141203204624'
fi

# install dependencies
echo "Installing OpsWorks agent dependencies"
apt-get -yq update
apt-get -yq install curl libxml2-dev libxslt-dev libyaml-dev

# create expected directories and populate them with expected config files
mkdir -p /{etc,opt,var/{log,lib}}/aws/opsworks/ /var/lib/cloud/
cp $(dirname "${BASH_SOURCE[0]}")/{client.yml,pre_config.yml} /var/lib/aws/opsworks/

# create a temporary directory to work in
TMP_DIR=$(mktemp -d "opsworks-installer.XXXXXXXX")
trap 'rm -rf "$TMP_DIR"' EXIT
pushd $TMP_DIR

# download and install the requested opsworks agent
echo "Installing OpsWorks agent version $OPSWORKS_AGENT_VERSION"
wget -nv -O opsworks-agent-installer.tgz https://opsworks-instance-agent.s3.amazonaws.com/$OPSWORKS_AGENT_VERSION/opsworks-agent-installer.tgz
tar -xzpof opsworks-agent-installer.tgz
cd opsworks-agent-installer/opsworks-agent/bin/
./installer_wrapper.sh -R opsworks-instance-assets.s3.amazonaws.com

# return to our previous location and destroy our temporary directory
popd > /dev/null
rm -rf "$TMP_DIR"
trap - EXIT

# ensure we can access the opsworks chef gem
echo "export PATH=\$PATH:/opt/aws/opsworks/current/bin" > /etc/profile.d/opsworks_path.sh
fi

# set the vagrant shared directory as cwd if available
[ -d /vagrant ] && cd /vagrant

# run our provisioner
env /opt/aws/opsworks/local/bin/ruby $(dirname "${BASH_SOURCE[0]}")/opsworks.rb "$@"
Loading

0 comments on commit 157db04

Please sign in to comment.