rsync-deploy 0.0.13 → 0.0.16

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: c0d8bd2f75921bfade8891d99baf5728fea343a4
4
- data.tar.gz: 2756d336765d28db681f0972caa33babc12c1be1
3
+ metadata.gz: 3717284c1b26d927d0e36696e2539e5964165f75
4
+ data.tar.gz: df5757be4cec9ed087d0b3295d187aadb6b9c856
5
5
  SHA512:
6
- metadata.gz: 91236019ec3336df7c25891c4936b89a450b76dc6183d1a75fba8fa15bd6d533334e213143445bb8ef17087646984f8cb8f6a44c5576e5288dc03917ed550c9d
7
- data.tar.gz: 0de91dbc4e02509b4845230e4f54efcd5130d1c5e2c57bfbbe770eea02954cadd58f72363287ba9a26a89ae49592861f500116dee788188635320f02215ae353
6
+ metadata.gz: 9856b050bbfa3c7f53b0203428d77467054f772ee28772ff2be04314c9cf9b3a9456d395c6edc56c51cc6a153b50c659327f291554eb2c1a5bb0adbd700b5a1a
7
+ data.tar.gz: 3159216a6de8b0d6d451080b8f866e318d96a92e0b14d7060f0339fe1780e164ac102ffd9bf28d0a631bfdfe2d044971ce230c561394a636a15b1b3d74363521
data/README.md CHANGED
@@ -58,9 +58,24 @@ Or to multiple servers, like this:
58
58
  deploy dev staging production
59
59
  ```
60
60
 
61
+ #### deploy download [env...]
62
+
63
+ Will download from the environment(s) listed. This works in reverse, so files from `path.remote` will go into `path.local`
64
+
65
+ This command is also aliased as `down` and `d`, so it can be run like:
66
+
67
+ ```
68
+ deploy down staging
69
+ ```
70
+
71
+ #### deploy list
72
+
73
+ Will list all configured environments.
74
+
61
75
  #### deploy config NAME
62
76
 
63
- Will change the name of deployment configuration files. By default they are named `deploy.yml`, but this can be changed to names such as `.deploy` which makes them hidden files. Keep in mind that **this is a global setting and will be applied to all deployments.**
77
+ Will change the name of deployment configuration files. By default they are named `deploy.yml`, but this can be changed to names such as `.deploy` which makes them hidden files. Keep in mind that **this is a global setting** and will be applied to all deployments.
78
+
64
79
 
65
80
  #### deploy help
66
81
 
@@ -126,7 +141,8 @@ The password to login to the server. If SSH keys aren't available, then the `pas
126
141
  - Type: `String`
127
142
  - Default: `none`
128
143
 
129
- The path to an alternative SSH key. This only needs to be set if your key isn't one of the following:
144
+ The path to an alternative SSH key. This only needs to be set if your key **isn't** one of the following:
145
+
130
146
  ```
131
147
  ~/.ssh/id_rsa
132
148
  ~/.ssh/id_dsa
data/bin/deploy CHANGED
@@ -3,39 +3,45 @@
3
3
  require 'deploy'
4
4
  require 'fileutils'
5
5
 
6
- # TODO: Create `-r`, `--rev`, `--reverse`, `rev`, `reverse` command to download
7
- # from the server instead of upload
6
+ # TODO: Allow creation of environments from install command, for example
7
+ # `deploy install live dev` would create a file with live and dev
8
+ # configurations to be filled in
9
+
8
10
  # TODO: Allow pre/post-deploy tasks to be run on a per-environment basis for
9
11
  # both local and remote servers. That could help some people, but not really
10
12
  # needed for a while yet.
11
13
 
12
14
  def help
13
15
  %Q(
14
- Usage: deploy [COMMAND] [ENVIRONMENTS] [OPTIONS]
16
+ Usage: deploy [COMMAND] [OPTIONS] [ENVIRONMENTS]
15
17
 
16
18
  Commands:
17
- install Configure directory for deployment
18
- config NAME Changes the deployment config file name
19
- help Prints this help document
20
- version Prints the siteleaf gem version
19
+
20
+ [env...] Deploys listed environments
21
+ reverse [env...] Downloads listed environments \(aliased as `r` or `rev`\)
22
+ download [env...] Downloads listed environments \(aliased as `d` or `down`\)
23
+
24
+ install Configure directory for deployment
25
+ list Lists all configured environments
26
+ config FILENAME Changes the deployment config file name
27
+ help Prints this help document
28
+ version Prints the siteleaf gem version
21
29
 
22
30
  Environments:
23
- <env> Deploys listed environments
31
+ [env...] Deploys listed environments
24
32
 
25
33
  If no commands, environments, or options are given,
26
34
  the first environment in the config file will be deployed.
27
35
 
28
36
  Options:
29
- -h, --help Prints this help document
30
- -v, --version Prints the deploy gem version
37
+ -h, --help Prints this help document
38
+ -v, --version Prints the deploy gem version
31
39
 
32
40
  See https://github.com/rosszurowski/deploy for additional documentation.
33
41
  )
34
42
  end
35
43
 
36
- # TODO: Allow creation of environments from install command, for example
37
- # `deploy install live dev` would create a file with live and dev
38
- # configurations to be filled in
44
+
39
45
  def install
40
46
 
41
47
  if File.exist?(Deploy::CONFIG_PATH)
@@ -72,37 +78,70 @@ def install
72
78
 
73
79
  end
74
80
 
75
- # See if they're running a command
76
- if ARGV.size > 0
77
- case ARGV[0]
78
- when '-v', '--version', 'version'
79
- puts "Deploy v" + Deploy::VERSION
80
- exit
81
- when '-h', '--help', 'help'
82
- puts help
83
- exit
84
- when 'install', 'setup'
85
- install
86
- exit
87
- when 'config'
88
- unless ARGV[1].empty?
89
- File.open(Deploy::GEM_SETTINGS_PATH, 'w+') do |file|
90
- # Remove illegal characters and add to file
91
- file.puts 'config_path: ' + ARGV[1].gsub(/[^\w\.]/, '_')
92
- end
93
- puts "Configuration file renamed to `#{ARGV[1].gsub(/[^\w\.]/, '_')}`"
94
- else
95
- puts "Please provide a name for configuration files. See `deploy help` for more details."
81
+ def set_config(new_path)
82
+ unless ARGV[1].empty?
83
+ File.open(Deploy::GEM_SETTINGS_PATH, 'w+') do |file|
84
+ # Remove illegal characters and add to file
85
+ file.puts 'config_path: ' + new_path
86
+ end
87
+ puts "Configuration file renamed to `#{new_path}`"
88
+ else
89
+ puts "Please provide a name for configuration files. See `deploy help` for more details."
90
+ end
91
+ end
92
+
93
+ def list
94
+ if File.exist?(Deploy::CONFIG_PATH)
95
+ deploy = Deploy::Deployment.new
96
+
97
+ # List out environments
98
+ longest_env = (deploy.environments.sort { |a, b| a.name.length <=> b.name.length }).last
99
+ deploy.environments.each.with_index(1) do |env, i|
100
+ printf "* \e[91m%-#{longest_env.name.length + 3}s\e[0m %s\n", "#{env.name}", "(#{env.config[:user]}@#{env.config[:host]})"
96
101
  end
102
+
103
+ else
104
+ puts "No config file found, run `deploy install` to create one"
97
105
  exit
98
106
  end
99
107
  end
100
108
 
109
+ def go(rev=false)
110
+ if File.exist?(Deploy::CONFIG_PATH)
111
+ deploy = Deploy::Deployment.new
112
+ deploy.reverse = rev
113
+ # Pass the arguments to the deploy, but remove the reverse command
114
+ deploy.go ARGV.reject { |cmd| cmd =~ /\b((?:r)|(?:rev)|(?:reverse)|(?:d)|(?:down)|(?:download))\b/i }
115
+ else
116
+ puts "No config file found, run `deploy install` to create one"
117
+ exit
118
+ end
119
+ end
101
120
 
102
- if File.exist?(Deploy::CONFIG_PATH)
103
- deploy = Deploy::Deployment.new
104
- deploy.go ARGV
105
- else
106
- puts "No config file found, run `deploy install` to create one"
121
+ # See if they're running a command
122
+ case ARGV[0]
123
+ when '-v', '--version', 'version'
124
+ puts "Deploy v" + Deploy::VERSION
125
+ exit
126
+ when '-h', '--help', 'help'
127
+ puts help
128
+ exit
129
+ when 'install', 'setup'
130
+ install
131
+ exit
132
+ when 'r', 'rev', 'reverse',
133
+ 'd', 'down', 'download'
134
+ # Run the deploy in reverse
135
+ go(true)
136
+ exit
137
+ when 'list'
138
+ list
107
139
  exit
108
- end
140
+ when 'config'
141
+ set_config ARGV[1].gsub(/[^\w\.]/, '_')
142
+ exit
143
+ end
144
+
145
+
146
+ # Run the deploy straight if nothing else triggered
147
+ go(false)
@@ -34,9 +34,9 @@ module Deploy
34
34
 
35
35
  @config[:excludes] = hash['exclude'] || Array.new
36
36
 
37
-
38
- @options[:verbose] = hash['verbose'] unless hash['verbose'].nil?
39
- @options[:sync] = hash['sync'] unless hash['sync'].nil?
37
+ @options[:reverse] = false
38
+ @options[:verbose] = hash['verbose'].to_s.empty? ? false : hash['verbose']
39
+ @options[:sync] = hash['sync'].to_s.empty? ? true : hash['sync']
40
40
 
41
41
  validate
42
42
 
@@ -60,50 +60,58 @@ module Deploy
60
60
  tmp_exclude.puts Deploy::CONFIG_PATH
61
61
  tmp_exclude.close
62
62
  end
63
-
63
+
64
64
  unless @config[:pass].empty?
65
65
  tmp_pass = Tempfile.new(['pass','.txt'])
66
66
  tmp_pass.puts @config[:pass]
67
67
  tmp_pass.close
68
68
  end
69
69
 
70
- rsync_cmd = 'rsync -a' # Always keep permissions
71
- rsync_cmd += 'v' if @options[:verbose] # Verbose if requested
72
- rsync_cmd += 'z' # Always zip files
70
+ rsync_cmd = 'rsync -a' # Always keep permissions
71
+ rsync_cmd += 'v' if @options[:verbose] # Verbose if requested
72
+ rsync_cmd += 'z' # Always zip files
73
73
 
74
- rsync_cmd += ' --progress' # Always show progress
75
- rsync_cmd += ' --force --delete' unless @options[:sync] == false # Sync unless explicitly requested
76
- rsync_cmd += " --exclude-from=#{tmp_exclude.path}" unless @config[:excludes].empty? # Include exclude file if it exists
77
- rsync_cmd += " --password-file=#{tmp_pass.path}" unless @config[:pass].empty? # Include password file if it exists
74
+ rsync_cmd += ' --progress' # Always show progress
75
+
76
+ if (@options[:sync] && !@options[:reverse])
77
+ rsync_cmd += ' --force --delete --delete-excluded' # Sync unless explicitly requested or downloading
78
+ end
79
+ rsync_cmd += " --exclude-from=#{tmp_exclude.path}" unless @config[:excludes].empty? # Include exclude file if it exists
80
+ rsync_cmd += " --password-file=#{tmp_pass.path}" unless @config[:pass].empty? # Include password file if it exists
78
81
  rsync_cmd += " -e \"ssh "
79
82
 
80
83
  if(@config[:pass].empty? and @config[:private_key].empty?)
81
- rsync_cmd += " -i #{@config[:private_key]} " # Include a custom private key if requested
84
+ rsync_cmd += " -i #{@config[:private_key]} " # Include a custom private key if requested
82
85
  end
83
-
84
- rsync_cmd += "-p#{@config[:port]}\"" # Choose port if specified
85
86
 
86
- rsync_cmd += " " + `pwd`.gsub(/\s+/, "") + "#{@config[:local]}" # The local path from the current directory
87
-
88
- rsync_cmd += " " # Adding a space here means we don't need an if/else statement
89
- rsync_cmd += "#{@config[:user]}@" unless @config[:user].empty? # Only add user if not empty
90
- rsync_cmd += "#{@config[:host]}:" # Add host
91
- rsync_cmd += "~#{@config[:remote]}" # Add remote (relative to remote user home)
87
+ rsync_cmd += "-p#{@config[:port]}\" " # Choose port if specified
88
+
89
+ unless @options[:reverse]
90
+ rsync_cmd += `pwd`.gsub(/\s+/, "") + "#{@config[:local]} " # The local path from the current directory
91
+ end
92
92
 
93
+ rsync_cmd += "#{@config[:user]}@" unless @config[:user].empty? # Only add user if not empty
94
+ rsync_cmd += "#{@config[:host]}:" # Add host
95
+ rsync_cmd += "~#{@config[:remote]}" # Add remote (relative to remote user home)
96
+
97
+ if @options[:reverse]
98
+ rsync_cmd += " " + `pwd`.gsub(/\s+/, "") + "#{@config[:local]}" # Put the local path after if we're downloading
99
+ end
100
+
93
101
  # Run the command
94
- puts rsync_cmd
95
- # system(rsync_cmd)
102
+ # puts rsync_cmd
103
+ system(rsync_cmd)
96
104
 
97
105
  # Remove excludes/pass file if needed
98
106
  tmp_exclude.unlink unless @config[:excludes].empty?
99
107
  tmp_pass.unlink unless @config[:pass].empty?
100
-
108
+
101
109
  end
102
-
110
+
103
111
  private
104
-
112
+
105
113
  def validate
106
-
114
+
107
115
  # Fail without hostname (user/password are optional)
108
116
  (puts "Error: no hostname set for `#{@name}`"; exit;) if @config[:host].empty?
109
117
 
@@ -113,6 +121,6 @@ module Deploy
113
121
  (puts "Error: no remote path set for `#{@name}`"; exit;) if @config[:remote].empty?
114
122
 
115
123
  end
116
-
124
+
117
125
  end
118
126
  end
@@ -1,5 +1,5 @@
1
1
  module Deploy
2
2
 
3
- VERSION = "0.0.13"
3
+ VERSION = "0.0.16"
4
4
 
5
5
  end
data/lib/deploy.rb CHANGED
@@ -14,6 +14,8 @@ module Deploy
14
14
  class Deployment
15
15
 
16
16
  attr_reader :environments
17
+
18
+ attr_accessor :reverse
17
19
 
18
20
  def initialize()
19
21
 
@@ -24,12 +26,15 @@ module Deploy
24
26
  @environments.push Environment.new(env[0], env[1])
25
27
  end
26
28
 
29
+ @reverse = false
30
+
27
31
  end
28
32
 
29
- def go(args)
33
+ def go(args = [])
30
34
 
31
35
  # If there are no arguments, deploy using the first environment in
32
36
  # the configuration file, otherwise loop through and deploy each one
37
+ # Note: the to_a statement ensures that args is not nil
33
38
  if args.size == 0
34
39
 
35
40
  @environments.first.deploy
@@ -51,7 +56,17 @@ module Deploy
51
56
  end
52
57
 
53
58
  end
59
+
60
+ end
54
61
 
62
+ # Set deployment reverse and apply it to all associated environments too
63
+ def reverse=(reverse)
64
+
65
+ @reverse = reverse
66
+ @environments.each do |env|
67
+ env.options[:reverse] = reverse
68
+ end
69
+
55
70
  end
56
71
 
57
72
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rsync-deploy
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.13
4
+ version: 0.0.16
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ross Zurowski