rsync-deploy 0.0.13 → 0.0.16
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.
- checksums.yaml +4 -4
- data/README.md +18 -2
- data/bin/deploy +79 -40
- data/lib/deploy/environment.rb +35 -27
- data/lib/deploy/version.rb +1 -1
- data/lib/deploy.rb +16 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3717284c1b26d927d0e36696e2539e5964165f75
|
4
|
+
data.tar.gz: df5757be4cec9ed087d0b3295d187aadb6b9c856
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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:
|
7
|
-
#
|
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] [
|
16
|
+
Usage: deploy [COMMAND] [OPTIONS] [ENVIRONMENTS]
|
15
17
|
|
16
18
|
Commands:
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
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
|
-
|
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
|
30
|
-
-v, --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
|
-
|
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
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
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
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
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
|
-
|
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)
|
data/lib/deploy/environment.rb
CHANGED
@@ -34,9 +34,9 @@ module Deploy
|
|
34
34
|
|
35
35
|
@config[:excludes] = hash['exclude'] || Array.new
|
36
36
|
|
37
|
-
|
38
|
-
@options[:verbose] = hash['verbose']
|
39
|
-
@options[:sync] = hash['sync']
|
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'
|
71
|
-
rsync_cmd += 'v' if @options[:verbose]
|
72
|
-
rsync_cmd += 'z'
|
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'
|
75
|
-
|
76
|
-
|
77
|
-
|
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]} "
|
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 += "
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
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
|
-
|
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
|
data/lib/deploy/version.rb
CHANGED
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
|