lib/docker-sync/sync_strategy/unison.rb in docker-sync-0.2.0.beta5 vs lib/docker-sync/sync_strategy/unison.rb in docker-sync-0.2.0.rc1
- old
+ new
@@ -21,15 +21,16 @@
@sync_name = sync_name
# if a custom image is set, apply it
if @options.key?('image')
@docker_image = @options['image']
else
- @docker_image = 'eugenmayer/unison:unox'
+ @docker_image = 'eugenmayer/unison'
end
begin
Preconditions::unison_available
Preconditions::unox_available
+ Preconditions::macfsevents_available
rescue Exception => e
say_status 'error', "#{@sync_name} has been configured to sync with unison, but no unison available", :red
say_status 'error', e.message, :red
exit 1
end
@@ -119,42 +120,49 @@
args = []
args = expand_ignore_strings + args
args.push(@options['src'])
args.push('-auto')
args.push('-batch')
- args.push(sync_prefer) if @options.key?('sync_prefer')
+ args.push(sync_prefer)
args.push(@options['sync_args']) if @options.key?('sync_args')
sync_host_port = get_host_port(get_container_name, UNISON_CONTAINER_PORT)
args.push("socket://#{@options['sync_host_ip']}:#{sync_host_port}")
if @options.key?('sync_group') || @options.key?('sync_groupid')
raise('Unison does not support sync_group, sync_groupid - please use rsync if you need that')
end
return args
end
+ # cares about conflict resolution
def sync_prefer
+ # thats our default, if nothing is set
+ unless @options.key?('sync_prefer') || @options['sync_prefer'] == 'default'
+ return "-prefer '#{@options['src']}' -copyonconflict"
+ end
+
case @options['sync_prefer']
- when 'src' then "-prefer #{@options['src']}"
- when 'dest' then "-prefer #{@options['dest']}"
- else "-prefer #{@options['sync_prefer']}"
+ when 'src' then "-prefer #{@options['src']}"
+ when 'dest' then "-prefer #{@options['dest']}"
+ else "-prefer #{@options['sync_prefer']}"
end
end
def start_container
say_status 'ok', 'Starting unison', :white
container_name = get_container_name
volume_name = get_volume_name
env = {}
+ 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')
+
ignore_strings = expand_ignore_strings
env['UNISON_EXCLUDES'] = ignore_strings.join(' ')
- env['UNISON_OWNER'] = @options['sync_user'] if @options.key?('sync_user')
env['MAX_INOTIFY_WATCHES'] = @options['max_inotify_watches'] if @options.key?('max_inotify_watches')
if @options['sync_userid'] == 'from_host'
- env['UNISON_OWNER_UID'] = Process.uid
+ env['OWNER_UID'] = Process.uid
else
- env['UNISON_OWNER_UID'] = @options['sync_userid'] if @options.key?('sync_userid')
+ env['OWNER_UID'] = @options['sync_userid'] if @options.key?('sync_userid')
end
additional_docker_env = env.map{ |key,value| "-e #{key}=\"#{value}\"" }.join(' ')
running = `docker ps --filter 'status=running' --filter 'name=#{container_name}' --format "{{.Names}}" | grep '^#{container_name}$'`
if running == ''
@@ -163,11 +171,11 @@
if exists == ''
say_status 'ok', "creating #{container_name} container", :white if @options['verbose']
run_privileged = '--privileged' if @options.key?('max_inotify_watches') #TODO: replace by the minimum capabilities required
cmd = "docker run -p '#{@options['sync_host_ip']}::#{UNISON_CONTAINER_PORT}' \
-v #{volume_name}:#{@options['dest']} \
- -e UNISON_DIR=#{@options['dest']} \
+ -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}"
@@ -198,10 +206,10 @@
say_status 'success', 'Unison server started', :green
end
def get_host_port(container_name, container_port)
File.exist?('/usr/bin/sed') ? sed = '/usr/bin/sed' : sed = `which sed`.chomp # use macOS native sed in /usr/bin/sed first, fallback to sed in $PATH if it's not there
- cmd = 'docker inspect --format=" {{ .NetworkSettings.Ports }} " ' + container_name + " | #{sed} " + '-E "s/.*map\[' + container_port + '[^ ]+ ([0-9]*)[^0-9].*/\1/"'
+ cmd = 'docker inspect --format=\'{{(index (index .NetworkSettings.Ports "5000/tcp") 0).HostPort}}\' ' + container_name
say_status 'command', cmd, :white if @options['verbose']
stdout, stderr, exit_status = Open3.capture3(cmd)
if not exit_status.success?
say_status 'command', cmd
say_status 'error', "Error getting mapped port, exit code #{$?.exitstatus}", :red