docker-sync 0.2.3 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/VERSION +1 -1
- data/lib/docker-sync.rb +4 -0
- data/lib/docker-sync/config/config_locator.rb +80 -0
- data/lib/docker-sync/config/config_serializer.rb +56 -0
- data/lib/docker-sync/config/global_config.rb +55 -0
- data/lib/docker-sync/config/project_config.rb +123 -0
- data/lib/docker-sync/preconditions/preconditions_linux.rb +24 -0
- data/lib/docker-sync/preconditions/preconditions_osx.rb +148 -0
- data/lib/docker-sync/preconditions/strategy.rb +57 -0
- data/lib/docker-sync/sync_manager.rb +16 -47
- data/lib/docker-sync/sync_process.rb +14 -22
- data/lib/docker-sync/sync_strategy/rsync.rb +3 -3
- data/lib/docker-sync/sync_strategy/unison.rb +3 -5
- data/lib/docker-sync/update_check.rb +18 -15
- data/lib/docker-sync/upgrade_check.rb +25 -7
- data/lib/docker-sync/watch_strategy/dummy.rb +0 -1
- data/lib/docker-sync/watch_strategy/fswatch.rb +2 -2
- data/lib/docker-sync/watch_strategy/unison.rb +0 -1
- data/tasks/daemon/daemon.thor +2 -2
- data/tasks/stack/stack.thor +12 -30
- data/tasks/sync/sync.thor +46 -28
- metadata +24 -5
- data/lib/docker-sync/config.rb +0 -120
- data/lib/docker-sync/config_template.rb +0 -17
- data/lib/docker-sync/preconditions.rb +0 -100
@@ -0,0 +1,57 @@
|
|
1
|
+
require 'docker-sync/preconditions/preconditions_osx'
|
2
|
+
require 'docker-sync/preconditions/preconditions_linux'
|
3
|
+
|
4
|
+
require 'singleton'
|
5
|
+
require 'os'
|
6
|
+
|
7
|
+
module DockerSync
|
8
|
+
module Preconditions
|
9
|
+
class Strategy
|
10
|
+
include Singleton
|
11
|
+
|
12
|
+
attr_accessor :strategy
|
13
|
+
|
14
|
+
def initialize
|
15
|
+
if DockerSync::Preconditions::Strategy.is_osx
|
16
|
+
@strategy = DockerSync::Preconditions::Osx.new
|
17
|
+
elsif DockerSync::Preconditions::Strategy.is_linux
|
18
|
+
@strategy = DockerSync::Preconditions::Linux.new
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
def self.is_osx
|
23
|
+
return OS.mac?
|
24
|
+
end
|
25
|
+
|
26
|
+
def self.is_linux
|
27
|
+
return OS.linux?
|
28
|
+
end
|
29
|
+
|
30
|
+
def check_all_preconditions(config)
|
31
|
+
strategy.check_all_preconditions(config)
|
32
|
+
end
|
33
|
+
|
34
|
+
def docker_available
|
35
|
+
strategy.docker_available
|
36
|
+
end
|
37
|
+
|
38
|
+
def docker_running
|
39
|
+
strategy.docker_running
|
40
|
+
end
|
41
|
+
|
42
|
+
def rsync_available
|
43
|
+
strategy.rsync_available
|
44
|
+
end
|
45
|
+
|
46
|
+
|
47
|
+
def fswatch_available
|
48
|
+
strategy.fswatch_available
|
49
|
+
end
|
50
|
+
|
51
|
+
def unison_available
|
52
|
+
strategy.unison_available
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
@@ -3,10 +3,6 @@ require 'thor/shell'
|
|
3
3
|
require 'docker-sync/sync_process'
|
4
4
|
# noinspection RubyResolve
|
5
5
|
require 'docker-sync/execution'
|
6
|
-
require 'yaml'
|
7
|
-
require 'dotenv'
|
8
|
-
require 'docker-sync/config_template'
|
9
|
-
require 'docker-sync/config'
|
10
6
|
|
11
7
|
module Docker_sync
|
12
8
|
class SyncManager
|
@@ -17,31 +13,9 @@ module Docker_sync
|
|
17
13
|
@config_path
|
18
14
|
|
19
15
|
def initialize(options)
|
20
|
-
DockerSyncConfig.load_dotenv
|
21
|
-
|
22
16
|
@sync_processes = []
|
23
|
-
@config_syncs = []
|
24
|
-
@config_global = []
|
25
|
-
@config_string = options[:config_string]
|
26
|
-
@config_path = options[:config_path]
|
27
|
-
load_configuration
|
28
|
-
end
|
29
17
|
|
30
|
-
|
31
|
-
unless File.exist?(@config_path)
|
32
|
-
raise "Config could not be loaded from #{@config_path} - it does not exist"
|
33
|
-
end
|
34
|
-
return File.read(@config_path)
|
35
|
-
end
|
36
|
-
|
37
|
-
def load_configuration
|
38
|
-
# try to interpolate supplied inline config string, alternatively load the configuration file
|
39
|
-
config = ConfigTemplate::interpolate_config_string(@config_string || load_configuration_file())
|
40
|
-
|
41
|
-
validate_config(config)
|
42
|
-
@config_global = config['options'] || {}
|
43
|
-
@config_syncs = config['syncs']
|
44
|
-
upgrade_syncs_config
|
18
|
+
load_configuration(options)
|
45
19
|
end
|
46
20
|
|
47
21
|
def global_options
|
@@ -87,26 +61,6 @@ module Docker_sync
|
|
87
61
|
end
|
88
62
|
end
|
89
63
|
|
90
|
-
def validate_config(config)
|
91
|
-
unless config.key?('syncs')
|
92
|
-
raise ('no syncs defined')
|
93
|
-
end
|
94
|
-
|
95
|
-
config['syncs'].each do |name, sync_config|
|
96
|
-
validate_sync_config(name, sync_config)
|
97
|
-
end
|
98
|
-
|
99
|
-
return true
|
100
|
-
end
|
101
|
-
|
102
|
-
def validate_sync_config(name, sync_config)
|
103
|
-
config_mandatory = %w[src]
|
104
|
-
config_mandatory.push('sync_host_port') if sync_config['sync_strategy'] == 'rsync' #TODO: Implement autodisovery for other strategies
|
105
|
-
config_mandatory.each do |key|
|
106
|
-
raise ("#{name} does not have #{key} configuration value set - this is mandatory") unless sync_config.key?(key)
|
107
|
-
end
|
108
|
-
end
|
109
|
-
|
110
64
|
def init_sync_processes(sync_name = nil)
|
111
65
|
return if @sync_processes.size != 0
|
112
66
|
if sync_name.nil?
|
@@ -199,5 +153,20 @@ module Docker_sync
|
|
199
153
|
sync_process.watch
|
200
154
|
}
|
201
155
|
end
|
156
|
+
|
157
|
+
private
|
158
|
+
|
159
|
+
def load_configuration(options)
|
160
|
+
config = options[:config] ||
|
161
|
+
DockerSync::ProjectConfig.new(
|
162
|
+
config_path: options[:config_path],
|
163
|
+
config_string: options[:config_string]
|
164
|
+
)
|
165
|
+
|
166
|
+
@config_global = config['options'] || {}
|
167
|
+
@config_syncs = config['syncs']
|
168
|
+
upgrade_syncs_config
|
169
|
+
end
|
170
|
+
|
202
171
|
end
|
203
172
|
end
|
@@ -31,34 +31,26 @@ module Docker_Sync
|
|
31
31
|
end
|
32
32
|
|
33
33
|
def set_sync_strategy
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
else
|
39
|
-
@sync_strategy = Docker_Sync::SyncStrategy::Unison.new(@sync_name, @options)
|
40
|
-
end
|
41
|
-
else
|
34
|
+
case @options['sync_strategy']
|
35
|
+
when 'rsync'
|
36
|
+
@sync_strategy = Docker_Sync::SyncStrategy::Rsync.new(@sync_name, @options)
|
37
|
+
when 'unison'
|
42
38
|
@sync_strategy = Docker_Sync::SyncStrategy::Unison.new(@sync_name, @options)
|
39
|
+
else
|
40
|
+
raise "Unknown sync_strategy #{@options['sync_strategy']}"
|
43
41
|
end
|
44
42
|
end
|
45
43
|
|
46
44
|
def set_watch_strategy
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
@watch_strategy = Docker_Sync::WatchStrategy::Unison.new(@sync_name, @options)
|
55
|
-
end
|
45
|
+
case @options['watch_strategy']
|
46
|
+
when 'fswatch'
|
47
|
+
@watch_strategy = Docker_Sync::WatchStrategy::Fswatch.new(@sync_name, @options)
|
48
|
+
when 'dummy'
|
49
|
+
@watch_strategy = Docker_Sync::WatchStrategy::Dummy.new(@sync_name, @options)
|
50
|
+
when 'unison'
|
51
|
+
@watch_strategy = Docker_Sync::WatchStrategy::Unison.new(@sync_name, @options)
|
56
52
|
else
|
57
|
-
|
58
|
-
@watch_strategy = Docker_Sync::WatchStrategy::Fswatch.new(@sync_name, @options)
|
59
|
-
else
|
60
|
-
@watch_strategy = Docker_Sync::WatchStrategy::Unison.new(@sync_name, @options)
|
61
|
-
end
|
53
|
+
raise "Unknown watch_strategy #{@options['watch_strategy']}"
|
62
54
|
end
|
63
55
|
end
|
64
56
|
|
@@ -1,5 +1,5 @@
|
|
1
1
|
require 'thor/shell'
|
2
|
-
require 'docker-sync/preconditions'
|
2
|
+
require 'docker-sync/preconditions/strategy'
|
3
3
|
require 'terminal-notifier'
|
4
4
|
|
5
5
|
module Docker_Sync
|
@@ -22,9 +22,9 @@ module Docker_Sync
|
|
22
22
|
end
|
23
23
|
|
24
24
|
begin
|
25
|
-
Preconditions::rsync_available
|
25
|
+
DockerSync::Preconditions::Strategy.instance.rsync_available
|
26
26
|
rescue Exception => e
|
27
|
-
say_status 'error', "#{@sync_name} has been configured to sync with rsync, but no rsync binary available", :red
|
27
|
+
say_status 'error', "#{@sync_name} has been configured to sync with rsync, but no rsync or fswatch binary available", :red
|
28
28
|
say_status 'error', e.message, :red
|
29
29
|
exit 1
|
30
30
|
end
|
@@ -1,5 +1,5 @@
|
|
1
1
|
require 'thor/shell'
|
2
|
-
require 'docker-sync/preconditions'
|
2
|
+
require 'docker-sync/preconditions/strategy'
|
3
3
|
require 'docker-sync/execution'
|
4
4
|
require 'open3'
|
5
5
|
require 'socket'
|
@@ -26,9 +26,7 @@ module Docker_Sync
|
|
26
26
|
@docker_image = 'eugenmayer/unison'
|
27
27
|
end
|
28
28
|
begin
|
29
|
-
Preconditions::unison_available
|
30
|
-
Preconditions::unox_available
|
31
|
-
Preconditions::macfsevents_available
|
29
|
+
DockerSync::Preconditions::Strategy.instance.unison_available
|
32
30
|
rescue Exception => e
|
33
31
|
say_status 'error', "#{@sync_name} has been configured to sync with unison, but no unison available", :red
|
34
32
|
say_status 'error', e.message, :red
|
@@ -217,7 +215,7 @@ module Docker_Sync
|
|
217
215
|
end
|
218
216
|
|
219
217
|
def stop_container
|
220
|
-
`docker ps | grep #{get_container_name} && docker stop #{get_container_name}`
|
218
|
+
`docker ps | grep #{get_container_name} && docker stop #{get_container_name} && docker wait #{get_container_name}`
|
221
219
|
end
|
222
220
|
|
223
221
|
def reset_container
|
@@ -1,6 +1,6 @@
|
|
1
1
|
require 'gem_update_checker'
|
2
2
|
require 'thor/actions'
|
3
|
-
require 'docker-sync/config'
|
3
|
+
require 'docker-sync/config/global_config'
|
4
4
|
|
5
5
|
class UpdateChecker
|
6
6
|
include Thor::Shell
|
@@ -8,7 +8,7 @@ class UpdateChecker
|
|
8
8
|
@newer_image_found
|
9
9
|
|
10
10
|
def initialize
|
11
|
-
@config =
|
11
|
+
@config = DockerSync::GlobalConfig.load
|
12
12
|
@newer_image_found = false
|
13
13
|
end
|
14
14
|
|
@@ -22,22 +22,28 @@ class UpdateChecker
|
|
22
22
|
end
|
23
23
|
|
24
24
|
# do not check the image if its the first run - since this it will be downloaded anyway
|
25
|
-
unless
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
25
|
+
unless @config.first_run?
|
26
|
+
unless has_internet?
|
27
|
+
check_unison_image
|
28
|
+
check_rsync_image
|
29
|
+
# stop if there was an update
|
30
|
+
if @newer_image_found
|
31
|
+
say_status 'warning', 'One or more images have been updated. Please use "docker-sync clean" before you start docker-sync again', :red
|
32
|
+
exit 0
|
33
|
+
end
|
33
34
|
end
|
34
|
-
|
35
35
|
end
|
36
36
|
|
37
37
|
check_and_warn(@config['update_enforce'])
|
38
38
|
end
|
39
39
|
|
40
|
+
def has_internet?
|
41
|
+
`ping -c1 -t 1 8.8.8.8 &2>1 /dev/null`
|
42
|
+
return $?.success?
|
43
|
+
end
|
44
|
+
|
40
45
|
def should_run
|
46
|
+
return false unless has_internet?
|
41
47
|
now = DateTime.now
|
42
48
|
last_check = DateTime.iso8601(@config['update_last_check'])
|
43
49
|
check_after_days = 2
|
@@ -86,10 +92,7 @@ class UpdateChecker
|
|
86
92
|
|
87
93
|
def check_and_warn(update_enforced = true)
|
88
94
|
# update the timestamp
|
89
|
-
|
90
|
-
@config['update_last_check'] = now.iso8601(9)
|
91
|
-
|
92
|
-
DockerSyncConfig::global_config_save(@config)
|
95
|
+
@config.update! 'update_last_check' => DateTime.now.iso8601(9)
|
93
96
|
|
94
97
|
check = docker_sync_update_check
|
95
98
|
if check.update_available
|
@@ -1,12 +1,12 @@
|
|
1
1
|
require 'gem_update_checker'
|
2
2
|
require 'thor/actions'
|
3
|
-
require 'docker-sync/config'
|
3
|
+
require 'docker-sync/config/global_config'
|
4
4
|
|
5
5
|
class UpgradeChecker
|
6
6
|
include Thor::Shell
|
7
7
|
@config
|
8
8
|
def initialize
|
9
|
-
@config =
|
9
|
+
@config = DockerSync::GlobalConfig.load
|
10
10
|
end
|
11
11
|
|
12
12
|
def run
|
@@ -17,13 +17,18 @@ class UpgradeChecker
|
|
17
17
|
end
|
18
18
|
|
19
19
|
def last_upgraded_version
|
20
|
-
@config['upgrade_status']
|
20
|
+
@config['upgrade_status']
|
21
21
|
end
|
22
22
|
|
23
23
|
def should_run
|
24
24
|
# get the update_status which is the version of the update hook which has been run already
|
25
25
|
upgrade_status = last_upgraded_version
|
26
|
-
if upgrade_status == ''
|
26
|
+
if upgrade_status == ''
|
27
|
+
@config.update! 'upgrade_status' => "#{UpgradeChecker.get_current_version}"
|
28
|
+
return
|
29
|
+
end
|
30
|
+
|
31
|
+
if Gem::Version.new(upgrade_status) < Gem::Version.new(UpgradeChecker.get_current_version) # thats how we compare the version
|
27
32
|
return true
|
28
33
|
end
|
29
34
|
|
@@ -59,9 +64,22 @@ class UpgradeChecker
|
|
59
64
|
end
|
60
65
|
end
|
61
66
|
|
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 docker-sync/unox/unison ! : \n\n_Please_ read :): https://github.com/EugenMayer/docker-sync/wiki/1.3-Upgrade-Guide\n\n", :red
|
69
|
+
|
70
|
+
cmd1 = 'rm -f /usr/loca/bin/unison-fsmonitor && gem uninstall docker-sync && brew tap eugenmayer/dockersync && brew install eugenmayer/dockersync/dockersync"'
|
71
|
+
Thor::Shell::Basic.new.say_status 'ok', "The installation progress of docker-sync 0.3.0 has changed, brew is now mandatory - you need to uninstall docker-sync/unox/unison ! : \n\n_Please_ read :): https://github.com/EugenMayer/docker-sync/wiki/1.3-Upgrade-Guide\n\n", :rwhite
|
72
|
+
|
73
|
+
if Thor::Shell::Basic.new.yes?('I will install reinstall docker-sync for you using the above command (y/N)')
|
74
|
+
system cmd1
|
75
|
+
else
|
76
|
+
raise('Please reinstall docker-sync yourself')
|
77
|
+
exit 1
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
62
81
|
|
63
82
|
# update the upgrade_status
|
64
|
-
@config
|
65
|
-
DockerSyncConfig::global_config_save(@config)
|
83
|
+
@config.update! 'upgrade_status' => "#{UpgradeChecker.get_current_version}"
|
66
84
|
end
|
67
|
-
end
|
85
|
+
end
|
@@ -1,6 +1,6 @@
|
|
1
1
|
require 'thor/shell'
|
2
2
|
require 'docker-sync/execution'
|
3
|
-
require 'docker-sync/preconditions'
|
3
|
+
require 'docker-sync/preconditions/strategy'
|
4
4
|
require 'pathname'
|
5
5
|
|
6
6
|
module Docker_Sync
|
@@ -19,7 +19,7 @@ module Docker_Sync
|
|
19
19
|
@events_to_watch = %w(AttributeModified Created Link MovedFrom MovedTo Renamed Removed Updated)
|
20
20
|
|
21
21
|
begin
|
22
|
-
Preconditions::fswatch_available
|
22
|
+
DockerSync::Preconditions::Strategy.instance.fswatch_available
|
23
23
|
rescue Exception => e
|
24
24
|
say_status 'error', e.message, :red
|
25
25
|
exit 1
|
data/tasks/daemon/daemon.thor
CHANGED
@@ -1,6 +1,6 @@
|
|
1
|
+
require 'docker-sync'
|
1
2
|
require 'docker-sync/sync_manager'
|
2
|
-
require 'docker-sync/
|
3
|
-
require 'docker-sync/preconditions'
|
3
|
+
require 'docker-sync/preconditions/strategy'
|
4
4
|
require 'docker-sync/update_check'
|
5
5
|
require 'docker-sync/upgrade_check'
|
6
6
|
require 'daemons'
|
data/tasks/stack/stack.thor
CHANGED
@@ -1,10 +1,12 @@
|
|
1
|
+
require 'docker-sync'
|
1
2
|
require 'docker-sync/sync_manager'
|
2
|
-
require 'docker-sync/
|
3
|
-
require 'docker-sync/preconditions'
|
3
|
+
require 'docker-sync/preconditions/strategy'
|
4
4
|
require 'docker-sync/update_check'
|
5
5
|
require 'docker-sync/upgrade_check'
|
6
6
|
require 'docker/compose'
|
7
7
|
require 'docker-sync/compose'
|
8
|
+
require 'docker-sync/config/project_config'
|
9
|
+
|
8
10
|
class Stack < Thor
|
9
11
|
class_option :config, :aliases => '-c', :default => nil, :type => :string, :desc => 'Path of the docker_sync config'
|
10
12
|
class_option :sync_name, :aliases => '-n', :type => :string, :desc => 'If given, only this sync configuration will be references/started/synced'
|
@@ -26,26 +28,16 @@ class Stack < Thor
|
|
26
28
|
upgrades.run
|
27
29
|
|
28
30
|
begin
|
29
|
-
|
31
|
+
config = DockerSync::ProjectConfig.new(config_path: options[:config])
|
32
|
+
DockerSync::Preconditions::Strategy.instance.check_all_preconditions(config)
|
30
33
|
rescue Exception => e
|
31
34
|
say_status 'error', e.message, :red
|
32
|
-
exit
|
33
|
-
end
|
34
|
-
|
35
|
-
if options[:config]
|
36
|
-
config_path = options[:config]
|
37
|
-
else
|
38
|
-
begin
|
39
|
-
config_path = DockerSyncConfig::project_config_path
|
40
|
-
rescue Exception => e
|
41
|
-
say_status 'error', e.message, :red
|
42
|
-
return
|
43
|
-
end
|
35
|
+
exit(1)
|
44
36
|
end
|
45
37
|
|
46
38
|
say_status 'note:', 'You can also run docker-sync in the background with docker-sync --daemon'
|
47
39
|
|
48
|
-
@sync_manager = Docker_sync::SyncManager.new(:
|
40
|
+
@sync_manager = Docker_sync::SyncManager.new(config: config)
|
49
41
|
@sync_manager.run(options[:sync_name])
|
50
42
|
global_options = @sync_manager.global_options
|
51
43
|
@compose_manager = ComposeManager.new(global_options)
|
@@ -77,23 +69,14 @@ class Stack < Thor
|
|
77
69
|
end
|
78
70
|
|
79
71
|
begin
|
80
|
-
|
72
|
+
config = DockerSync::ProjectConfig.new(config_path: options[:config])
|
73
|
+
DockerSync::Preconditions::Strategy.instance.check_all_preconditions(config)
|
81
74
|
rescue Exception => e
|
82
75
|
say_status 'error', e.message, :red
|
83
|
-
exit
|
76
|
+
exit(1)
|
84
77
|
end
|
85
78
|
|
86
|
-
|
87
|
-
config_path = options[:config]
|
88
|
-
else
|
89
|
-
begin
|
90
|
-
config_path = DockerSyncConfig::project_config_path
|
91
|
-
rescue Exception => e
|
92
|
-
say_status 'error', e.message, :red
|
93
|
-
return
|
94
|
-
end
|
95
|
-
end
|
96
|
-
@sync_manager = Docker_sync::SyncManager.new(:config_path => config_path)
|
79
|
+
@sync_manager = Docker_sync::SyncManager.new(config: config)
|
97
80
|
global_options = @sync_manager.global_options
|
98
81
|
# shutdown compose first
|
99
82
|
@compose_manager = ComposeManager.new(global_options)
|
@@ -105,4 +88,3 @@ class Stack < Thor
|
|
105
88
|
say_status 'success', 'Finished cleanup. Removed stopped, removed sync container and removed their volumes', :green
|
106
89
|
end
|
107
90
|
end
|
108
|
-
|