capistrano-syncfiles 0.1.0 → 0.2.0

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: 14f3dd6c418570a81f704b80c94b67ae9d2657db
4
- data.tar.gz: b52c8d0ba32469a41d38300f8350e92f7c9c026a
3
+ metadata.gz: 1177558c37d50af39fefd640b3fef6b01d5d95b2
4
+ data.tar.gz: d1616acee6018b4001875964df9a9db4172ba304
5
5
  SHA512:
6
- metadata.gz: f5b4ae710b0e4483ad71c7fa9dde612d7b92529d98c5f82db5b246b7c48f3717d7c3262f5bf4c93f773a53a83d2856325c578a159131668242e1e30a197372fa
7
- data.tar.gz: b6051c8550ea65b4ae978197a3b0a46e97abe54503ecb3c2dcb1bceaa63a5b5bd38a7f08b2b5ecf733efa567e8bc58d7a0ee88af0b4516889b5dfa0552d1a765
6
+ metadata.gz: 2eb78df5dcfed5fbbcc2966dda1d8e524710f56d764b34c195cb34a493cef5289a5b49f6eb06c1105dc4c4f063d97c0f86fd3c2cc764e5d78297b4224e81dc18
7
+ data.tar.gz: cb00e0c3907fd997e327ab85c5a19fd21e23cae3c002182e9e44bda464b1b3e9ef0a527f3bb74e481c05c1d24b9954b81c5a6881df29ebfb15adaf705dbdca77
data/README.md CHANGED
@@ -1,6 +1,8 @@
1
1
  # capistrano-syncfiles
2
2
 
3
- This gem provides up and down file syncing with rsync or tar. This could be usefull if you are in a shared hosting environment.
3
+ This gem provides up and down file syncing with rsync, tar or sftp. This could be usefull if you are in a shared hosting environment.
4
+
5
+ Supports folder excludes.
4
6
 
5
7
  ## Installation
6
8
  First make sure you install the capistrano-syncfiles by adding it to your `Gemfile`:
@@ -17,7 +19,7 @@ Configure your files and folders like these:
17
19
  set :syncfiles, {
18
20
  'wordpress/wp-content/uploads' => { # local path
19
21
  remote: 'wordpress/wp-content/uploads', # remote path
20
- exclude: ['fvm', 'ithemes-security', 'wc-logs'] # excluded files
22
+ exclude: ['fvm', 'ithemes-security', 'wc-logs'] # excluded folders/files, based on local path, works also for remote
21
23
  }
22
24
  }
23
25
 
@@ -26,6 +28,8 @@ set :syncfiles_roles, :all # roles to run on, default: :all
26
28
  set :syncfiles_temp_file # applies only to tar strategy, default: "/tmp/transfere-#{local_path.hash}.tar.gz"
27
29
 
28
30
  set :syncfiles_tar_verbose # applies only to tar strategy, default: true
31
+
32
+ set :syncfiles_sftp_password # password for sftp connection
29
33
  ```
30
34
 
31
35
  ## Usage
@@ -33,8 +37,12 @@ The following tasks will be added
33
37
  ```
34
38
  cap syncfiles:rsync:down
35
39
  cap syncfiles:rsync:up
40
+
36
41
  cap syncfiles:tar:down
37
42
  cap syncfiles:tar:up
43
+
44
+ cap syncfiles:sftp:down
45
+ cap syncfiles:sftp:up
38
46
  ```
39
47
 
40
48
  You can invoke this tasks(Rake) as you do normally: https://github.com/ruby/rake
@@ -45,8 +53,8 @@ Capistrano tasks: http://capistranorb.com/documentation/getting-started/flow/
45
53
  The MIT License (MIT)
46
54
 
47
55
  ### Changelog
56
+ ##### 0.2.0
57
+ - add sftp strategy
48
58
 
49
- 0.1.0
50
- -----
51
-
59
+ ##### 0.1.0
52
60
  - Initial release
@@ -3,13 +3,13 @@ $:.push File.expand_path("../lib", __FILE__)
3
3
 
4
4
  Gem::Specification.new do |s|
5
5
  s.name = "capistrano-syncfiles"
6
- s.version = "0.1.0"
6
+ s.version = "0.2.0"
7
7
  s.licenses = ["MIT"]
8
8
  s.authors = ["Tom Hanoldt"]
9
9
  s.email = ["tom@creative-workflow.berlin"]
10
10
  s.homepage = "https://github.com/creative-workflow/capistrano-syncfiles"
11
- s.summary = %q{This gem provides up and down file syncing with rsync or tar. This could be usefull if you are in a shared hosting environment.}
12
- s.description = %q{This gem provides up and down file syncing with rsync or tar. This could be usefull if you are in a shared hosting environment.}
11
+ s.summary = %q{This gem provides up and down file syncing with rsync, tar or sftp. This could be usefull if you are in a shared hosting environment.}
12
+ s.description = %q{This gem provides up and down file syncing with rsync, tar or sftp. This could be usefull if you are in a shared hosting environment.}
13
13
 
14
14
  s.files = `git ls-files`.split("\n")
15
15
  s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
@@ -18,4 +18,5 @@ Gem::Specification.new do |s|
18
18
 
19
19
  # specify any dependencies here; for example:
20
20
  s.add_dependency "capistrano", "~> 3.0"
21
+ s.add_dependency 'fun_sftp', '~> 1.1.1'
21
22
  end
@@ -0,0 +1,80 @@
1
+ require 'fun_sftp'
2
+ namespace :sftp do
3
+ def connection(server, username, password)
4
+ @connection ||= FunSftp::SFTPClient.new(server, username, password)
5
+ end
6
+
7
+ def ensure_directory_exsits_remote(handle, remote_directory)
8
+ return if handle.has_directory? remote_directory
9
+
10
+ parent_directory = ::File.dirname(remote_directory)
11
+ if !handle.has_directory? parent_directory
12
+ ensure_directory_exsits_remote(handle, parent_directory)
13
+ end
14
+
15
+ puts "mkdir #{remote_directory}"
16
+ handle.mkdir!(remote_directory)
17
+ end
18
+
19
+ desc "Synchronise local and remote wp content folders via sftp"
20
+ task :up do
21
+ files = fetch(:syncfiles)
22
+ files.each do |local_path, config|
23
+ remote_path = config[:remote]
24
+ exclude_dir = Array(config[:exclude])
25
+ exclude_args = exclude_dir.map { |dir| "! -path '#{dir}/*'"}
26
+ sync_roles = fetch(:syncfiles_roles, :all)
27
+
28
+ cmd = ["find #{local_path} -type fl ", *exclude_args]
29
+ puts cmd.join(' ')
30
+ filtered_files = `#{cmd.join(' ')}`.lines
31
+
32
+ on release_roles sync_roles do |role|
33
+ handle = connection(role.hostname, role.user, fetch(:syncfiles_sftp_password))
34
+
35
+ uploads = filtered_files.map do |local_file|
36
+ local_file.strip!
37
+
38
+ remote_file = local_file.sub(local_path, remote_path)
39
+
40
+ remote_directory = ::File.dirname(remote_file)
41
+
42
+ ensure_directory_exsits_remote(handle, remote_directory)
43
+
44
+ handle.upload!(local_file, remote_file)
45
+ end
46
+ end
47
+ end
48
+ end
49
+
50
+ desc "Synchronise local and remote wp content folders via sftp"
51
+ task :down do
52
+ files = fetch(:syncfiles)
53
+ files.each do |local_path, config|
54
+ remote_path = config[:remote]
55
+ exclude_dir = Array(config[:exclude])
56
+ sync_roles = fetch(:syncfiles_roles, :all)
57
+
58
+ on primary sync_roles do |role|
59
+ handle = connection(role.hostname, role.user, fetch(:syncfiles_sftp_password))
60
+
61
+ puts "collecting files in #{remote_path}"
62
+ handle.glob(remote_path, "**/*").each do |remote_file|
63
+
64
+ remote_file = "#{remote_path}/#{remote_file}"
65
+
66
+ local_file = remote_file.sub(remote_path, local_path)
67
+
68
+ next if exclude_dir.any? do |exclude|
69
+ local_file.start_with?(exclude)
70
+ end
71
+
72
+ `mkdir -p #{::File.dirname(local_file)}`
73
+
74
+ handle.download!(remote_file, local_file)
75
+ end
76
+
77
+ end
78
+ end
79
+ end
80
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: capistrano-syncfiles
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tom Hanoldt
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-08-19 00:00:00.000000000 Z
11
+ date: 2017-08-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: capistrano
@@ -24,8 +24,22 @@ dependencies:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
26
  version: '3.0'
27
- description: This gem provides up and down file syncing with rsync or tar. This could
28
- be usefull if you are in a shared hosting environment.
27
+ - !ruby/object:Gem::Dependency
28
+ name: fun_sftp
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: 1.1.1
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: 1.1.1
41
+ description: This gem provides up and down file syncing with rsync, tar or sftp. This
42
+ could be usefull if you are in a shared hosting environment.
29
43
  email:
30
44
  - tom@creative-workflow.berlin
31
45
  executables: []
@@ -41,6 +55,7 @@ files:
41
55
  - lib/capistrano/syncfiles.rb
42
56
  - lib/capistrano/tasks/syncfiles.rake
43
57
  - lib/capistrano/tasks/syncfiles/rsync.rake
58
+ - lib/capistrano/tasks/syncfiles/sftp.rake
44
59
  - lib/capistrano/tasks/syncfiles/tar.rake
45
60
  homepage: https://github.com/creative-workflow/capistrano-syncfiles
46
61
  licenses:
@@ -65,6 +80,6 @@ rubyforge_project:
65
80
  rubygems_version: 2.6.12
66
81
  signing_key:
67
82
  specification_version: 4
68
- summary: This gem provides up and down file syncing with rsync or tar. This could
69
- be usefull if you are in a shared hosting environment.
83
+ summary: This gem provides up and down file syncing with rsync, tar or sftp. This
84
+ could be usefull if you are in a shared hosting environment.
70
85
  test_files: []