docker-sync 0.4.0.pre.beta1 → 0.4.0.pre.beta2

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: ee30fd93932dfd458f8d77e2e4109e0f61a16269
4
- data.tar.gz: 107807dec19acbc71e6807f861db99e67d52a2bc
3
+ metadata.gz: c66c65a38606565e60bf76aa80b33934690b6851
4
+ data.tar.gz: ee1aa4c4a84dfbb9eb9dfdbaa5fc31d3a27cef46
5
5
  SHA512:
6
- metadata.gz: 651b6deb48778e5c9dceae3ecae2a1668b16dc820e4e63b8ad6f818b2a7d4fcc13abf117e82575c38358eb63bd06412c742ab608f3f0eba5ab3e143170a2c6f3
7
- data.tar.gz: 819d3d464a51f88237d140a785a56f4e3cb4ed7745edab0ce32bd0c87eadecf9f20c14391b474cc099356b13d1ce21891fe93b6125d6cde08a392057b0899c2f
6
+ metadata.gz: 250dc5898a0f2e92ad7208bec4ff1c92b1a3177daf1873c8768ec634e6e4e3f1b68c2a3f8aa5e1fb8c9c9e3ca49952dcd360a41b25b1102060672727cfa52fd3
7
+ data.tar.gz: c59ef8da87e69dd577bb9f647de17ed9db331e6b4a6aae73210c7c1cecd05053145c89222fa8f96332d72afb794fab8e33624b203182ee22a0487e809da8b436
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.4.0-beta1
1
+ 0.4.0-beta2
@@ -126,7 +126,7 @@ module DockerSync
126
126
  watch_strategy = sync_config['watch_strategy']
127
127
  watch_strategy = 'dummy' if watch_strategy == 'disable'
128
128
 
129
- if ['fswatch', 'unison', 'dummy'].include?(watch_strategy)
129
+ if %w(fswatch unison dummy).include?(watch_strategy)
130
130
  watch_strategy
131
131
  else
132
132
  default_watch_strategy(sync_config)
@@ -136,7 +136,7 @@ module DockerSync
136
136
  def default_sync_strategy
137
137
  case true
138
138
  when OS.linux? then 'native'
139
- else 'unison'
139
+ else 'native_osx'
140
140
  end
141
141
  end
142
142
 
@@ -130,6 +130,7 @@ module Docker_sync
130
130
  end
131
131
 
132
132
  def stop
133
+ init_sync_processes
133
134
  @sync_processes.each { |sync_process|
134
135
  sync_process.stop
135
136
  unless sync_process.watch_thread.nil?
@@ -35,52 +35,17 @@ module Docker_Sync
35
35
  end
36
36
  end
37
37
 
38
- def run
39
- start_container
40
- sync
41
- end
42
-
43
- def watch
44
- # nop
45
- end
46
-
47
- def sync
48
- # nop
49
- end
50
-
51
- def expand_ignore_strings
52
- expanded_ignore_strings = []
53
-
54
- exclude_type = 'Name'
55
- unless @options['sync_excludes_type'].nil?
56
- exclude_type = @options['sync_excludes_type']
57
- end
58
-
59
- unless @options['sync_excludes'].nil?
60
- expanded_ignore_strings = @options['sync_excludes'].map do |pattern|
61
- if exclude_type == 'none'
62
- # the ignore type like Name / Path are part of the pattern
63
- ignore_string = "#{pattern}"
64
- else
65
- ignore_string = "#{exclude_type} #{pattern}"
66
- end
67
- "-ignore='#{ignore_string}'"
68
- end
69
- end
70
- expanded_ignore_strings
71
- end
72
-
73
38
  def start_container
74
- say_status 'ok', 'Starting unison', :white
39
+ say_status 'ok', 'Starting native_osx', :white
75
40
  container_name = get_container_name
76
- #create_volume
77
41
  host_sync_src = @options['src']
78
42
  volume_app_sync_name = @sync_name
79
43
  env = {}
80
- say_status 'ok', 'sync_user is no longer supported, since it ise no needed, use sync_userid only please', :yellow if @options.key?('sync_user')
44
+ raise 'sync_user is no longer supported, since it ise no needed, use sync_userid only please', :yellow if @options.key?('sync_user')
81
45
 
82
46
  ignore_strings = expand_ignore_strings
83
47
  env['UNISON_EXCLUDES'] = ignore_strings.join(' ')
48
+ env['UNISON_SYNC_PREFER'] = sync_prefer
84
49
  env['MAX_INOTIFY_WATCHES'] = @options['max_inotify_watches'] if @options.key?('max_inotify_watches')
85
50
  if @options['sync_userid'] == 'from_host'
86
51
  env['OWNER_UID'] = Process.uid
@@ -95,6 +60,7 @@ module Docker_Sync
95
60
  exists = `docker ps --filter "status=exited" --filter "name=#{container_name}" --format "{{.Names}}" | grep '^#{container_name}$'`
96
61
  if exists == ''
97
62
  say_status 'ok', "creating #{container_name} container", :white if @options['verbose']
63
+ run_privileged = ''
98
64
  run_privileged = '--privileged' if @options.key?('max_inotify_watches') #TODO: replace by the minimum capabilities required
99
65
  cmd = "docker run -v #{volume_app_sync_name}:/app_sync -v #{host_sync_src}:/host_sync -e VOLUME=#{@options['dest']} -e TZ=${TZ-`readlink /etc/localtime | sed -e 's,/usr/share/zoneinfo/,,'`} #{additional_docker_env} #{run_privileged} --name #{container_name} -d #{@docker_image}"
100
66
  else
@@ -109,26 +75,22 @@ module Docker_Sync
109
75
  `#{cmd}` || raise('Start failed')
110
76
  say_status 'ok', "starting initial sync of #{container_name}", :white if @options['verbose']
111
77
  # wait until container is started, then sync:
112
- say_status 'success', 'Unison container started', :green
78
+ say_status 'success', 'Sync container started', :green
113
79
  end
114
80
 
115
- def get_container_name
116
- return "#{@sync_name}"
81
+ def run
82
+ start_container
83
+ sync
117
84
  end
118
85
 
119
- def get_volume_name
120
- return @sync_name
86
+ def watch
87
+ # nop
121
88
  end
122
89
 
123
- def stop_container
124
- `docker ps | grep #{get_container_name} && docker stop #{get_container_name} && docker wait #{get_container_name}`
90
+ def sync
91
+ # nop
125
92
  end
126
93
 
127
- def reset_container
128
- stop_container
129
- `docker ps -a | grep #{get_container_name} && docker rm #{get_container_name}`
130
- `docker volume ls -q | grep #{get_volume_name} && docker volume rm #{get_volume_name}`
131
- end
132
94
 
133
95
  def clean
134
96
  reset_container
@@ -143,6 +105,64 @@ module Docker_Sync
143
105
  puts e.message
144
106
  end
145
107
  end
108
+
109
+ private
110
+
111
+ def reset_container
112
+ stop_container
113
+ `docker ps -a | grep #{get_container_name} && docker rm #{get_container_name}`
114
+ `docker volume ls -q | grep #{get_volume_name} && docker volume rm #{get_volume_name}`
115
+ end
116
+
117
+
118
+ def get_container_name
119
+ return "#{@sync_name}"
120
+ end
121
+
122
+ def get_volume_name
123
+ return @sync_name
124
+ end
125
+
126
+ def stop_container
127
+ `docker ps | grep #{get_container_name} && docker stop #{get_container_name} && docker wait #{get_container_name}`
128
+ end
129
+
130
+
131
+ # cares about conflict resolution
132
+ def sync_prefer
133
+ case @options.fetch('sync_prefer', 'default')
134
+ when 'default' then
135
+ '-prefer /host_sync' # thats our default, if nothing is set
136
+ when 'src' then
137
+ '-prefer /host_sync'
138
+ when 'dest' then
139
+ '-prefer /app_sync'
140
+ else
141
+ raise 'sync_pref can only be: src or dest, no path - path is no longer needed it abstracted'
142
+ end
143
+ end
144
+
145
+ def expand_ignore_strings
146
+ expanded_ignore_strings = []
147
+
148
+ exclude_type = 'Name'
149
+ unless @options['sync_excludes_type'].nil?
150
+ exclude_type = @options['sync_excludes_type']
151
+ end
152
+
153
+ unless @options['sync_excludes'].nil?
154
+ expanded_ignore_strings = @options['sync_excludes'].map do |pattern|
155
+ if exclude_type == 'none'
156
+ # the ignore type like Name / Path are part of the pattern
157
+ ignore_string = "#{pattern}"
158
+ else
159
+ ignore_string = "#{exclude_type} #{pattern}"
160
+ end
161
+ "-ignore='#{ignore_string}'"
162
+ end
163
+ end
164
+ expanded_ignore_strings
165
+ end
146
166
  end
147
167
  end
148
168
  end
@@ -23,6 +23,7 @@ class Sync < Thor
23
23
 
24
24
  desc 'start', 'Start all sync configurations in this project'
25
25
  method_option :daemon, :aliases => '-d', :default => false, :type => :boolean, :desc => 'Run in the background'
26
+ method_option :foreground, :aliases => '-d', :default => false, :type => :boolean, :desc => 'Run in the background'
26
27
  method_option :app_name, :aliases => '--name', :default => 'daemon', :type => :string, :desc => 'App name used in PID and OUTPUT file name for Daemon'
27
28
  method_option :dir, :aliases => '--dir', :default => './.docker-sync', :type => :string, :desc => 'Path to PID and OUTPUT file Directory'
28
29
  method_option :logd, :aliases => '--logd', :default => true, :type => :boolean, :desc => 'To log OUPUT to file on Daemon or not'
@@ -36,10 +37,15 @@ class Sync < Thor
36
37
  @sync_manager = Docker_sync::SyncManager.new(config: config)
37
38
 
38
39
  start_dir = Dir.pwd # Set start_dir variable to be equal to pre-daemonized folder, since daemonizing will change dir to '/'
39
- if options['daemon']
40
- daemonize
40
+
41
+ if options['daemon']
42
+ puts 'WARNING: --daemon is deprecated and now the default. Just start without --daemom'
43
+ end
44
+
45
+ if options['foreground']
46
+ say_status 'note:', 'Starting in foreground mode', :white
41
47
  else
42
- say_status 'note:', 'You can also run docker-sync in the background with --daemon', :white
48
+ daemonize
43
49
  end
44
50
 
45
51
  Dir.chdir(start_dir) do # We want run these in pre-daemonized folder/directory since provided config_path might not be full_path
@@ -56,16 +62,22 @@ class Sync < Thor
56
62
 
57
63
  config = config_preconditions
58
64
  sync_manager = Docker_sync::SyncManager.new(config: config)
59
-
60
- begin
61
- pid = File.read("#{options['dir']}/#{options['app_name']}.pid") # Read PID from PIDFILE created by Daemons
62
- Process.kill(:INT, -(Process.getpgid(pid.to_i))) # Send INT signal to group PID, which means INT will be sent to all sub-processes and Threads spawned by docker-sync
63
- wait_for_process_termination(pid.to_i)
64
- rescue Errno::ESRCH, Errno::ENOENT => e
65
- say_status 'error', e.message, :red # Rescue incase PIDFILE does not exist or there is no process with such PID
66
- say_status 'error', 'Check if your PIDFILE and process with such PID exists', :red
67
- exit(69) # EX_UNAVAILABLE (see `man sysexits` or `/usr/include/sysexits.h`)
65
+ sync_manager.stop
66
+ pid_file_path="#{options['dir']}/#{options['app_name']}.pid"
67
+ if File.exist?(pid_file_path)
68
+ begin
69
+ pid = File.read("#{options['dir']}/#{options['app_name']}.pid") # Read PID from PIDFILE created by Daemons
70
+ Process.kill(:INT, -(Process.getpgid(pid.to_i))) # Send INT signal to group PID, which means INT will be sent to all sub-processes and Threads spawned by docker-sync
71
+ wait_for_process_termination(pid.to_i)
72
+ rescue Errno::ESRCH, Errno::ENOENT => e
73
+ say_status 'error', e.message, :red # Rescue incase PIDFILE does not exist or there is no process with such PID
74
+ say_status 'error', 'Check if your PIDFILE and process with such PID exists', :red
75
+ exit(69) # EX_UNAVAILABLE (see `man sysexits` or `/usr/include/sysexits.h`)
76
+ end
77
+ else
78
+ # there was no watcher started / needed, e.g. dummy. Nothing to worry about
68
79
  end
80
+
69
81
  end
70
82
 
71
83
  desc 'sync', 'just sync - do not start a watcher though'
@@ -90,7 +102,7 @@ class Sync < Thor
90
102
  files.each do |pid_file|
91
103
  pid = File.read(pid_file).to_i
92
104
  Process.kill(:INT, -(Process.getpgid(pid))) if Daemons::Pid.running?(pid)
93
- say_status 'shutdown', 'Background dsync has been stopped'
105
+ say_status 'shutdown', 'Background sync has been stopped'
94
106
  end
95
107
  # Remove the .docker-sync directory
96
108
  FileUtils.rm_r dir if File.directory?(dir)
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: docker-sync
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.0.pre.beta1
4
+ version: 0.4.0.pre.beta2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Eugen Mayer