Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Moonshine

 Moonshine

Introducing Moonshine, the Rails-focused Ruby DSL for Puppet. Presented at ATLRUG in 2009

Jesse Newland

October 02, 2011
Tweet

More Decks by Jesse Newland

Other Decks in Technology

Transcript

  1. It’s easy, I’ll just use Capistrano. gem install rmagick apt‐get

    install libmagick10 libmagick9‐dev ssh [email protected] Thursday, January 15, 2009
  2. It’s easy, I’ll just use Capistrano. gem install rmagick apt‐get

    install libmagick10 libmagick9‐dev ssh [email protected] apt‐get install mysql‐ server libmysql‐ruby libmysqlclient15‐dev Thursday, January 15, 2009
  3. It’s easy, I’ll just use Capistrano. gem install rmagick apt‐get

    install libmagick10 libmagick9‐dev ssh [email protected] vi /etc/my.cnf apt‐get install mysql‐ server libmysql‐ruby libmysqlclient15‐dev Thursday, January 15, 2009
  4. It’s easy, I’ll just use Capistrano. gem install rmagick apt‐get

    install libmagick10 libmagick9‐dev ssh [email protected] vi /etc/my.cnf apt‐get install mysql‐ server libmysql‐ruby libmysqlclient15‐dev /etc/init.d/mysql start Thursday, January 15, 2009
  5. A Series of Dependencies • Rails v2.2.2, v1.2.3, etc •

    Ruby/Ruby Enterprise • Apache/Nginx • Passenger/Thin/Mongrel • MySQL/PostgreSQL • system user Thursday, January 15, 2009
  6. A Series of Dependencies • rmagick • libmagick10 libmagick9-dev •

    thinking-sphinx • compile by hand • memcached • libmemcached, rubygem, service Thursday, January 15, 2009
  7. • impossible to verify • not revisioned • no ‘migrations’

    • not DRY • not testable Thursday, January 15, 2009
  8. Moonshine::Manifest #config/moonshine/default.rb class Moonshine::Manifest::Rails::Production < Moonshine::Manifest::Rails #packages(%w(vim curl)) #service('memcached', %w(memcache

    libmemcached)) #puppet.exec 'foo', # :command => "echo 'normal puppet stuff' > /tmp/test" end Thursday, January 15, 2009
  9. • Ubuntu • Apache • Passenger • Ruby Enterprise Edition

    • MySQL • ‘rails’ user • /srv/rails Decisions We’ve Made For You Thursday, January 15, 2009
  10. class Moonshine::Manifest::Rails < Moonshine::Manifest requires [ :user, :ruby, :rubygems, :db,

    :web, :rails, :deploy ] provides :user, 'rails' provides :ruby, 'enterprise_ruby' provides :rubygems, 'enterprise_rubygems' provides :db, 'mysql' provides :web, 'apache2' provides :rails, 'passenger' provides :deploy, 'git' end Look at all the choices I’m not making Thursday, January 15, 2009
  11. Answer some questions • application name • git repo •

    branch to deploy from • user to create • generates SSH key for git host • server ‘tags’ Thursday, January 15, 2009
  12. Moonshine goes to work • clones your repo • parses

    and executes generated moonshine manifests • installs needed gems • install dependencies • migrates your db • deploys your app Thursday, January 15, 2009
  13. Gem Dependencies gem_dependencies do |gem| #lots of dependencies are specified

    for you already #gem.packages 'mysql', %w(mysql‐dev libmysqlclient5‐dev) #gem.packages 'rmagick', %w(ruby‐dev libmagick9‐dev) #... #can specify a mini‐manifest to satisfy before #installation of this gem gem.custom 'urgem' do |puppet| puppet.file '/file/needed/by/ur/gem', :ensure => 'present', :content => 'foo' build_tarball('http://whatever.com/lib‐something.tgz') end end Thursday, January 15, 2009
  14. On subsequent runs • updates your repo • parses and

    executes updated moonshine manifests • verifies needed gems • verifies dependencies • migrates your db • deploys your app Thursday, January 15, 2009
  15. • Reproducible • Verified from top-bottom on each deploy •

    Versionable with your application • same commit can contain, for example, thinking sphinx and installation of the sphinx searchd daemon • DRY Deployment is now... Thursday, January 15, 2009
  16. Puppet Based class MysqlMain < Moonshine::Manifest puppet.file '/etc/my.cnf', :ensure =>

    'present', :content => """ [client] port = 3306 socket = /var/run/mysqld/mysqld.sock [mysqld] default‐character‐set = utf8 key_buffer = 16M max_allowed_packet = 16M thread_stack = 128K thread_cache_size = 8 """ end Thursday, January 15, 2009
  17. But Ruby class MysqlMain < Moonshine::Manifest puppet.file '/etc/my.cnf', :ensure =>

    'present', :content => ArbitraryKlass.arbitrary_function('foo') end Thursday, January 15, 2009
  18. Modular UrClass < Moonshine::Manifest::Rails < Moonshine::Manifest •easy to create your

    own reusable server manifests •extend existing ones with modules Thursday, January 15, 2009
  19. Sample ‘plugin’ module MoonshineOrderedPackages def packages(array_or_name, params = {}) package_array

    = array_or_name.to_a params = { :ensure => 'installed' }.merge(params) package_array.each_with_index do |name,index| #ensure packages are installed in order given package_params = params if package_array[index+1] package_params.merge({ :before => package(package_array[index+1]) }) end puppet.package name.to_s, package_params end end end Moonshine::Manifest::Rails.send(:extend, MoonshineOrderedPackages) Thursday, January 15, 2009