Skip to content
This repository has been archived by the owner on Sep 26, 2021. It is now read-only.

Commit

Permalink
Gemify
Browse files Browse the repository at this point in the history
  • Loading branch information
Pranav Raja committed Aug 2, 2013
1 parent e15991a commit 4696482
Show file tree
Hide file tree
Showing 18 changed files with 228 additions and 190 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
credentials.yml
config.yml
8 changes: 2 additions & 6 deletions Gemfile
Original file line number Diff line number Diff line change
@@ -1,8 +1,4 @@
source :rubygems

gem 'aws-sdk'

group :development, :test do
gem 'rspec'
end

gem 'rake'
gemspec
10 changes: 9 additions & 1 deletion Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
PATH
remote: .
specs:
beanstalkify (0.0.1)
aws-sdk

GEM
remote: http://rubygems.org/
specs:
Expand All @@ -8,6 +14,7 @@ GEM
diff-lcs (1.2.4)
json (1.8.0)
nokogiri (1.5.10)
rake (10.0.3)
rspec (2.14.1)
rspec-core (~> 2.14.0)
rspec-expectations (~> 2.14.0)
Expand All @@ -22,5 +29,6 @@ PLATFORMS
ruby

DEPENDENCIES
aws-sdk
beanstalkify!
rake
rspec
5 changes: 2 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,10 @@
# Prerequisites

- Ruby 1.9
- bundler

# Setup
# Installation

bundle install
gem install beanstalkify

Create a file called `credentials.yml`, with the following format:

Expand Down
1 change: 1 addition & 0 deletions Rakefile
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
require 'bundler/gem_tasks'
36 changes: 0 additions & 36 deletions application.rb

This file was deleted.

20 changes: 0 additions & 20 deletions archive.rb

This file was deleted.

13 changes: 0 additions & 13 deletions beanstalk.rb

This file was deleted.

21 changes: 21 additions & 0 deletions beanstalkify.gemspec
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# -*- encoding: utf-8 -*-
$:.push File.expand_path("../lib", __FILE__)
require 'beanstalkify/version'

Gem::Specification.new do |s|
s.name = 'beanstalkify'
s.version = Beanstalkify::VERSION
s.summary = "Beanstalk automation for dummies"
s.description = "Create Amazon Elastic Beanstalk apps and deploy versions from the command line"
s.authors = ["Pranav Raja"]
s.email = 'rickdangerous1@gmail.com'
s.files = `git ls-files`.split("\n")
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
s.require_paths = ["lib"]
s.homepage = 'https://github.com/pranavraja/beanstalkify'
s.license = 'MIT'

s.add_dependency 'aws-sdk'
s.add_development_dependency "rspec"
end
10 changes: 5 additions & 5 deletions beanstalkify → bin/beanstalkify
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
#!/usr/bin/env ruby
require 'optparse'
require 'yaml'
require './beanstalk'
require './application'
require 'beanstalkify/beanstalk'
require 'beanstalkify/application'

options = {}
OptionParser.new do |opts|
Expand All @@ -25,11 +25,11 @@ end.parse!

required_params = [:credentials, :archive, :environment, :stack]
unless (required_params - options.keys).empty?
puts "Example usage: beanstalkify.rb -k credentials.yml -a AppName-version.zip -e AppName-test -s '64bit Amazon Linux running Node.js' -c config.yml"
puts "Example usage: beanstalkify -k credentials.yml -a AppName-version.zip -e AppName-test -s '64bit Amazon Linux running Node.js' -c config.yml"
exit
end

Beanstalk.configure! options[:credentials]
app = Application.new(options[:stack], options[:config] || [])
Beanstalkify::Beanstalk.configure! options[:credentials]
app = Beanstalkify::Application.new(options[:stack], options[:config] || [])
app.deploy!(options[:archive], options[:environment])

48 changes: 0 additions & 48 deletions deploy.rb

This file was deleted.

58 changes: 0 additions & 58 deletions environment.rb

This file was deleted.

38 changes: 38 additions & 0 deletions lib/beanstalkify/application.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
require 'beanstalkify/environment'
require 'beanstalkify/deploy'

module Beanstalkify
class Application
attr_accessor :stack, :config

# config is an array of hashes:
# :namespace, :option_name, :value
def initialize(stack, config)
@stack = stack
@config = config.map { |c| Hash[c.map { |k, v| [k.to_sym,v]}] }
end

# Deploy an archive to an environment.
# If the environment doesn't exist, it will be created.
def deploy!(archive, environment_name)
deployment = Deploy.new(archive)
env = Environment.new(environment_name)
if deployment.deployed?
puts "#{deployment.application.version} is already uploaded."
else
deployment.upload!
deployment.wait!
end
if env.status.empty?
puts "Creating stack '#{@stack}' for #{deployment.application.name}-#{deployment.application.version}..."
env.create!(deployment.application, @stack, @config)
env.wait!("Launching")
else
puts "Deploying #{deployment.application.version} to #{environment_name}..."
env.deploy!(deployment.application, @config)
env.wait!("Updating")
end
puts "Done. Visit http://#{env.url} in your browser."
end
end
end
22 changes: 22 additions & 0 deletions lib/beanstalkify/archive.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@

module Beanstalkify
class Archive
attr_accessor :path

def initialize(path)
@path = path
end

def name
filename.split('-')[0]
end

def version
File.basename(@path, '.*').split('-')[-1]
end

def filename
File.basename(@path)
end
end
end
15 changes: 15 additions & 0 deletions lib/beanstalkify/beanstalk.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
require 'aws-sdk'

module Beanstalkify
class Beanstalk
@@config = {}
def self.configure!(config={})
# Convert string keys to symbols
@@config = Hash[config.map{|(k,v)| [k.to_sym,v]}]
end
def self.api
AWS.config(@@config)
AWS::ElasticBeanstalk.new.client
end
end
end
Loading

0 comments on commit 4696482

Please sign in to comment.