Permalink
Browse files

Initial Sprinkle source import

  • Loading branch information...
crafterm committed Feb 27, 2008
1 parent 777b795 commit fcbbd93fbfb96820ec38a10097185d6635fcf707
View
@@ -0,0 +1,20 @@
+Copyright (c) 2008 Marcus Crafter
+
+Permission is hereby granted, free of charge, to any person obtaining
+a copy of this software and associated documentation files (the
+"Software"), to deal in the Software without restriction, including
+without limitation the rights to use, copy, modify, merge, publish,
+distribute, sublicense, and/or sell copies of the Software, and to
+permit persons to whom the Software is furnished to do so, subject to
+the following conditions:
+
+The above copyright notice and this permission notice shall be
+included in all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
View
@@ -0,0 +1,7 @@
+require 'rake'
+require 'spec/rake/spectask'
+
+desc 'Run RSpec Suite'
+Spec::Rake::SpecTask.new('spec') do |t|
+ t.spec_files = FileList['spec/**/*_spec.rb']
+end
View
@@ -0,0 +1,18 @@
+set :application, "asb"
+
+# create a pseudo terminal for every command, otherwise SSH/SVN breaks
+#default_run_options[:pty] = true
+
+# If you aren't deploying to /u/apps/#{application} on the target
+# servers (which is the default), you can specify the actual location
+# via the :deploy_to variable:
+#set :deploy_to, "/path/to/sites/#{application}"
+
+# If you aren't using Subversion to manage your source code, specify
+# your SCM below:
+# set :scm, :subversion
+# set :user, "root"
+
+role :app, "yourhost.com"
+role :web, "yourhost.com"
+role :db, "yourhost.com", :primary => true
View
@@ -0,0 +1,104 @@
+#$:.unshift(File.dirname(__FILE__) + '/../lib')
+$: << File.expand_path(File.dirname(__FILE__) + '/../lib')
+
+
+## REVISIT: idea i'm toying with is that you have separate files for platforms, that way deploy doesn't have to know about
+# platform specifics, but perhaps thats something we want... needs further thought
+
+require 'rubygems'
+require 'sprinkle'
+
+## Special package, anything that defines a 'source' package means build-essential should be installed for Ubuntu
+
+package :build_essential do
+ description 'Build tools'
+ apt 'build-essential'
+end
+
+## Defines available packages
+
+package :ruby do
+ description 'Ruby Virtual Machine'
+ version '1.8.6'
+ source "ftp://ftp.ruby-lang.org/pub/ruby/1.8/ruby-#{version}-p111.tar.gz" # implicit :style => :gnu
+ requires :ruby_dependencies
+end
+
+package :ruby_dependencies do
+ description 'Ruby Virtual Machine Build Dependencies'
+ apt %w( bison zlib1g-dev libssl-dev libreadline5-dev libncurses5-dev file )
+end
+
+package :mysql, :provides => :database do
+ description 'MySQL Database'
+ apt %w( mysql-server mysql-client )
+end
+
+package :apache, :provides => :webserver do
+ description 'Apache 2 HTTP Server'
+ version '2.2.6'
+ source "http://apache.wildit.net.au/httpd/httpd-#{version}.tar.bz2" do
+ enable %w( mods-shared=all proxy proxy-balancer proxy-http rewrite cache headers ssl deflate so )
+ prefix "/opt/local/apache2-#{version}"
+ post :install, 'install -m 755 support/apachectl /etc/init.d/apache2', 'update-rc.d -f apache2 defaults'
+ end
+ requires :apache_dependencies
+end
+
+package :apache_dependencies do
+ description 'Apache 2 HTTP Server Build Dependencies'
+ apt %w( openssl libtool mawk zlib1g-dev libssl-dev )
+end
+
+package :rubygems do
+ description 'Ruby Gems Package Management System'
+ version '1.0.1'
+ source "http://rubyforge.org/frs/download.php/29548/rubygems-#{version}.tgz" do
+ custom_install 'ruby setup.rb'
+ end
+ requires :ruby
+end
+
+package :rails do
+ description 'Ruby on Rails'
+ gem 'rails'
+ version '2.0.2'
+end
+
+package :mongrel, :provides => :appserver do
+ description 'Mongrel Application Server'
+ gem 'mongrel'
+ version '1.1.3'
+end
+
+package :mongrel_cluster do
+ description 'Cluster Management for Mongrel'
+ gem 'mongrel_cluster'
+ version '1.0.5'
+ requires :mongrel
+end
+
+
+## Define a policy that applies to what roles of machines
+
+policy :rails, :roles => :app do
+ requires :rails, :version => '2.0.2'
+ requires :appserver
+ requires :database
+ requires :webserver
+end
+
+deployment do
+
+ # better name
+ delivery :capistrano
+
+ # installer defaults
+ source do
+ prefix '/usr/local'
+ archives '/usr/local/sources'
+ builds '/usr/local/build'
+ end
+
+end
+
View
@@ -0,0 +1,25 @@
+require 'active_support'
+require 'sprinkle/extensions/string'
+require 'sprinkle/extensions/array'
+require 'sprinkle/extensions/symbol'
+require 'sprinkle/package'
+require 'sprinkle/policy'
+require 'sprinkle/deployment'
+require 'sprinkle/installers/installer'
+require 'sprinkle/installers/source'
+require 'sprinkle/installers/apt'
+require 'sprinkle/installers/gem'
+
+class Object
+ include Sprinkle
+end
+
+actor = ENV['DACTOR']
+
+if actor
+ # some other target?
+else
+ require 'sprinkle/actors/capistrano'
+
+ # more work here
+end
@@ -0,0 +1,72 @@
+require 'capistrano/cli'
+
+module Sprinkle
+ module Actors
+ class Capistrano
+
+ def initialize
+ @config = ::Capistrano::Configuration.new
+ @config.logger.level = ::Capistrano::Logger::TRACE
+ @config.set(:password) { ::Capistrano::CLI.password_prompt }
+ @config.load "deploy" # normally config/deploy in rails
+ end
+
+ # better name
+
+ def process(name, commands, roles)
+ define_task(name, roles) do
+ via = fetch(:run_method, :sudo)
+ commands.each do |command|
+ invoke_command command, :via => via
+ end
+ end
+ run(name)
+ end
+
+ private
+
+ # REVISIT: can we set the description somehow?
+ def define_task(name, roles, &block)
+ @config.task task_sym(name), :roles => roles, &block
+ end
+
+ def run(task)
+ @config.send task_sym(task)
+ end
+
+ def task_sym(name)
+ "install_#{name.to_task_name}".to_sym
+ end
+ end
+ end
+end
+
+
+=begin
+
+# channel: the SSH channel object used for this response
+# stream: either :err or :out, for stderr or stdout responses
+# output: the text that the server is sending, might be in chunks
+run "apt-get update" do |channel, stream, output|
+ if output =~ /Are you sure?/
+ answer = Capistrano::CLI.ui.ask("Are you sure: ")
+ channel.send_data(answer + "\n")
+ else
+ # allow the default callback to be processed
+ Capistrano::Configuration.default_io_proc.call[channel, stream, output]
+ end
+ end
+
+
+
+ You can tell subversion to use a different username+password by
+ setting a couple variables:
+ set :svn_username, "my svn username"
+ set :svn_password, "my svn password"
+ If you don't want to set the password explicitly in your recipe like
+ that, you can make capistrano prompt you for it like this:
+ set(:svn_password) { Capistrano::CLI.password_prompt("Subversion
+ password: ") }
+ - Jamis
+=end
+
View
@@ -0,0 +1,35 @@
+module Sprinkle
+
+ def deployment(&block)
+ Deployment.new(&block)
+ end
+
+ # REVISIT: deployment context - better name?
+ class Deployment
+ attr_accessor :style, :defaults
+
+ def initialize(&block)
+ @defaults = {}
+ self.instance_eval(&block)
+ process
+ end
+
+ def delivery(type)
+ @style = Actors.const_get(type.to_s.titleize).new
+ end
+
+ def source(&block)
+ @defaults[:source] = block
+ end
+
+ private
+
+ def process
+ @@policies.each do |policy|
+ policy.process(self)
+ end
+ end
+ end
+
+end
+
@@ -0,0 +1,7 @@
+class Array
+
+ def to_task_name
+ collect(&:to_task_name).join('_')
+ end
+
+end
@@ -0,0 +1,10 @@
+class String
+
+ # REVISIT: what chars shall we allow in task names?
+ def to_task_name
+ s = downcase
+ s.gsub!(/-/, '_') # all - to _ chars
+ s
+ end
+
+end
@@ -0,0 +1,7 @@
+class Symbol
+
+ def to_task_name
+ to_s.to_task_name
+ end
+
+end
@@ -0,0 +1,17 @@
+module Sprinkle
+ module Installers
+ class Apt < Installer
+ def initialize(parent, packages, &block)
+ super parent, &block
+ packages = [packages] unless packages.is_a? Array
+ @packages = packages
+ end
+
+ protected
+
+ def install_sequence
+ "apt-get -y install #{@packages.join(' ')}"
+ end
+ end
+ end
+end
@@ -0,0 +1,23 @@
+module Sprinkle
+ module Installers
+ class Gem < Installer
+ def initialize(parent, gem, &block)
+ super parent, &block
+ @gem = gem
+ end
+
+ protected
+
+ # rubygems 0.9.5+ installs dependencies by default, and does platform selection
+ # REVISIT: assume yes? how do we handle multiple versions? install version specified in the package if available
+
+ def install_sequence
+ unless version
+ ["gem install #{@gem}"]
+ else
+ ["gem install #{@gem} --version #{version}"]
+ end
+ end
+ end
+ end
+end
Oops, something went wrong.

0 comments on commit fcbbd93

Please sign in to comment.