Saturday, November 28, 2009

What If Hosting Was a Library?

# Was thinking, "if hosting was a library, what might it look like..."

require 'ProviderX'

# We'll pretend we already have an account with fictitious ProviderX

host = ProviderX.new(:user => 'foo', :password => 'secret')

# Let's see what ProviderX will allow us to deploy to

host.provides
> ['Amazon', 'Google']

# Let's create a new environment to deploy to

production = host.cloud.new(:vendor => 'Amazon', :name => 'production', :min_cpu => 2, :min_mem => 1024)

# We also would need to define the application that we wish to deploy

application = host.application.new(:repository => 'http://foo.com/foo.git', :type => 'Rails', :name => 'foo', :domain => 'foo.com', :ssl_enabled => true)

# All set! Let's deploy.

application.deploy_to production

application.deployed?
> true

application.deployed_to
> ['production']

production.applications
> ['foo']

# Maybe we forgot that we want to redirect www.foo.com to foo.com

application.redirects.add :from => 'www.foo.com', :to => 'foo.com'

# We don't want to deploy the code again, we just want to sync configuration changes (the redirect).

application.sync_configs production

# Perhaps we could control our resources from within our application

if production.swapping?
  production.ram.add 128
end

# That's it for my day-dreaming.

1 comment:

  1. The vendors should just conform to the host interface. Less typing, more explicit.

    production = Amazon::Cloud.new(blah blah)

    Honestly, I've learned to live without stuff like Capistrano though and realized my life is simpler for it. Shell scripts FTW. :-)

    ReplyDelete