simple_deployer 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
data/README.markdown ADDED
@@ -0,0 +1,42 @@
1
+ Simple_deployer allows to use Simpledeployer.com from the command line
2
+ ========================================================
3
+
4
+ This library wraps the REST API for managing and deploying Rails apps to the
5
+ Simpledeployer. It can be called as a Ruby library, or invoked from the
6
+ command line. Code push and pull is done through Amazon S3.
7
+
8
+ For more about Simpledeployer see <http://simpledeployer.com>.
9
+
10
+
11
+ Setup
12
+ -----
13
+
14
+ 1. install SD gem - sudo gem install simple_deployer
15
+ 2. type sd in command line
16
+
17
+ List of available commands
18
+ -------------------------
19
+ sd info - account info
20
+
21
+ sd projects - projects list for current user
22
+ sd project pr_id - project info
23
+ sd project.create - create a project from with source code from current folder
24
+ sd project.servers pr_id - servers list for project pr_id
25
+ sd project.launch_server pr_id - launch new server in project pr_id
26
+ sd project.databases pr_id - list of databases in project pr_id
27
+ sd project.load_balancer pr_id - load balancer in project pr_id
28
+ sd project.deploy_folder pr_id - deploy current folder content in all servers of project pr_id
29
+ sd project.deploy pr_id - deploy latest code to all servers of project pr_id
30
+
31
+ sd server server_id - server status of server_id server
32
+ sd server.reboot server_id - reboot server server_id
33
+ sd server.terminate server_id - terminate server server_id
34
+
35
+
36
+
37
+ Sample workflow
38
+
39
+ 1) create project with sources from current folder - sd project.create
40
+ 2) launch server - sd project.launch_server (you can omit pr_id parameter - by default it is id of project you created on first step)
41
+ 3) Deploy latest code from current folder - sd project.deploy_folder
42
+ 4) Terminate server - sd server.terminate server_id where server_id you can get from step 2
data/Rakefile ADDED
@@ -0,0 +1,20 @@
1
+ begin
2
+ require 'jeweler'
3
+ Jeweler::Tasks.new do |gemspec|
4
+ gemspec.name = "simple_deployer"
5
+ gemspec.summary = "Appoxy simple_deployer Gem"
6
+ gemspec.description = "Appoxy simple_deployer Gem"
7
+ gemspec.email = "roman@appoxy.com"
8
+ gemspec.homepage = "http://www.simpledeployer.com"
9
+ gemspec.files = FileList["[A-Z]*", "lib/**/*", "bin/sd"]
10
+ gemspec.authors = ["Roman Kononov"]
11
+ gemspec.executables = "sd"
12
+ gemspec.add_dependency 'aws'
13
+ gemspec.add_dependency 'zip'
14
+ gemspec.add_dependency 'appoxy_rails'
15
+ gemspec.add_development_dependency "rake"
16
+ end
17
+ Jeweler::GemcutterTasks.new
18
+ rescue LoadError
19
+ puts "Jeweler not available. Install it with: sudo gem install jeweler -s http://gems.github.com"
20
+ end
data/VERSION.yml ADDED
@@ -0,0 +1,7 @@
1
+
2
+ :major: 0
3
+ :minor: 1
4
+ :patch: 1
5
+
6
+
7
+
data/bin/sd ADDED
@@ -0,0 +1,13 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ lib = File.expand_path(File.dirname(__FILE__) + '/../lib')
4
+ $LOAD_PATH.unshift(lib) if File.directory?(lib) && !$LOAD_PATH.include?(lib)
5
+
6
+ require 'simple_deployr'
7
+ require 'simple_deployr/command'
8
+
9
+ args = ARGV.dup
10
+ ARGV.clear
11
+ command = args.shift.strip rescue 'help'
12
+
13
+ SimpleDeployr::Command.run(command, args)
@@ -0,0 +1,77 @@
1
+ require 'aws'
2
+ require 'appoxy_rails'
3
+ module SimpleDeployer
4
+
5
+ class Service < Appoxy::Api::Client
6
+
7
+ attr_accessor :config
8
+
9
+
10
+ def initialize(config, options={})
11
+ puts 'Starting SimpleDeployer...'
12
+ self.config = config
13
+ super("http://www.simpledeployer.com/api/", config.access_key, config.secret_key, options)
14
+ self.host = self.config.host if self.config && self.config.host
15
+ self.version = "0.2"
16
+ end
17
+
18
+
19
+ def project_info(project_id)
20
+ project = get("project/#{project_id}")
21
+ end
22
+
23
+
24
+ def create_project(name, filename, aws_access_key, aws_secret_key)
25
+ data = {"name"=>name, "scm_url"=>filename, "aws_access_key"=>aws_access_key, "aws_secret_key"=>aws_secret_key}
26
+ ret = post("projects", data)
27
+ end
28
+
29
+
30
+ def launch_server(project_id)
31
+ data = {"launch_in_worker"=>"true"}
32
+ ret = get("projects/#{project_id}/launch_server", data)
33
+ end
34
+
35
+
36
+ def servers_list(project_id)
37
+ servers = get("projects/#{project_id}/servers")
38
+ end
39
+
40
+
41
+ def databases_list(project_id)
42
+ databases = get("projects/#{project_id}/databases")
43
+ end
44
+
45
+
46
+ def load_balancer(project_id)
47
+ load_balancer = get("projects/#{project_id}/load_balancer")
48
+ end
49
+
50
+
51
+ def projects_list()
52
+ projects = get("projects")
53
+ end
54
+
55
+
56
+ def deploy_code(project_id, params={})
57
+ data = params
58
+ p "DATA is" + data.to_s
59
+ ret = get("projects/#{project_id}/deploy_code", data)
60
+ end
61
+
62
+
63
+ def server_status(server_id)
64
+ status = get("servers/#{server_id}")
65
+ end
66
+
67
+
68
+ def reboot_server(server_id)
69
+ get("servers/#{server_id}/reboot")
70
+ end
71
+
72
+
73
+ def terminate_server(server_id)
74
+ delete("servers/#{server_id}")
75
+ end
76
+ end
77
+ end
@@ -0,0 +1,31 @@
1
+ require 'simple_deployer/commands/base'
2
+ Dir["#{File.dirname(__FILE__)}/commands/*.rb"].each { |c| require c }
3
+ module SimpleDeployer
4
+ module Command
5
+ class << self
6
+ def run(command, args)
7
+ config = Config.new()
8
+ config.read()
9
+ begin
10
+ service = SimpleDeployer::Service.new(config) #authorization should be there
11
+ klass, method = parse(command)
12
+ runner = klass.new(args, service)
13
+ runner.send(method)
14
+ rescue RestClient::RequestTimeout
15
+ p "API request timed out."
16
+ rescue NameError,NoMethodError =>ex
17
+ p "Invalid command please type 'sd' for help"
18
+ p ex.inspect
19
+ end
20
+ end
21
+
22
+
23
+ def parse(command)
24
+ begin
25
+ parts = command.split(".")
26
+ return eval("SimpleDeployer::Command::#{parts[0].capitalize}"), parts[1] ? parts[1].to_sym : :main
27
+ end
28
+ end
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,46 @@
1
+ module SimpleDeployer::Command
2
+ class CommandsBase
3
+ def initialize(args, service)
4
+ @args = args
5
+ @service = service
6
+ end
7
+
8
+
9
+ private
10
+ def upload(file)
11
+ f = File.open(file, "r")
12
+ data = ''
13
+ f.each_line do |line|
14
+ data += line
15
+ end
16
+ @service.config.s3_bucket.put(File.basename(file), data)
17
+ end
18
+
19
+
20
+ def package(path)
21
+ require 'zip/zip'
22
+ path.sub!(%r[/$], '')
23
+ archive = File.join(path, File.basename(path))+'.zip'
24
+ FileUtils.rm archive, :force=>true
25
+ Zip::ZipFile.open(archive, 'w') do |zipfile|
26
+ Dir["#{path}/**/**"].each do |file|
27
+ zipfile.add(file.sub(path+'/', ''), file)
28
+ end
29
+ end
30
+ return archive
31
+ end
32
+
33
+
34
+ def get_project
35
+ @pr_id = @args.empty? ? @service.config.project_id : @args[0]
36
+ raise "You should define project id" unless @pr_id
37
+ end
38
+
39
+
40
+ def get_server
41
+ @server_id = @args ? @args[0] : nil
42
+ raise "You should define server id" unless @server_id
43
+ end
44
+
45
+ end
46
+ end
@@ -0,0 +1,27 @@
1
+ module SimpleDeployer::Command
2
+ class Help < CommandsBase
3
+ def main
4
+ help = <<EOF
5
+ Available commands
6
+
7
+ sd info - account info
8
+
9
+ sd projects - projects list for current user
10
+ sd project pr_id - project info
11
+ sd project.create - create a project from with source code from current folder
12
+ sd project.servers pr_id - servers list for project pr_id
13
+ sd project.launch_server pr_id - launch new server in project pr_id
14
+ sd project.databases pr_id - list of databases in project pr_id
15
+ sd project.load_balancer pr_id - load balancer in project pr_id
16
+ sd project.deploy_folder pr_id - deploy current folder content in all servers of project pr_id
17
+ sd project.deploy pr_id - deploy latest code to all servers of project pr_id
18
+
19
+ sd server server_id - server status of server_id server
20
+ sd server.reboot server_id - reboot server server_id
21
+ sd server.terminate server_id - terminate server server_id
22
+ EOF
23
+ # help.each_line{|l| p l}
24
+ print help
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,14 @@
1
+ module SimpleDeployer::Command
2
+
3
+ class Info < CommandsBase
4
+
5
+ def main
6
+ puts "Account info"
7
+ p "Access_key " + @service.config.access_key
8
+ p "Secret_key " + @service.config.secret_key
9
+ p "Aws_access_key " + @service.config.aws_access_key
10
+ p "Aws_secret_key " + @service.config.aws_secret_key
11
+ p "Current project id " + (@service.config.project_id || "Undefined")
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,84 @@
1
+ module SimpleDeployer::Command
2
+
3
+ class Project < CommandsBase
4
+
5
+ def main
6
+ get_project
7
+ project = @service.project_info(@pr_id)
8
+ p "Project info"
9
+ project.each_pair do |k, v|
10
+ p "#{k}:#{v}"
11
+ end
12
+ end
13
+
14
+
15
+ def create
16
+ puts "Packaging local folder"
17
+ file = package(Dir.getwd)
18
+ p "Packing done"
19
+ p "Uploading"
20
+ upload(file)
21
+ p "creating project"
22
+ pr_id = @service.create_project(File.basename(file, '.*') + "_project", File.basename(file), @service.config.aws_access_key, @service.config.aws_secret_key)
23
+ @service.config.project_id = pr_id
24
+ @service.config.save_config
25
+ p "Project created, project id saved as default"
26
+ # p "launching server " + pr_id
27
+ # @service.launch_server(pr_id)
28
+ # p "server launched"
29
+ end
30
+
31
+
32
+ def servers
33
+ get_project
34
+ servers = @service.servers_list(@pr_id)
35
+ if servers.size >0
36
+ servers.each do |s|
37
+ p "ID:" + s["id"] + "; status:" + s["status"]
38
+ end
39
+ else
40
+ p "No active servers"
41
+
42
+ end
43
+ end
44
+
45
+
46
+ def launch_server
47
+ get_project
48
+ @service.launch_server(@pr_id)
49
+ end
50
+
51
+
52
+ def databases
53
+ get_project
54
+ databases = @service.databases_list(@pr_id)
55
+ p databases.size >0 ? databases : "No active databases"
56
+
57
+ end
58
+
59
+
60
+ def load_balancer
61
+ get_project
62
+ lb = @service.load_balancer(@pr_id)
63
+ p lb ? lb : "No load balancer"
64
+ end
65
+
66
+
67
+ def deploy_folder
68
+ get_project
69
+ file = package(Dir.getwd)
70
+ upload(file)
71
+ @service.deploy_code(pr_id, "scm_url"=> File.basename(file), "scm_type"=>"s3")
72
+ p "Code deployed"
73
+ end
74
+
75
+
76
+ def deploy
77
+ get_project
78
+ @service.deploy_code(@pr_id)
79
+ end
80
+
81
+
82
+ end
83
+ end
84
+
@@ -0,0 +1,13 @@
1
+ module SimpleDeployer::Command
2
+
3
+ class Projects < CommandsBase
4
+
5
+ def main
6
+ projects = @service.projects_list()
7
+ projects.each do |pr|
8
+ p "Name:" + pr["name"] + "; id:" + pr["id"] + "; active servers:"+pr["num_servers"].to_s
9
+ end
10
+ end
11
+ end
12
+ end
13
+
@@ -0,0 +1,22 @@
1
+ module SimpleDeployer::Command
2
+
3
+ class Server < CommandsBase
4
+ def main
5
+ get_server
6
+ p @service.server_status(@server_id)
7
+ end
8
+
9
+
10
+ def reboot
11
+ get_server
12
+ p @service.reboot_server(@server_id)
13
+ end
14
+
15
+
16
+ def terminate
17
+ get_server
18
+ p @service.terminate_server(@server_id)
19
+ end
20
+
21
+ end
22
+ end
@@ -0,0 +1,82 @@
1
+ module SimpleDeployer
2
+ class Config
3
+ attr_accessor :access_key,
4
+ :secret_key,
5
+ :aws_access_key,
6
+ :aws_secret_key,
7
+ :project_id,
8
+ :host
9
+
10
+
11
+ def read
12
+ credentials = read_from_file
13
+ if credentials
14
+ parse(credentials)
15
+ else
16
+ credentials = read_from_cli
17
+ write_to_file(credentials)
18
+ parse(credentials)
19
+ end
20
+ end
21
+
22
+
23
+ def s3_bucket
24
+ return s3.bucket(s3_bucket_name, true)
25
+ end
26
+
27
+
28
+ def s3
29
+ Aws::S3.new(aws_access_key, aws_secret_key, {:connection_mode => :per_request})
30
+ end
31
+
32
+
33
+ def s3_bucket_name
34
+ 'sd_store'
35
+ end
36
+
37
+
38
+ def config_file
39
+ Dir.pwd + "/.sd/config.yaml"
40
+ end
41
+
42
+
43
+ def save_config
44
+ write_to_file({"access_key"=>self.access_key, "secret_key"=>self.secret_key, "aws_access_key"=>self.aws_access_key, "aws_secret_key"=>self.aws_secret_key, "project_id"=>self.project_id})
45
+ end
46
+
47
+
48
+ private
49
+ def write_to_file(credentials)
50
+ FileUtils.makedirs(File.dirname(config_file))
51
+ File.open(config_file, 'w', 0755) {|f| f.write(credentials.to_yaml) }
52
+ end
53
+
54
+
55
+ def read_from_file
56
+ File.exists?(config_file) and YAML.load_file(config_file)
57
+ end
58
+
59
+
60
+ def read_from_cli
61
+ puts "Enter your SD credentials."
62
+ print "Access Key: "
63
+ access_key = gets.strip
64
+ print "Secret Key: "
65
+ secret_key = gets.strip
66
+ print "AWS Access Key: "
67
+ aws_access_key = gets.strip
68
+ print "AWS Secret Key: "
69
+ aws_secret_key = gets.strip
70
+ return {"access_key"=>access_key, "secret_key"=>secret_key, "aws_access_key"=>aws_access_key, "aws_secret_key"=>aws_secret_key}
71
+ end
72
+
73
+
74
+ def parse(params={})
75
+ self.access_key = params["access_key"]
76
+ self.secret_key=params["secret_key"]
77
+ self.aws_access_key=params["aws_access_key"]
78
+ self.aws_secret_key=params["aws_secret_key"]
79
+ self.project_id=params["project_id"] if params["project_id"]
80
+ end
81
+ end
82
+ end
@@ -0,0 +1,16 @@
1
+ require 'simple_deployer/client'
2
+ require 'simple_deployer/config'
3
+ require 'appoxy_rails'
4
+ module SimpleDeployer
5
+
6
+ class << self
7
+ attr_accessor :config,
8
+ :service
9
+
10
+ def configure()
11
+ SimpleDeployer.config ||= Config.new
12
+ yield(config)
13
+ SimpleDeployer.service = Service.new(config.access_key, config.secret_key, :config=>config)
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,64 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE DIRECTLY
3
+ # Instead, edit Jeweler::Tasks in rakefile, and run 'rake gemspec'
4
+ # -*- encoding: utf-8 -*-
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = %q{simple_deployer}
8
+ s.version = "0.1.1"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
+ s.authors = ["Roman Kononov"]
12
+ s.date = %q{2011-01-06}
13
+ s.default_executable = %q{sd}
14
+ s.description = %q{Appoxy simple_deployer Gem}
15
+ s.email = %q{roman@appoxy.com}
16
+ s.executables = ["sd"]
17
+ s.extra_rdoc_files = [
18
+ "README.markdown"
19
+ ]
20
+ s.files = [
21
+ "README.markdown",
22
+ "Rakefile",
23
+ "VERSION.yml",
24
+ "bin/sd",
25
+ "lib/simple_deployr.rb",
26
+ "lib/simple_deployr/client.rb",
27
+ "lib/simple_deployr/command.rb",
28
+ "lib/simple_deployr/commands/base.rb",
29
+ "lib/simple_deployr/commands/help.rb",
30
+ "lib/simple_deployr/commands/info.rb",
31
+ "lib/simple_deployr/commands/project.rb",
32
+ "lib/simple_deployr/commands/projects.rb",
33
+ "lib/simple_deployr/commands/server.rb",
34
+ "lib/simple_deployr/config.rb",
35
+ "simple_deployer.gemspec"
36
+ ]
37
+ s.homepage = %q{http://www.simpledeployer.com}
38
+ s.require_paths = ["lib"]
39
+ s.rubygems_version = %q{1.3.7}
40
+ s.summary = %q{Appoxy simple_deployer Gem}
41
+
42
+ if s.respond_to? :specification_version then
43
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
44
+ s.specification_version = 3
45
+
46
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
47
+ s.add_runtime_dependency(%q<aws>, [">= 0"])
48
+ s.add_runtime_dependency(%q<zip>, [">= 0"])
49
+ s.add_runtime_dependency(%q<appoxy_rails>, [">= 0"])
50
+ s.add_development_dependency(%q<rake>, [">= 0"])
51
+ else
52
+ s.add_dependency(%q<aws>, [">= 0"])
53
+ s.add_dependency(%q<zip>, [">= 0"])
54
+ s.add_dependency(%q<appoxy_rails>, [">= 0"])
55
+ s.add_dependency(%q<rake>, [">= 0"])
56
+ end
57
+ else
58
+ s.add_dependency(%q<aws>, [">= 0"])
59
+ s.add_dependency(%q<zip>, [">= 0"])
60
+ s.add_dependency(%q<appoxy_rails>, [">= 0"])
61
+ s.add_dependency(%q<rake>, [">= 0"])
62
+ end
63
+ end
64
+
metadata ADDED
@@ -0,0 +1,129 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: simple_deployer
3
+ version: !ruby/object:Gem::Version
4
+ prerelease: false
5
+ segments:
6
+ - 0
7
+ - 1
8
+ - 1
9
+ version: 0.1.1
10
+ platform: ruby
11
+ authors:
12
+ - Roman Kononov
13
+ autorequire:
14
+ bindir: bin
15
+ cert_chain: []
16
+
17
+ date: 2011-01-06 00:00:00 -08:00
18
+ default_executable: sd
19
+ dependencies:
20
+ - !ruby/object:Gem::Dependency
21
+ name: aws
22
+ prerelease: false
23
+ requirement: &id001 !ruby/object:Gem::Requirement
24
+ none: false
25
+ requirements:
26
+ - - ">="
27
+ - !ruby/object:Gem::Version
28
+ segments:
29
+ - 0
30
+ version: "0"
31
+ type: :runtime
32
+ version_requirements: *id001
33
+ - !ruby/object:Gem::Dependency
34
+ name: zip
35
+ prerelease: false
36
+ requirement: &id002 !ruby/object:Gem::Requirement
37
+ none: false
38
+ requirements:
39
+ - - ">="
40
+ - !ruby/object:Gem::Version
41
+ segments:
42
+ - 0
43
+ version: "0"
44
+ type: :runtime
45
+ version_requirements: *id002
46
+ - !ruby/object:Gem::Dependency
47
+ name: appoxy_rails
48
+ prerelease: false
49
+ requirement: &id003 !ruby/object:Gem::Requirement
50
+ none: false
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ segments:
55
+ - 0
56
+ version: "0"
57
+ type: :runtime
58
+ version_requirements: *id003
59
+ - !ruby/object:Gem::Dependency
60
+ name: rake
61
+ prerelease: false
62
+ requirement: &id004 !ruby/object:Gem::Requirement
63
+ none: false
64
+ requirements:
65
+ - - ">="
66
+ - !ruby/object:Gem::Version
67
+ segments:
68
+ - 0
69
+ version: "0"
70
+ type: :development
71
+ version_requirements: *id004
72
+ description: Appoxy simple_deployer Gem
73
+ email: roman@appoxy.com
74
+ executables:
75
+ - sd
76
+ extensions: []
77
+
78
+ extra_rdoc_files:
79
+ - README.markdown
80
+ files:
81
+ - README.markdown
82
+ - Rakefile
83
+ - VERSION.yml
84
+ - bin/sd
85
+ - lib/simple_deployr.rb
86
+ - lib/simple_deployr/client.rb
87
+ - lib/simple_deployr/command.rb
88
+ - lib/simple_deployr/commands/base.rb
89
+ - lib/simple_deployr/commands/help.rb
90
+ - lib/simple_deployr/commands/info.rb
91
+ - lib/simple_deployr/commands/project.rb
92
+ - lib/simple_deployr/commands/projects.rb
93
+ - lib/simple_deployr/commands/server.rb
94
+ - lib/simple_deployr/config.rb
95
+ - simple_deployer.gemspec
96
+ has_rdoc: true
97
+ homepage: http://www.simpledeployer.com
98
+ licenses: []
99
+
100
+ post_install_message:
101
+ rdoc_options: []
102
+
103
+ require_paths:
104
+ - lib
105
+ required_ruby_version: !ruby/object:Gem::Requirement
106
+ none: false
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ segments:
111
+ - 0
112
+ version: "0"
113
+ required_rubygems_version: !ruby/object:Gem::Requirement
114
+ none: false
115
+ requirements:
116
+ - - ">="
117
+ - !ruby/object:Gem::Version
118
+ segments:
119
+ - 0
120
+ version: "0"
121
+ requirements: []
122
+
123
+ rubyforge_project:
124
+ rubygems_version: 1.3.7
125
+ signing_key:
126
+ specification_version: 3
127
+ summary: Appoxy simple_deployer Gem
128
+ test_files: []
129
+