Skip to content
This repository has been archived by the owner on Apr 17, 2020. It is now read-only.

Dev workflow with Guard + Rake #7

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,8 @@ source 'http://rubygems.org'
gem 'vagrant'
gem 'puppet'
gem 'rake'
gem 'guard'
gem 'guard-rake'
gem 'growl_notify'
gem 'vagrant-sync'
gem 'librarian-puppet', :git => 'https://github.com/benburkert/librarian-puppet.git'
16 changes: 16 additions & 0 deletions Guardfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# Guardfile for watching a local Razor source directory and calling Rake tasks to sync into [gold] VM on changes
# Place your Razor git clone into src/Razor

notification :growl_notify, :sticky => true, :priority => 0

guard 'rake', :task => 'src_spec' do
watch(%r{^src/Razor/spec/.+\.(rb|js|yaml|json)$})
end

guard 'rake', :task => 'src_bin' do
watch(%r{^src/Razor/bin/.+\.(rb|js|yaml|json)$})
end

guard 'rake', :task => 'src_lib' do
watch(%r{^src/Razor/lib/.+\.(rb|js|yaml|json)$})
end
89 changes: 68 additions & 21 deletions Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,33 +2,47 @@ require 'rake'
require 'net/ssh'
require 'net/scp'

RAZOR_SRC = 'src/Razor'
RAZOR_DST = '/opt/razor'
TMP_DIR = '/tmp/src_sync'

USER = PASSWORD = 'vagrant'
HOSTS = {
'gold' => '172.16.0.2',
'gold' => '172.16.0.2',
}

DISTROS = {
'microkernel' => {
:type => :mk,
:url => 'https://github.com/downloads/puppetlabs/Razor/rz_mk_dev-image.0.9.0.4.iso',
},
'ubuntu' => {
:release => 'ubuntu_precise',
:version => '12.04',
:url => 'http://releases.ubuntu.com/precise/ubuntu-12.04-server-amd64.iso',
},
'scientific' => {
:release => 'scientific',
:version => '6.2',
:url => 'https://github.com/downloads/puppetlabs/Razor/rz_mk_dev-image.0.8.9.0.iso',
},
'centos' => {
:release => 'centos',
:version => '6.2',
:url => 'http://mirror.metrocast.net/centos/6.2/isos/x86_64/CentOS-6.2-x86_64-minimal.iso',
},
'microkernel' => {
:type => :mk,
:url => 'https://github.com/downloads/puppetlabs/Razor/rz_mk_dev-image.0.9.0.4.iso',
},
'ubuntu' => {
:release => 'ubuntu_precise',
:version => '12.04',
:url => 'http://releases.ubuntu.com/precise/ubuntu-12.04-server-amd64.iso',
},
'scientific' => {
:release => 'scientific',
:version => '6.2',
:url => 'http://ftp.scientificlinux.org/linux/scientific/6.2/x86_64/iso/SL-62-x86_64-2012-02-06-Install-DVD.iso',
},
'centos' => {
:release => 'centos',
:version => '6.2',
:url => 'http://mirror.metrocast.net/centos/6.2/isos/x86_64/CentOS-6.2-x86_64-minimal.iso',
},
}

if RAZOR_SRC
SYNC_TREE = {}
%w(bin lib spec).each do |folder|
SYNC_TREE["src_#{folder}"] = {
:source => "#{RAZOR_SRC}/#{folder}",
}
end
end


def ssh(host, user = USER, password = PASSWORD)
(@ssh_connections ||= {})[host.to_s] ||= net_ssh(HOSTS[host.to_s], user, password)
end
Expand All @@ -42,7 +56,7 @@ def scp(host, local_path, remote_path, user = USER, password = PASSWORD)
end

def razor(*a)
puts ssh(:gold).exec!(['sudo /opt/razor/bin/razor', *a].join(' '))
puts ssh(:gold).exec!(['sudo ' + RAZOR_DST + '/bin/razor', *a].join(' '))
end

def download(url, options = {})
Expand All @@ -63,8 +77,11 @@ desc "Start here. Provision & configure the Razor server."
task :start do
sh('librarian-puppet install')
sh('vagrant up')

end



DISTROS.each do |name, options|
namespace name do
url = options[:url]
Expand All @@ -90,3 +107,33 @@ DISTROS.each do |name, options|

task name => "#{name}:setup"
end

if RAZOR_SRC
SYNC_TREE.each do |name, options|
namespace name do
source = options[:source]
target = TMP_DIR

desc "Replicate #{source} to #{target} on [gold]"
task :sync do
ssh(:gold).exec!('mkdir -p ' + TMP_DIR) # ensure tmpdir
sh("vagrant sync gold -f \'#{source}\' -t \'#{target}\'")
ssh(:gold).exec!("sudo cp -r #{target}/* #{RAZOR_DST}")
end
end

task name => "#{name}:sync"
end

namespace 'src' do
task :sync_all do
SYNC_TREE.each_key do |name|
Rake::Task["#{name}:sync"].execute
end
end
end
task 'src' => 'src:sync_all'
end