docker-sync 0.3.6 → 0.4.0.pre.beta1

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: b2336a2163de001ea72e9eb9c2c10121878f222a
4
- data.tar.gz: 86f36bcf8f7dfeff282d24482e57ee1b9841ce96
3
+ metadata.gz: ee30fd93932dfd458f8d77e2e4109e0f61a16269
4
+ data.tar.gz: 107807dec19acbc71e6807f861db99e67d52a2bc
5
5
  SHA512:
6
- metadata.gz: ad2e54be371b67155fa802581608754bdb9132e9070541962e4c0c70521890ea4c297085ce979d0b8ea2cbc9a04b50cf03f64346927b97fb089987c93892a4f6
7
- data.tar.gz: a77c9eac0ae4208d0d10cadb6b97bb1aa4578d9cf3dcce69e72c4695d8eea8d06afcca54d37ff320702d5ffbf5bd2f06051951f523c6e55e407267580ba2092d
6
+ metadata.gz: 651b6deb48778e5c9dceae3ecae2a1668b16dc820e4e63b8ad6f818b2a7d4fcc13abf117e82575c38358eb63bd06412c742ab608f3f0eba5ab3e143170a2c6f3
7
+ data.tar.gz: 819d3d464a51f88237d140a785a56f4e3cb4ed7745edab0ce32bd0c87eadecf9f20c14391b474cc099356b13d1ce21891fe93b6125d6cde08a392057b0899c2f
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.3.6
1
+ 0.4.0-beta1
@@ -115,7 +115,7 @@ module DockerSync
115
115
  def sync_strategy_for(sync_config)
116
116
  sync_strategy = sync_config['sync_strategy']
117
117
 
118
- if ['rsync', 'unison', 'native'].include?(sync_strategy)
118
+ if %w(rsync unison native native_osx).include?(sync_strategy)
119
119
  sync_strategy
120
120
  else
121
121
  default_sync_strategy
@@ -145,6 +145,7 @@ module DockerSync
145
145
  when 'rsync' then 'fswatch'
146
146
  when 'unison' then 'unison'
147
147
  when 'native' then 'dummy'
148
+ when 'native_osx' then 'dummy'
148
149
  else raise "you shouldn't be here"
149
150
  end
150
151
  end
@@ -154,7 +155,7 @@ module DockerSync
154
155
  # [nbr] convert the sync src from relative to absolute path
155
156
  # preserve '/' as it may be significant to the sync cmd
156
157
  absolute_path = File.expand_path(path)
157
- absolute_path << "/" if path.end_with?("/")
158
+ absolute_path << '/' if path.end_with?('/')
158
159
  absolute_path
159
160
  }
160
161
  end
@@ -49,7 +49,7 @@ module Docker_sync
49
49
 
50
50
  # for each strategy check if a custom image has been defined and inject that into the sync-endpoints
51
51
  # which do fit for this strategy
52
- %w(rsync unison).each do |strategy|
52
+ %w(rsync unison native_osx native).each do |strategy|
53
53
  if config.key?("#{strategy}_image") && @config_syncs[name]['sync_strategy'] == strategy
54
54
  @config_syncs[name]['image'] = config["#{strategy}_image"]
55
55
  end
@@ -3,6 +3,8 @@ require 'thor/shell'
3
3
  require 'docker-sync/sync_strategy/rsync'
4
4
  require 'docker-sync/sync_strategy/unison'
5
5
  require 'docker-sync/sync_strategy/native'
6
+ require 'docker-sync/sync_strategy/native_osx'
7
+
6
8
  # noinspection RubyResolve
7
9
  require 'docker-sync/watch_strategy/fswatch'
8
10
  require 'docker-sync/watch_strategy/dummy'
@@ -45,6 +47,8 @@ module Docker_Sync
45
47
  @sync_strategy = Docker_Sync::SyncStrategy::Unison.new(@sync_name, @options)
46
48
  when 'native'
47
49
  @sync_strategy = Docker_Sync::SyncStrategy::Native.new(@sync_name, @options)
50
+ when 'native_osx'
51
+ @sync_strategy = Docker_Sync::SyncStrategy::NativeOsx.new(@sync_name, @options)
48
52
  else
49
53
  raise "Unknown sync_strategy #{@options['sync_strategy']}"
50
54
  end
@@ -0,0 +1,148 @@
1
+ require 'thor/shell'
2
+ require 'docker-sync/preconditions/strategy'
3
+ require 'docker-sync/execution'
4
+ require 'open3'
5
+ require 'socket'
6
+ require 'terminal-notifier'
7
+
8
+ module Docker_Sync
9
+ module SyncStrategy
10
+ class NativeOsx
11
+ include Thor::Shell
12
+ include Execution
13
+
14
+ @options
15
+ @sync_name
16
+ @watch_thread
17
+ @local_server_pid
18
+
19
+ def initialize(sync_name, options)
20
+ @options = options
21
+ @sync_name = sync_name
22
+ # if a custom image is set, apply it
23
+ if @options.key?('image')
24
+ @docker_image = @options['image']
25
+ else
26
+ @docker_image = 'eugenmayer/unison:hostsync'
27
+ end
28
+
29
+ begin
30
+ DockerSync::Preconditions::Strategy.instance.docker_available
31
+ rescue Exception => e
32
+ say_status 'error', "#{@sync_name} has been configured to sync with native docker volume, but docker is not found", :red
33
+ say_status 'error', e.message, :red
34
+ exit 1
35
+ end
36
+ end
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
+ def start_container
74
+ say_status 'ok', 'Starting unison', :white
75
+ container_name = get_container_name
76
+ #create_volume
77
+ host_sync_src = @options['src']
78
+ volume_app_sync_name = @sync_name
79
+ 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')
81
+
82
+ ignore_strings = expand_ignore_strings
83
+ env['UNISON_EXCLUDES'] = ignore_strings.join(' ')
84
+ env['MAX_INOTIFY_WATCHES'] = @options['max_inotify_watches'] if @options.key?('max_inotify_watches')
85
+ if @options['sync_userid'] == 'from_host'
86
+ env['OWNER_UID'] = Process.uid
87
+ else
88
+ env['OWNER_UID'] = @options['sync_userid'] if @options.key?('sync_userid')
89
+ end
90
+
91
+ additional_docker_env = env.map{ |key,value| "-e #{key}=\"#{value}\"" }.join(' ')
92
+ running = `docker ps --filter 'status=running' --filter 'name=#{container_name}' --format "{{.Names}}" | grep '^#{container_name}$'`
93
+ if running == ''
94
+ say_status 'ok', "#{container_name} container not running", :white if @options['verbose']
95
+ exists = `docker ps --filter "status=exited" --filter "name=#{container_name}" --format "{{.Names}}" | grep '^#{container_name}$'`
96
+ if exists == ''
97
+ say_status 'ok', "creating #{container_name} container", :white if @options['verbose']
98
+ run_privileged = '--privileged' if @options.key?('max_inotify_watches') #TODO: replace by the minimum capabilities required
99
+ 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
+ else
101
+ say_status 'ok', "starting #{container_name} container", :white if @options['verbose']
102
+ cmd = "docker start #{container_name} && docker exec #{container_name} supervisorctl restart unison"
103
+ end
104
+ else
105
+ say_status 'ok', "#{container_name} container still running, restarting unison in container", :blue
106
+ cmd = "docker exec #{container_name} supervisorctl restart unison"
107
+ end
108
+ say_status 'command', cmd, :white if @options['verbose']
109
+ `#{cmd}` || raise('Start failed')
110
+ say_status 'ok', "starting initial sync of #{container_name}", :white if @options['verbose']
111
+ # wait until container is started, then sync:
112
+ say_status 'success', 'Unison container started', :green
113
+ end
114
+
115
+ def get_container_name
116
+ return "#{@sync_name}"
117
+ end
118
+
119
+ def get_volume_name
120
+ return @sync_name
121
+ end
122
+
123
+ def stop_container
124
+ `docker ps | grep #{get_container_name} && docker stop #{get_container_name} && docker wait #{get_container_name}`
125
+ end
126
+
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
+
133
+ def clean
134
+ reset_container
135
+ end
136
+
137
+ def stop
138
+ say_status 'ok', "Stopping sync container #{get_container_name}"
139
+ begin
140
+ stop_container
141
+ rescue Exception => e
142
+ say_status 'error', "Stopping failed of #{get_container_name}:", :red
143
+ puts e.message
144
+ end
145
+ end
146
+ end
147
+ end
148
+ end
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.6
4
+ version: 0.4.0.pre.beta1
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-05-03 00:00:00.000000000 Z
11
+ date: 2017-05-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: thor
@@ -166,6 +166,7 @@ files:
166
166
  - lib/docker-sync/sync_manager.rb
167
167
  - lib/docker-sync/sync_process.rb
168
168
  - lib/docker-sync/sync_strategy/native.rb
169
+ - lib/docker-sync/sync_strategy/native_osx.rb
169
170
  - lib/docker-sync/sync_strategy/rsync.rb
170
171
  - lib/docker-sync/sync_strategy/unison.rb
171
172
  - lib/docker-sync/update_check.rb
@@ -191,9 +192,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
191
192
  version: '2.0'
192
193
  required_rubygems_version: !ruby/object:Gem::Requirement
193
194
  requirements:
194
- - - ">="
195
+ - - ">"
195
196
  - !ruby/object:Gem::Version
196
- version: '0'
197
+ version: 1.3.1
197
198
  requirements: []
198
199
  rubyforge_project:
199
200
  rubygems_version: 2.4.5.1