nodex 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore ADDED
@@ -0,0 +1,4 @@
1
+ *.gem
2
+ .bundle
3
+ Gemfile.lock
4
+ pkg/*
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "http://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in nodex.gemspec
4
+ gemspec
data/README ADDED
File without changes
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ require 'bundler'
2
+ Bundler::GemHelper.install_tasks
data/bin/nodex.rb ADDED
@@ -0,0 +1,7 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'rubygems'
4
+ require 'nodex'
5
+ require 'nodex/cli'
6
+
7
+ Nodex::CLI.execute ARGV
data/lib/nodex/cli.rb ADDED
@@ -0,0 +1,13 @@
1
+ module Nodex
2
+ class CLI
3
+ def self.execute(params)
4
+ deploy = Deploy.new
5
+ case params.size
6
+ when 0
7
+ deploy.remote_update
8
+ when 1
9
+ deploy.send "remote_#{params.first}"
10
+ end
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,53 @@
1
+ module Nodex
2
+ class Deploy
3
+ include Helper
4
+ include DSL
5
+
6
+ attr_accessor :repository, :user, :application, :host, :path, :branch, :environment, :skip_steps, :cache_dirs, :db_example_name, :skip_steps
7
+
8
+ def initialize
9
+ self.server = :passenger
10
+ configure
11
+ end
12
+
13
+ def server=(server)
14
+ load_module "servers/#{server}"
15
+ end
16
+
17
+ def configure
18
+ configure_from configuration_file if configuration_file
19
+ end
20
+
21
+ def configure_from(file)
22
+ deploy = self
23
+ eval file.read + ';local_variables.each { |variable| deploy.send "#{variable}=", eval(variable.to_s) rescue nil }'
24
+ end
25
+
26
+ def remote_setup
27
+ remote_run "cd #{path} && #{git_clone} && #{app_checkout} && #{copy_example_file} && #{install_bundler} && #{bundle_cmd} && #{rake_db_create}"
28
+ local_setup
29
+ end
30
+
31
+ def local_setup
32
+ after_update_code
33
+ end
34
+
35
+ def remote_update
36
+ local_update
37
+ end
38
+
39
+ def local_update
40
+ update_code
41
+ after_update_code
42
+ end
43
+
44
+ private
45
+
46
+ def after_update_code
47
+ install_gems
48
+ migrate_database
49
+ clear_cache
50
+ restart_server
51
+ end
52
+ end
53
+ end
data/lib/nodex/dsl.rb ADDED
@@ -0,0 +1,61 @@
1
+ module Nodex
2
+ module DSL
3
+ def load_module(filename)
4
+ require "inploy/#{filename}"
5
+ extend eval(filename.split("/").map { |word| camelize(word) }.join("::"))
6
+ end
7
+
8
+ def rake_task(task)
9
+ "rake #{task} RAILS_ENV=#{environment}"
10
+ end
11
+
12
+ def update_code
13
+ remote_run "cd #{application_path} && #{git_pull}"
14
+ end
15
+
16
+ def migrate_database
17
+ remote_run "cd #{application_path} && rake db:migrate RAILS_ENV=#{environment}" unless skip_step?('migrate_database')
18
+ end
19
+
20
+ def log(command)
21
+ puts "Inploy => #{command}"
22
+ end
23
+
24
+ def run(command)
25
+ log command
26
+ Kernel.system "#{command}"
27
+ end
28
+
29
+ def clear_cache
30
+ unless skip_step?('clear_cache')
31
+ cache_dirs.each do |dir|
32
+ run "rm -rf #{dir}"
33
+ end
34
+ end
35
+ end
36
+
37
+ def rake_db_create
38
+ rake_task "db:create"
39
+ end
40
+
41
+ def bundle_install
42
+ remote_run "cd #{application_path} && #{bundle_cmd}" unless skip_step?('bundle_install')
43
+ end
44
+
45
+ def install_gems
46
+ if using_bundler?
47
+ bundle_install
48
+ else
49
+ remote_run "cd #{application_path} && rake gems:install RAILS_ENV=#{environment}" unless skip_step?('install_gems')
50
+ end
51
+ end
52
+
53
+ def remote_run(commands)
54
+ run "ssh #{user}@#{host} #{login_shell_wrap(commands)}"
55
+ end
56
+
57
+ def login_shell_wrap(cmd)
58
+ "'#{cmd}'"
59
+ end
60
+ end
61
+ end
@@ -0,0 +1,55 @@
1
+ module Inploy
2
+ module Helper
3
+ def configuration_file
4
+ File.open("config/nodex.rb") rescue File.open("nodex.rb") rescue nil
5
+ end
6
+
7
+ def skip_step?(step)
8
+ skip_steps and skip_steps.include?(step)
9
+ end
10
+
11
+ def skip_steps_cmd
12
+ " skip_steps=#{skip_steps.join(',')}" unless skip_steps.nil?
13
+ end
14
+
15
+ def camelize(string)
16
+ string.to_s.gsub(/\/(.?)/) { "::" + $1.upcase }.gsub(/(^|_)(.)/) { $2.upcase }
17
+ end
18
+
19
+ def application_path
20
+ "#{path}/#{application}"
21
+ end
22
+
23
+ def copy_example_file
24
+ "cp #{application_path}/config/#{db_example_name} #{application_path}/config/database.yml"
25
+ end
26
+
27
+ def bundle_cmd
28
+ "bundle install --without development test cucumber"
29
+ end
30
+
31
+ def install_bundler
32
+ "gem install bundler"
33
+ end
34
+
35
+ def git_clone
36
+ "git clone #{repository} #{application}"
37
+ end
38
+
39
+ def git_pull
40
+ "git pull origin #{branch}"
41
+ end
42
+
43
+ def app_checkout
44
+ "cd #{application} && #{checkout}"
45
+ end
46
+
47
+ def using_bundler?
48
+ File.exists? "Gemfile"
49
+ end
50
+
51
+ def checkout
52
+ branch.eql?("master") ? "" : "git branch | grep -vq #{branch} && git checkout -f -b #{branch} origin/#{branch}"
53
+ end
54
+ end
55
+ end
@@ -0,0 +1,3 @@
1
+ module Nodex
2
+ VERSION = "0.0.2"
3
+ end
@@ -0,0 +1,9 @@
1
+ module Nodex
2
+ module Servers
3
+ module Mongrel
4
+ def restart_server
5
+ run "mongrel_cluster restart"
6
+ end
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,9 @@
1
+ module Nodex
2
+ module Servers
3
+ module Passenger
4
+ def restart_server
5
+ run "touch tmp/restart.txt"
6
+ end
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,12 @@
1
+ module Nodex
2
+ module Servers
3
+ module Thin
4
+ def restart_server
5
+ run "thin --pid tmp/pids/thin.pid stop"
6
+ run "thin --rackup config.ru --daemonize\
7
+ --log log/thin.log --pid tmp/pids/thin.pid --environment production\
8
+ --port 4500 start"
9
+ end
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,9 @@
1
+ module Nodex
2
+ module Servers
3
+ module Unicorn
4
+ def restart_server
5
+ run "kill -USR2 `cat tmp/pids/unicorn.pid`"
6
+ end
7
+ end
8
+ end
9
+ end
data/nodex.gemspec ADDED
@@ -0,0 +1,21 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require "nodex/version"
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = "nodex"
7
+ s.version = Nodex::VERSION
8
+ s.platform = Gem::Platform::RUBY
9
+ s.authors = ["Bruno S. Barros"]
10
+ s.email = ["bkether@gmail.com"]
11
+ s.homepage = "http://bkether.blogspot.com"
12
+ s.summary = %q{Easy way to deploy}
13
+ s.description = %q{Easy way to deploy a rails app (minimalist version of inploy)}
14
+
15
+ s.rubyforge_project = "nodex"
16
+
17
+ s.files = `git ls-files`.split("\n")
18
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
19
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
20
+ s.require_paths = ["lib"]
21
+ end
metadata ADDED
@@ -0,0 +1,71 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: nodex
3
+ version: !ruby/object:Gem::Version
4
+ prerelease:
5
+ version: 0.0.2
6
+ platform: ruby
7
+ authors:
8
+ - Bruno S. Barros
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+
13
+ date: 2011-03-06 00:00:00 -03:00
14
+ default_executable:
15
+ dependencies: []
16
+
17
+ description: Easy way to deploy a rails app (minimalist version of inploy)
18
+ email:
19
+ - bkether@gmail.com
20
+ executables:
21
+ - nodex.rb
22
+ extensions: []
23
+
24
+ extra_rdoc_files: []
25
+
26
+ files:
27
+ - .gitignore
28
+ - Gemfile
29
+ - README
30
+ - Rakefile
31
+ - bin/nodex.rb
32
+ - lib/nodex/cli.rb
33
+ - lib/nodex/deploy.rb
34
+ - lib/nodex/dsl.rb
35
+ - lib/nodex/helper.rb
36
+ - lib/nodex/version.rb
37
+ - lib/servers/mongrel.rb
38
+ - lib/servers/passenger.rb
39
+ - lib/servers/thin.rb
40
+ - lib/servers/unicorn.rb
41
+ - nodex.gemspec
42
+ has_rdoc: true
43
+ homepage: http://bkether.blogspot.com
44
+ licenses: []
45
+
46
+ post_install_message:
47
+ rdoc_options: []
48
+
49
+ require_paths:
50
+ - lib
51
+ required_ruby_version: !ruby/object:Gem::Requirement
52
+ none: false
53
+ requirements:
54
+ - - ">="
55
+ - !ruby/object:Gem::Version
56
+ version: "0"
57
+ required_rubygems_version: !ruby/object:Gem::Requirement
58
+ none: false
59
+ requirements:
60
+ - - ">="
61
+ - !ruby/object:Gem::Version
62
+ version: "0"
63
+ requirements: []
64
+
65
+ rubyforge_project: nodex
66
+ rubygems_version: 1.5.0
67
+ signing_key:
68
+ specification_version: 3
69
+ summary: Easy way to deploy
70
+ test_files: []
71
+