gploy 0.1.7 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/.deploys ADDED
@@ -0,0 +1,3 @@
1
+ 1
2
+ 201305051135290300
3
+ 201305051158010300
data/.gitignore ADDED
@@ -0,0 +1,7 @@
1
+ minhagem.gemspec
2
+ pkg
3
+ coverage/*.*
4
+ *.swp
5
+
6
+ .DS_Store
7
+ lib/.DS_Store
data/Gemfile ADDED
@@ -0,0 +1,12 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in gploy.gemspec
4
+ gemspec
5
+
6
+ group :development do
7
+ gem 'guard-rspec'
8
+ end
9
+
10
+ gem "net-ssh", "~> 2.6.7"
11
+ gem "net-sftp", "~> 2.1.1"
12
+ gem "fakefs", :require => "fakefs/safe"
data/Gemfile.lock ADDED
@@ -0,0 +1,54 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ gploy (0.2.0)
5
+
6
+ GEM
7
+ remote: https://rubygems.org/
8
+ specs:
9
+ coderay (1.0.9)
10
+ diff-lcs (1.2.3)
11
+ fakefs (0.4.2)
12
+ formatador (0.2.4)
13
+ guard (1.7.0)
14
+ formatador (>= 0.2.4)
15
+ listen (>= 0.6.0)
16
+ lumberjack (>= 1.0.2)
17
+ pry (>= 0.9.10)
18
+ thor (>= 0.14.6)
19
+ guard-rspec (2.5.2)
20
+ guard (>= 1.1)
21
+ rspec (~> 2.11)
22
+ listen (0.7.3)
23
+ lumberjack (1.0.3)
24
+ method_source (0.8.1)
25
+ net-sftp (2.1.1)
26
+ net-ssh (>= 2.6.5)
27
+ net-ssh (2.6.7)
28
+ pry (0.9.12)
29
+ coderay (~> 1.0.5)
30
+ method_source (~> 0.8)
31
+ slop (~> 3.4)
32
+ rake (0.9.2.2)
33
+ rspec (2.13.0)
34
+ rspec-core (~> 2.13.0)
35
+ rspec-expectations (~> 2.13.0)
36
+ rspec-mocks (~> 2.13.0)
37
+ rspec-core (2.13.1)
38
+ rspec-expectations (2.13.0)
39
+ diff-lcs (>= 1.1.3, < 2.0)
40
+ rspec-mocks (2.13.1)
41
+ slop (3.4.4)
42
+ thor (0.18.1)
43
+
44
+ PLATFORMS
45
+ ruby
46
+
47
+ DEPENDENCIES
48
+ bundler (~> 1.3)
49
+ fakefs
50
+ gploy!
51
+ guard-rspec
52
+ net-sftp (~> 2.1.1)
53
+ net-ssh (~> 2.6.7)
54
+ rake
data/Guardfile ADDED
@@ -0,0 +1,8 @@
1
+ # A sample Guardfile
2
+ # More info at https://github.com/guard/guard#readme
3
+
4
+ guard 'rspec' do
5
+ watch(%r{^spec/.+_spec\.rb$})
6
+ watch(%r{^lib/(.+)\.rb$}) { |m| "spec/lib/#{m[1]}_spec.rb" }
7
+ watch('spec/spec_helper.rb') { "spec" }
8
+ end
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 Edipo L Federle
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,54 @@
1
+ # Gploy
2
+
3
+ This RubyGem can be used to deploy Ruby on Rails application.
4
+ **NOTE** under development, and incomplete yet
5
+
6
+ ## Installation
7
+
8
+ Add this line to your application's Gemfile:
9
+
10
+ gem 'gploy'
11
+
12
+ And then execute:
13
+
14
+ $ bundle
15
+
16
+ Or install it yourself as:
17
+
18
+ $ gem install gploy
19
+
20
+ ## Usage
21
+
22
+ First, you need your project under git and available in some repository, like github.
23
+ Is not necessary to use within your project. If you have a directory with following structure:
24
+
25
+ >some_folder
26
+ -> config/gploy.yml
27
+
28
+ With this, is now possible deploy your app. The gploy.yml file should be as:
29
+
30
+ ruby_env:
31
+ rake: /user/.rbenv/versions/1.9.3-p194/bin/rake
32
+
33
+ deploy:
34
+ url: localhost
35
+ user: root
36
+ password: secret
37
+ app_name: my_app
38
+ repo: https://github.com/edipofederle/blog.git
39
+ path: /var/www/apps
40
+ number_releases: 3
41
+
42
+ tasks:
43
+ dbmigrate: RAILS_ENV=production rake db:migrate
44
+
45
+
46
+ The *number_releases* is the number of version of deployments you want keep into server.
47
+
48
+ ## Contributing
49
+
50
+ 1. Fork it
51
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
52
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
53
+ 4. Push to the branch (`git push origin my-new-feature`)
54
+ 5. Create new Pull Request
data/Rakefile CHANGED
@@ -1,12 +1,2 @@
1
- require 'rubygems'
2
- require 'rake'
3
- require 'echoe'
4
-
5
- Echoe.new('gploy', '0.1.7') do |p|
6
- p.description = "Gploy Description Here"
7
- p.url = "http://github.com/edipofederle/gploy"
8
- p.author = "Edipo L Federle"
9
- p.email = "edipofederle at gmail dot com"
10
- p.ignore_pattern = ["tmp/*", "script/*"]
11
- p.development_dependencies = []
12
- end
1
+ require "bundler/gem_tasks"
2
+ require 'rake/testtask'
data/bin/gploy CHANGED
@@ -1,56 +1,42 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
- $:.unshift File.join(File.dirname(__FILE__), *%w[.. lib])
3
+ lib = File.expand_path(File.dirname(__FILE__) + '/../lib')
4
+ $LOAD_PATH.unshift(lib) if File.directory?(lib) && !$LOAD_PATH.include?(lib)
4
5
 
5
- help = <<HELP
6
+ require 'gploy'
6
7
 
7
- To learn about gploy visit github page at http://github.com/edipofederle/gploy or type rake -T to see all functions.
8
+ COMANDS = %w[-version help deploy:setup deploy:tasks]
8
9
 
9
- HELP
10
+ gploy = Gploy::Configure.new
10
11
 
11
- require 'optparse'
12
- require "gploy"
13
- require "logger"
14
-
15
- exec = {}
16
- options = {}
17
- opts = OptionParser.new do |opts|
18
- opts.banner = help
19
- opts.on("--version", "Display current version") do
20
- puts "Gploy " + Gploy::VERSION
21
- exit 0
22
- end
23
-
24
- opts.on("--pr", "Create post-receive file") do
25
- c = Gploy::Configure.new
26
- c.configure_hook
27
- end
28
-
29
- opts.on("--setup", "Configure Project") do
30
- c = Gploy::Configure.new
31
- c.setup
32
- end
33
-
34
- opts.on("--update-hook", "Update Hook File") do
35
- c = Gploy::Configure.new
36
- c.upload_hook
37
- end
38
-
39
- opts.on("--deploy", "New Deploy") do
40
- c = Gploy::Configure.new
41
- c.new_deploy
42
- end
12
+ def validate_command(command)
43
13
 
44
- opts.on("--configure", "Initial configuration") do
45
- c = Gploy::Configure.new
46
- c.configure_server
14
+ unless COMANDS.include?(command)
15
+ puts "invalid command. Valid commands are #{commands}."
16
+ exit
47
17
  end
48
-
49
18
  end
50
19
 
51
- opts.parse!
52
- case ARGV.size
53
- when 0
54
- puts "Invalid options. Run `gploy --help` for assistance."
55
- exit(1)
20
+ puts "------ GPLOY ------"
21
+
22
+ args = ARGV.dup
23
+ ARGV.clear
24
+ if args.empty?
25
+ puts "invalid command. Valid commands are #{COMANDS}."
26
+ exit
27
+ end
28
+
29
+ command = args.shift.strip
30
+
31
+ validate_command(command)
32
+
33
+ if command == "-version"
34
+ puts Gploy::VERSION
35
+ exit
36
+ elsif command == "help"
37
+ puts "see: https://github.com/edipofederle/gploy"
38
+ exit
39
+ else
40
+ gploy.run(command)
56
41
  end
42
+
data/config/gploy.yml ADDED
@@ -0,0 +1,14 @@
1
+ ruby_env:
2
+ rake: /root/.rbenv/versions/1.9.3-p194/bin/rake
3
+
4
+ deploy:
5
+ url: localhost
6
+ user: root
7
+ password: secret
8
+ app_name: my_app
9
+ repo: https://github.com/edipofederle/blog.git
10
+ path: /var/www/apps
11
+ number_releases: 3
12
+
13
+ tasks:
14
+ dbmigrate: RAILS_ENV=production rake db:migrate
data/gploy.gemspec CHANGED
@@ -1,31 +1,25 @@
1
- # -*- encoding: utf-8 -*-
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'gploy/version'
2
5
 
3
- Gem::Specification.new do |s|
4
- s.name = %q{gploy}
5
- s.version = "0.1.7"
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "gploy"
8
+ spec.version = Gploy::VERSION
9
+ spec.authors = ["Edipo L Federle"]
10
+ spec.email = ["edipofederle@gmail.com"]
11
+ spec.description = %q{Deployment}
12
+ spec.summary = %q{Deployment with git}
13
+ spec.homepage = "http://github.com/edipofederle/gploy"
14
+ spec.license = "MIT"
6
15
 
7
- s.required_rubygems_version = Gem::Requirement.new(">= 1.2") if s.respond_to? :required_rubygems_version=
8
- s.authors = [%q{Edipo L Federle}]
9
- s.date = %q{2011-07-15}
10
- s.description = %q{Gploy Description Here}
11
- s.email = %q{edipofederle at gmail dot com}
12
- s.executables = [%q{gploy}]
13
- s.extra_rdoc_files = [%q{README.markdown}, %q{bin/gploy}, %q{lib/TODO.txt}, %q{lib/gploy.rb}, %q{lib/gploy/configure.rb}, %q{lib/gploy/helpers.rb}, %q{lib/gploy/logger.rb}, %q{lib/gploy/teste.rb}]
14
- s.files = [%q{Manifest}, %q{README.markdown}, %q{Rakefile}, %q{bin/gploy}, %q{config/config.yaml}, %q{config/post-receive}, %q{install.rb}, %q{lib/TODO.txt}, %q{lib/gploy.rb}, %q{lib/gploy/configure.rb}, %q{lib/gploy/helpers.rb}, %q{lib/gploy/logger.rb}, %q{lib/gploy/teste.rb}, %q{test/TimeChange.rb}, %q{test/config/config.yaml}, %q{test/config/post-receive}, %q{test/db/schema.rb}, %q{test/helper.rb}, %q{test/suite.rb}, %q{test/test_configuration.rb}, %q{test/test_configure.rb}, %q{test/test_logger.rb}, %q{test/unMocker.rb}, %q{gploy.gemspec}]
15
- s.homepage = %q{http://github.com/edipofederle/gploy}
16
- s.rdoc_options = [%q{--line-numbers}, %q{--inline-source}, %q{--title}, %q{Gploy}, %q{--main}, %q{README.markdown}]
17
- s.require_paths = [%q{lib}]
18
- s.rubyforge_project = %q{gploy}
19
- s.rubygems_version = %q{1.8.5}
20
- s.summary = %q{Gploy Description Here}
21
- s.test_files = [%q{test/test_configuration.rb}, %q{test/test_configure.rb}, %q{test/test_logger.rb}]
16
+ spec.files = `git ls-files`.split($/)
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
22
20
 
23
- if s.respond_to? :specification_version then
24
- s.specification_version = 3
25
-
26
- if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
27
- else
28
- end
29
- else
30
- end
31
- end
21
+ spec.add_development_dependency "bundler", "~> 1.3"
22
+ spec.add_development_dependency "rake"
23
+ spec.add_development_dependency "net-ssh", "~> 2.6.7"
24
+ spec.add_development_dependency "net-sftp", "~> 2.1.1"
25
+ end
data/lib/gploy.rb CHANGED
@@ -1,6 +1,5 @@
1
1
  $:.unshift File.dirname(__FILE__) # For use/testing when no gem is installedr"
2
2
 
3
-
4
3
  def require_all(path)
5
4
  glob = File.join(File.dirname(__FILE__), path, '*.rb')
6
5
  Dir[glob].each do |f|
@@ -8,7 +7,6 @@ def require_all(path)
8
7
  end
9
8
  end
10
9
 
11
- require 'rubygems'
12
10
 
13
11
  require "rubygems"
14
12
  require 'net/ssh'
@@ -16,10 +14,9 @@ require 'fileutils'
16
14
  require 'yaml'
17
15
  require 'net/sftp'
18
16
 
19
- require 'gploy/logger'
20
17
  require 'gploy/helpers'
21
18
  require 'gploy/configure'
19
+ require 'gploy/Settings'
20
+ require 'gploy/deep_symbolize'
22
21
 
23
- module Gploy
24
- VERSION = '0.1.7'
25
- end
22
+ require 'gploy/version'
@@ -1,165 +1,82 @@
1
1
  module Gploy
2
-
2
+
3
3
  class Configure
4
+
4
5
  include Helpers
5
-
6
- VERSION = '0.1.7'
6
+
7
7
  def initialize
8
- @path = "config/config.yaml"
9
- end
10
-
11
-
12
- def configure_server
13
- log("Starting gploy configuration...create config.yaml")
14
- create_file_and_direcotry_unless_exists("config", "config.yaml")
15
- puts "Files created into the config directory. Now need edit config.yaml"
16
- puts ""
17
- puts "---------------------------------------------------------"
18
- puts "You can put this content into your config.yaml file and edit it"
19
- post_commands_server
20
- end
21
-
22
- def configure_hook
23
- config = read_config_file(@path)
24
- @url = config["config"]["url"]
25
- @app_name = config["config"]["app_name"]
26
- @user = config["config"]["user"]
27
- @password = config["config"]["password"]
28
- @origin = config["config"]["origin"]
29
- log("Configure Hook")
30
- create_file_and_direcotry_unless_exists("config", "post-receive")
31
- puts "Now you should edit config/post-receive file, like this:"
32
- puts ""
33
- post_commands(config)
34
- end
35
-
36
- def setup
37
- log("Starting gploy setup...")
38
- config = read_config_file(@path)
39
- @url = config["config"]["url"]
40
- @app_name = config["config"]["app_name"]
41
- @user = config["config"]["user"]
42
- @password = config["config"]["password"]
43
- @origin = config["config"]["origin"]
44
- log("Start Setup...")
45
- check_if_dir_log_exists
46
- remote
47
- initialize_local_repo
48
- create_repo(@app_name)
49
- add_remote(@url, @user, @app_name, @origin)
50
- push_local(@origin)
51
- clone_into_server(@app_name)
52
- add_remote_origin(@url, @user, @app_name, @origin)
53
- sys_link(@app_name)
54
- tmp_create(@app_name)
55
- update_hook_into_server(@user, @url, @app_name)
56
- run_tasks
57
- puts "OK. No error Found. You now can run <git push #{@origin} master> for update your project"
58
- end
59
-
60
- def upload_hook
61
- log("Realoding hook file...")
62
- remote
63
- update_hook(@user, @url, @app_name)
64
- puts "File successfully Updated"
65
- end
66
-
67
- def read_config_file(path)
68
8
  begin
69
- config = YAML.load_file(path)
70
- raise "Invalid configuration - #{path}" if !config.is_a?(Hash)
71
- $stderr.puts "Configuration ok from #{path}"
72
- rescue => e
73
- $stderr.puts "WARNING: I Could not read configuration file."
74
- $stderr.puts "\t" + e.to_s
75
- config = {}
9
+ unless File.exists?("config/gploy.yml")
10
+ post_commands_server
11
+ $stdout.puts "Add this to your gploy.conf file\nExting..."
12
+ end
76
13
  end
77
- config
78
- end
79
-
80
- def remote
81
- @shell = start(@url, @user, @password)
82
- end
83
-
84
- def path
85
- "config/post-receive"
86
- end
87
-
88
- def run_tasks
89
- migrate(@app_name)
90
- restart_server(@app_name)
91
14
  end
92
15
 
93
- def start(server, user, pass)
94
- Net::SSH.start(server, user, :password => pass)
95
- end
96
-
97
- def path_hook(name)
98
- "~/repos/#{name}.git/hooks/post-receive"
99
- end
100
-
101
- def create_repo(name)
102
- run_remote "cd repos/ && mkdir #{name}.git && cd #{name}.git && git init --bare"
103
- end
104
-
105
- def create_hook_file
106
- unless dirExists?("config")
107
- Dir.mkdir("config")
16
+ def run(command)
17
+ Settings.load!("config/gploy.yml")
18
+ puts @remote = remote_command(Settings.deploy[:url], Settings.deploy[:user], Settings.deploy[:password])
19
+
20
+ if command == "deploy:setup"
21
+ $stdout.puts "Configuring server..."
22
+ new_release = Time.now.to_s.gsub(/\W/, '')
23
+
24
+ puts @remote.exec!("cd #{Settings.deploy[:path]} && mkdir #{Settings.deploy[:app_name]} && cd #{Settings.deploy[:path]}/#{Settings.deploy[:app_name]} && mkdir #{new_release}")
25
+ puts @remote.exec!("cd #{Settings.deploy[:path]}/#{Settings.deploy[:app_name]} && git clone #{Settings.deploy[:repo]} #{new_release}")
26
+
27
+ update_number_of_deployments(new_release)
28
+ update_syn_link(new_release)
108
29
  end
109
- FileUtils.touch("config/post-receive")
110
- end
111
-
112
- def initialize_local_repo
113
- puts "Starting local git repository"
114
- unless dirExists?(".git/")
115
- run_local("git init && git add . && git commit -m 'Initial Commit' ")
116
- else
117
- puts "Git is already configured in this project"
30
+
31
+ if command == "deploy:tasks"
32
+ Settings.tasks.each do |command|
33
+ puts "executing: #{command} ..."
34
+ unless Settings.ruby_env == nil
35
+ if command[1].include?("rake")
36
+ execute_task(command[1].gsub("rake", Settings.ruby_env[:rake]))
37
+ end
38
+ else
39
+ execute_tas(command[1])
40
+ end
41
+ end
118
42
  end
119
- end
120
-
121
- def create_file_and_direcotry_unless_exists(dir, file)
122
- unless dirExists?("#{dir}")
123
- Dir.mkdir(dir)
124
- end
125
- unless File.exists?("config/#{file}")
126
- FileUtils.touch "#{dir}/#{file}"
127
- end
128
- end
129
-
130
- def add_remote(server, user, name, origin)
131
- run_local("git remote add #{origin} #{user}@#{server}:~/repos/#{name}.git")
43
+
44
+ restart(new_release)
45
+
132
46
  end
133
47
 
134
- def add_remote_origin(server, user, name, origin)
135
- run_remote("cd rails_app/#{name}/ && git remote add #{origin} ~/repos/#{name}.git/")
48
+ def restart(release)
49
+ puts @remote.exec!("cd #{Settings.deploy[:path]}/#{Settings.deploy[:app_name]}/#{release} && mkdir tmp && touch tmp/restart.txt")
136
50
  end
137
51
 
138
- def new_deploy
139
- read_config_file(path)
140
- run_local("git checkout #{@branch} - && git push #{@origin} master")
141
- end
142
-
143
- def clone(name)
144
- @shell.exec!("git clone ~/repos/#{name}.git ~/rails_app/#{name}")
145
- end
146
-
147
- def clone_into_server(name)
148
- run_remote "git clone repos/#{name}.git ~/rails_app/#{name}"
149
- end
150
-
151
- def push_local(origin)
152
- run_local "git checkout master && git push #{origin} master"
52
+ def execute_task(line)
53
+ lines = IO.readlines(".deploys")
54
+ puts "cd #{Settings.deploy[:path]}/#{Settings.deploy[:app_name]}/#{lines.last.tr("\n","")} && #{line}"
55
+ puts @remote.exec!("cd #{Settings.deploy[:path]}/#{Settings.deploy[:app_name]}/#{lines.last.tr("\n","")} && #{line}")
153
56
  end
154
57
 
155
- def tmp_create(name)
156
- run_remote "cd rails_app/#{name}/ && mkdir tmp"
58
+ def update_syn_link(new_release)
59
+ @remote.exec!("cd #{Settings.deploy[:path]}/#{Settings.deploy[:app_name]} && rm current")
60
+ @remote.exec!("cd #{Settings.deploy[:path]}/#{Settings.deploy[:app_name]} && ln -s #{new_release} current")
157
61
  end
158
62
 
159
- def log(msg)
160
- a = Time.now.strftime('%Y-%m-%d %H:%M:%S')
161
- $stderr.puts(a + " " + msg)
63
+ def update_number_of_deployments(new_release)
64
+
65
+ unless File.exist?(".deploys")
66
+ File.write(".deploys", "")
67
+ end
68
+
69
+ count = File.foreach(".deploys").inject(0) {|c, line| c+1}
70
+ puts "Number of releases: #{count}"
71
+
72
+ if count == Settings.deploy[:number_releases]
73
+ puts "Remove all releases...."
74
+ File.open(".deploys", 'w') { |file| file.truncate(0)}
75
+ @remote.exec!("cd #{Settings.deploy[:path]}/#{Settings.deploy[:app_name]} && rm -rf *")
76
+ end
77
+
78
+ File.open(".deploys", 'a') { |file| file.puts(new_release) }
162
79
  end
163
-
80
+
164
81
  end
165
82
  end