docker-sync 0.3.5 → 0.3.6

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: 2a89a19048102b5fcc54438687fb393820dde82c
4
- data.tar.gz: 296a95c1806e2a39528928792e0a2214474f1cc9
3
+ metadata.gz: b2336a2163de001ea72e9eb9c2c10121878f222a
4
+ data.tar.gz: 86f36bcf8f7dfeff282d24482e57ee1b9841ce96
5
5
  SHA512:
6
- metadata.gz: 3f2eb116585b29cdc996a3b986b2e5c98d5bba11b082150e20bf818006b867d10dc0af3de3c54b48f63ad48bf0a59ce46c6e81f9d67a0f33ed670360cd1cdb8a
7
- data.tar.gz: 95b9667a3536132f1f3d768ac36ececfaa82fe51e48e1621efed5147c995d4cd6d92556ef4ff3ae23e70efe214c5a110290c37ffcb7ebc3dfe0f3658edf93c58
6
+ metadata.gz: ad2e54be371b67155fa802581608754bdb9132e9070541962e4c0c70521890ea4c297085ce979d0b8ea2cbc9a04b50cf03f64346927b97fb089987c93892a4f6
7
+ data.tar.gz: a77c9eac0ae4208d0d10cadb6b97bb1aa4578d9cf3dcce69e72c4695d8eea8d06afcca54d37ff320702d5ffbf5bd2f06051951f523c6e55e407267580ba2092d
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.3.5
1
+ 0.3.6
@@ -26,7 +26,10 @@ module DockerSync
26
26
 
27
27
  def initialize(config_path: nil, config_string: nil)
28
28
  if config_string.nil?
29
- config_path = DockerSync::ConfigLocator.lookup_project_config_path
29
+ if config_path.nil? || config_path.empty?
30
+ config_path = DockerSync::ConfigLocator.lookup_project_config_path
31
+ end
32
+
30
33
  load_project_config(config_path)
31
34
  else
32
35
  @config = DockerSync::ConfigSerializer.default_deserializer_string(config_string)
@@ -87,38 +90,85 @@ module DockerSync
87
90
  end
88
91
 
89
92
  def normalize_config!
93
+ normalize_options_config!
94
+
90
95
  config['syncs'].each do |name, sync_config|
91
96
  config['syncs'][name] = normalize_sync_config(sync_config)
92
97
  end
93
98
  end
94
99
 
100
+ def normalize_options_config!
101
+ config['options'] = {
102
+ 'project_root' => 'pwd',
103
+ }.merge(config['options'] || {})
104
+ end
105
+
95
106
  def normalize_sync_config(sync_config)
96
107
  {
97
108
  'sync_strategy' => sync_strategy_for(sync_config),
98
109
  'watch_strategy' => watch_strategy_for(sync_config)
99
- }.merge(sync_config)
110
+ }.merge(sync_config).merge(
111
+ 'src' => expand_path(sync_config['src']),
112
+ )
100
113
  end
101
114
 
102
115
  def sync_strategy_for(sync_config)
103
- case sync_config['sync_strategy']
104
- when 'rsync' then 'rsync'
105
- else 'unison'
116
+ sync_strategy = sync_config['sync_strategy']
117
+
118
+ if ['rsync', 'unison', 'native'].include?(sync_strategy)
119
+ sync_strategy
120
+ else
121
+ default_sync_strategy
106
122
  end
107
123
  end
108
124
 
109
125
  def watch_strategy_for(sync_config)
110
- if sync_config.key?('watch_strategy')
111
- case sync_config['watch_strategy']
112
- when 'fswatch' then 'fswatch'
113
- when 'disable','dummy' then 'dummy'
114
- else 'unison'
115
- end
116
- elsif sync_config['sync_strategy'] == 'rsync'
117
- 'fswatch'
126
+ watch_strategy = sync_config['watch_strategy']
127
+ watch_strategy = 'dummy' if watch_strategy == 'disable'
128
+
129
+ if ['fswatch', 'unison', 'dummy'].include?(watch_strategy)
130
+ watch_strategy
118
131
  else
119
- 'unison'
132
+ default_watch_strategy(sync_config)
120
133
  end
121
134
  end
122
135
 
136
+ def default_sync_strategy
137
+ case true
138
+ when OS.linux? then 'native'
139
+ else 'unison'
140
+ end
141
+ end
142
+
143
+ def default_watch_strategy(sync_config)
144
+ case sync_strategy_for(sync_config)
145
+ when 'rsync' then 'fswatch'
146
+ when 'unison' then 'unison'
147
+ when 'native' then 'dummy'
148
+ else raise "you shouldn't be here"
149
+ end
150
+ end
151
+
152
+ def expand_path(path)
153
+ Dir.chdir(project_root) {
154
+ # [nbr] convert the sync src from relative to absolute path
155
+ # preserve '/' as it may be significant to the sync cmd
156
+ absolute_path = File.expand_path(path)
157
+ absolute_path << "/" if path.end_with?("/")
158
+ absolute_path
159
+ }
160
+ end
161
+
162
+ def project_root
163
+ if use_config_path_for_project_root?
164
+ File.dirname(@config_path)
165
+ else
166
+ Dir.pwd
167
+ end
168
+ end
169
+
170
+ def use_config_path_for_project_root?
171
+ config['options']['project_root'] == 'config_path' && !(@config_path.nil? || @config_path.empty?)
172
+ end
123
173
  end
124
174
  end
@@ -2,6 +2,19 @@ module DockerSync
2
2
  module Preconditions
3
3
  class Linux
4
4
  def check_all_preconditions(config)
5
+ return unless should_run_precondition?
6
+
7
+ docker_available
8
+ docker_running
9
+
10
+ if config.unison_required?
11
+ unison_available
12
+ end
13
+
14
+ if config.rsync_required?
15
+ rsync_available
16
+ fswatch_available
17
+ end
5
18
  end
6
19
 
7
20
  def docker_available
@@ -18,7 +31,21 @@ module DockerSync
18
31
 
19
32
  def unison_available
20
33
  end
21
- end
22
34
 
35
+ def is_driver_docker_for_mac?
36
+ return false
37
+ end
38
+
39
+ def is_driver_docker_toolbox?
40
+ return false
41
+ end
42
+ private
43
+
44
+ def should_run_precondition?(silent: false)
45
+ true
46
+ end
47
+
48
+
49
+ end
23
50
  end
24
51
  end
@@ -45,6 +45,7 @@ module DockerSync
45
45
  cmd1 = 'brew install unison'
46
46
 
47
47
  Thor::Shell::Basic.new.say_status 'warning', 'Could not find unison binary in $PATH. Trying to install now', :red
48
+ Thor::Shell::Basic.new.say_status 'command', cmd1, :white
48
49
  if Thor::Shell::Basic.new.yes?('I will install unison using brew for you? (y/N)')
49
50
  system cmd1
50
51
  else
@@ -59,7 +60,7 @@ module DockerSync
59
60
  def fswatch_available
60
61
  if should_run_precondition?
61
62
  if (find_executable0 'fswatch').nil?
62
- cmd1 = 'brew install fswatch"'
63
+ cmd1 = 'brew install fswatch'
63
64
 
64
65
  Thor::Shell::Basic.new.say_status 'warning', 'No fswatch available. Install it by "brew install fswatch Trying to install now', :red
65
66
  if Thor::Shell::Basic.new.yes?('I will install fswatch using brew for you? (y/N)')
@@ -72,11 +73,22 @@ module DockerSync
72
73
 
73
74
  end
74
75
 
76
+ def is_driver_docker_for_mac?
77
+ `docker info | grep 'Docker Root Dir: /var/lib/docker' && docker info | grep 'Operating System: Alpine Linux'`
78
+ $?.success?
79
+ end
80
+
81
+ def is_driver_docker_toolbox?
82
+ return false unless find_executable0('docker-machine')
83
+ `docker info | grep 'Operating System: Boot2Docker'`
84
+ $?.success?
85
+ end
86
+
75
87
  private
76
88
 
77
89
  def should_run_precondition?(silent = false)
78
90
  unless has_brew?
79
- Thor::Shell::Basic.new.say_status 'inf', 'Not running any precondition checks since you have no brew and that is unsupported. Is all up to you know.', :white unless silent
91
+ Thor::Shell::Basic.new.say_status 'info', 'Not running any precondition checks since you have no brew and that is unsupported. Is all up to you know.', :white unless silent
80
92
  return false
81
93
  end
82
94
  return true
@@ -90,15 +102,24 @@ module DockerSync
90
102
  def unox_available
91
103
  if should_run_precondition?
92
104
  `brew list unox`
93
- if $?.exitstatus > 0
94
- unless (find_executable0 'unison-fsmonitor').nil?
95
- # unox installed, but not using brew, we do not allow that anymore
96
- Thor::Shell::Basic.new.say_status 'error', 'You install unison-fsmonitor (unox) not using brew. Please uninstall it and run docker-sync again, so we can install it for you', :red
97
- exit 1
105
+ unless $?.success?
106
+ # unox installed, but not using brew, we do not allow that anymore
107
+ if File.exist?('/usr/local/bin/unison-fsmonitor')
108
+ Thor::Shell::Basic.new.say_status 'error', 'You installed unison-fsmonitor (unox) not using brew-method - the old legacy way. We need to fix that.', :red
109
+
110
+ uninstall_cmd='sudo rm /usr/local/bin/unison-fsmonitor'
111
+ Thor::Shell::Basic.new.say_status 'command', uninstall_cmd, :white
112
+ if Thor::Shell::Basic.new.yes?('Should i uninstall the legacy /usr/local/bin/unison-fsmonitor for you ? (y/N)')
113
+ system uninstall_cmd
114
+ else
115
+ Thor::Shell::Basic.new.say_status 'error', 'Uninstall /usr/local/bin/unison-fsmonitor manually please', :white
116
+ exit 1
117
+ end
98
118
  end
99
- cmd1 = 'brew tap eugenmayer/dockersync && brew install eugenmayer/dockersync/unox'
100
119
 
120
+ cmd1 = 'brew tap eugenmayer/dockersync && brew install eugenmayer/dockersync/unox'
101
121
  Thor::Shell::Basic.new.say_status 'warning', 'Could not find unison-fsmonitor (unox) binary in $PATH. Trying to install now', :red
122
+ Thor::Shell::Basic.new.say_status 'command', cmd1, :white
102
123
  if Thor::Shell::Basic.new.yes?('I will install unox through brew for you? (y/N)')
103
124
  system cmd1
104
125
  else
@@ -51,6 +51,14 @@ module DockerSync
51
51
  def unison_available
52
52
  strategy.unison_available
53
53
  end
54
+
55
+ def is_driver_docker_for_mac?
56
+ strategy.is_driver_docker_for_mac?
57
+ end
58
+
59
+ def is_driver_docker_toolbox?
60
+ strategy.is_driver_docker_toolbox?
61
+ end
54
62
  end
55
63
  end
56
64
  end
@@ -30,12 +30,6 @@ module Docker_sync
30
30
  @config_syncs.each do |name, config|
31
31
  @config_syncs[name]['config_path'] = @config_path
32
32
 
33
- # [nbr] convert the sync src from relative to absolute path
34
- # preserve '/' as it may be significant to the sync cmd
35
- absolute_path = File.expand_path(@config_syncs[name]['src'])
36
- absolute_path << "/" if @config_syncs[name]['src'].end_with?("/")
37
- @config_syncs[name]['src'] = absolute_path
38
-
39
33
  @config_syncs[name]['cli_mode'] = @config_global['cli_mode'] || 'auto'
40
34
 
41
35
  # set the global verbose setting, if the sync-endpoint does not define a own one
@@ -46,8 +40,10 @@ module Docker_sync
46
40
  end
47
41
  end
48
42
 
49
- # set default value for 'dest'
50
- if !@config_syncs[name].key?('dest')
43
+ if @config_syncs[name].key?('dest')
44
+ puts 'Please do no longer use "dest" in your docker-sync.yml configuration - also see https://github.com/EugenMayer/docker-sync/wiki/1.2-Upgrade-Guide#dest-has-been-removed!'
45
+ exit 1
46
+ else
51
47
  @config_syncs[name]['dest'] = '/sync'
52
48
  end
53
49
 
@@ -163,6 +159,7 @@ module Docker_sync
163
159
  config_string: options[:config_string]
164
160
  )
165
161
 
162
+ @config_path = config.config_path
166
163
  @config_global = config['options'] || {}
167
164
  @config_syncs = config['syncs']
168
165
  upgrade_syncs_config
@@ -2,6 +2,7 @@ require 'thor/shell'
2
2
  # noinspection RubyResolve
3
3
  require 'docker-sync/sync_strategy/rsync'
4
4
  require 'docker-sync/sync_strategy/unison'
5
+ require 'docker-sync/sync_strategy/native'
5
6
  # noinspection RubyResolve
6
7
  require 'docker-sync/watch_strategy/fswatch'
7
8
  require 'docker-sync/watch_strategy/dummy'
@@ -18,11 +19,17 @@ module Docker_Sync
18
19
 
19
20
  # noinspection RubyStringKeysInHashInspection
20
21
  def initialize(sync_name, options)
22
+ @sync_name = sync_name
23
+
21
24
  defaults = {
22
25
  'verbose' => false,
23
- 'sync_host_ip' => get_host_ip
26
+ 'sync_host_ip' => get_host_ip_default
24
27
  }
25
- @sync_name = sync_name
28
+ # even if sync_host_ip is set, if it is set to auto, enforce the default
29
+ if options.key?('sync_host_ip') && options['sync_host_ip'] == 'auto' || options['sync_host_ip'] == ''
30
+ options['sync_host_ip'] = defaults['sync_host_ip']
31
+ end
32
+
26
33
  @options = defaults.merge(options)
27
34
  @sync_strategy = nil
28
35
  @watch_strategy = nil
@@ -36,6 +43,8 @@ module Docker_Sync
36
43
  @sync_strategy = Docker_Sync::SyncStrategy::Rsync.new(@sync_name, @options)
37
44
  when 'unison'
38
45
  @sync_strategy = Docker_Sync::SyncStrategy::Unison.new(@sync_name, @options)
46
+ when 'native'
47
+ @sync_strategy = Docker_Sync::SyncStrategy::Native.new(@sync_name, @options)
39
48
  else
40
49
  raise "Unknown sync_strategy #{@options['sync_strategy']}"
41
50
  end
@@ -54,8 +63,17 @@ module Docker_Sync
54
63
  end
55
64
  end
56
65
 
57
- def get_host_ip
58
- return '127.0.0.1'
66
+ def get_host_ip_default
67
+ return '127.0.0.1' if DockerSync::Preconditions::Strategy.instance.is_driver_docker_for_mac?
68
+
69
+ if DockerSync::Preconditions::Strategy.instance.is_driver_docker_toolbox?
70
+ cmd = 'docker-machine ip'
71
+ stdout, stderr, exit_status = Open3.capture3(cmd)
72
+ unless exit_status.success?
73
+ raise "Error getting sync_host_ip automatically, exit code #{$?.exitstatus} ... #{stderr}"
74
+ end
75
+ return stdout.gsub("\n",'')
76
+ end
59
77
  end
60
78
 
61
79
  def run
@@ -0,0 +1,69 @@
1
+ require 'thor/shell'
2
+ require 'docker-sync/preconditions/strategy'
3
+
4
+ module Docker_Sync
5
+ module SyncStrategy
6
+ class Native
7
+ include Thor::Shell
8
+
9
+ @options
10
+ @sync_name
11
+
12
+ def initialize(sync_name, options)
13
+ @sync_name = sync_name
14
+ @options = options
15
+
16
+ begin
17
+ DockerSync::Preconditions::Strategy.instance.docker_available
18
+ rescue Exception => e
19
+ say_status 'error', "#{@sync_name} has been configured to sync with native docker volume, but docker is not found", :red
20
+ say_status 'error', e.message, :red
21
+ exit 1
22
+ end
23
+ end
24
+
25
+ def run
26
+ create_volume
27
+ end
28
+
29
+ def sync
30
+ # noop
31
+ end
32
+
33
+ def get_volume_name
34
+ @sync_name
35
+ end
36
+
37
+ def start_container
38
+ # noop
39
+ end
40
+
41
+ def clean
42
+ delete_volume
43
+ end
44
+
45
+ def stop
46
+ # noop
47
+ end
48
+
49
+ private
50
+
51
+ def create_volume
52
+ run_cmd "docker volume create --opt type=none --opt device=\"#{@options['src']}\" --opt o=bind "\
53
+ "--name #{get_volume_name}"
54
+
55
+ say_status 'success', "Docker volume for #{get_volume_name} created", :white
56
+ end
57
+
58
+ def delete_volume
59
+ run_cmd "docker volume ls -q | grep #{get_volume_name} && docker volume rm #{get_volume_name}"
60
+ end
61
+
62
+ def run_cmd(cmd)
63
+ say_status 'command', cmd, :white if @options['verbose']
64
+
65
+ `#{cmd}`
66
+ end
67
+ end
68
+ end
69
+ end
@@ -117,7 +117,7 @@ module Docker_Sync
117
117
  def sync_options
118
118
  args = []
119
119
  args = expand_ignore_strings + args
120
- args.push(@options['src'])
120
+ args.push("'#{@options['src']}'")
121
121
  args.push('-auto')
122
122
  args.push('-batch')
123
123
  args.push(sync_prefer)
@@ -187,7 +187,7 @@ module Docker_Sync
187
187
  stdout, stderr, exit_status = Open3.capture3(cmd)
188
188
  break if exit_status == 0
189
189
  attempt += 1
190
- break if attempt > max_attempt
190
+ raise 'Failed to start unison container in time, try to increase max_attempt in your configuration. See https://github.com/EugenMayer/docker-sync/wiki/2.-Configuration for more informations' if attempt > max_attempt
191
191
  sleep 1
192
192
  end
193
193
  sync
@@ -65,7 +65,7 @@ class UpgradeChecker
65
65
  end
66
66
 
67
67
  if Gem::Version.new(last_upgraded_version) < Gem::Version.new('0.3.0')
68
- Thor::Shell::Basic.new.say_status 'warning', "The installation progress of docker-sync 0.3.0 has changed, brew is now mandatory - you need to uninstall unox ! : \n\n_Please_ read :): https://github.com/EugenMayer/docker-sync/wiki/1.3-Upgrade-Guide\n\n", :red
68
+ Thor::Shell::Basic.new.say_status 'warning', "The installation progress of docker-sync 0.3.0 has changed, brew is now mandatory - you need to uninstall unox ! : \n\n_Please_ read :): https://github.com/EugenMayer/docker-sync/wiki/1.2-Upgrade-Guide\n\n", :red
69
69
 
70
70
  cmd1 = 'sudo rm -f /usr/local/bin/unison-fsmonitor && brew tap eugenmayer/dockersync && brew install eugenmayer/dockersync/unox'
71
71
  Thor::Shell::Basic.new.say_status 'ok', cmd1, :rwhite
@@ -9,11 +9,13 @@ module Docker_Sync
9
9
 
10
10
  @options
11
11
  @sync_name
12
+ @watch_fork
12
13
  @watch_thread
13
14
 
14
15
  def initialize(sync_name, options)
15
16
  @options = options
16
17
  @sync_name = sync_name
18
+ @watch_fork = nil
17
19
  @watch_thread = nil
18
20
  end
19
21
 
@@ -33,6 +35,10 @@ module Docker_Sync
33
35
  def watch_options
34
36
  end
35
37
 
38
+ def watch_fork
39
+ return @watch_fork
40
+ end
41
+
36
42
  def watch_thread
37
43
  return @watch_thread
38
44
  end
@@ -82,6 +82,11 @@ module Docker_Sync
82
82
  # append the actual operation
83
83
  return "#{sync_command}sync"
84
84
  end
85
+
86
+ def watch_fork
87
+ return nil
88
+ end
89
+
85
90
  def watch_thread
86
91
  return @watch_thread
87
92
  end
data/tasks/sync/sync.thor CHANGED
@@ -119,7 +119,7 @@ class Sync < Thor
119
119
 
120
120
  config = config_preconditions
121
121
 
122
- say_status 'ok',"Found configuration at #{config_path}"
122
+ say_status 'ok',"Found configuration at #{config.config_path}"
123
123
  @sync_manager = Docker_sync::SyncManager.new(config: config)
124
124
  @sync_manager.get_sync_points.each do |name, config|
125
125
  say_status name, "On address #{config['sync_host_ip']}:#{config['sync_host_port']}",:white unless options['verbose']
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: docker-sync
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.5
4
+ version: 0.3.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Eugen Mayer
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-04-25 00:00:00.000000000 Z
11
+ date: 2017-05-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: thor
@@ -165,6 +165,7 @@ files:
165
165
  - lib/docker-sync/preconditions/strategy.rb
166
166
  - lib/docker-sync/sync_manager.rb
167
167
  - lib/docker-sync/sync_process.rb
168
+ - lib/docker-sync/sync_strategy/native.rb
168
169
  - lib/docker-sync/sync_strategy/rsync.rb
169
170
  - lib/docker-sync/sync_strategy/unison.rb
170
171
  - lib/docker-sync/update_check.rb