docker-sync 0.0.8 → 0.0.9
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 +4 -4
- data/Thorfile +3 -0
- data/VERSION +1 -0
- data/bin/docker-sync +3 -2
- data/lib/config.rb +23 -0
- data/lib/docker_sync/sync_strategy/rsync.rb +54 -35
- data/lib/docker_sync/sync_strategy/unison.rb +30 -18
- data/lib/update_check.rb +63 -0
- data/tasks/sync.thor +6 -0
- metadata +18 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7d1a5236f02cd1af95a2c5dd4f958653a2fb3509
|
4
|
+
data.tar.gz: f9eea32e9ed875dcd767bd6c7309c7fe0aa0ea4b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ca288151453629511d80e24436ea0efb072cb83ec559787249873b85932814f876e7bd66dad3ad07c288210a0d44612aef58507adbe27eab98afe9c1f5fd2ce1
|
7
|
+
data.tar.gz: 515f0cda8d12222f52c2cd2f63566b8ae5ca8148b76b898fd5e3517fcddbd925743b96d65c4755990b8be3f5ddc09849b1e9bc673d303612014e67192f1a6626
|
data/Thorfile
CHANGED
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
0.0.9
|
data/bin/docker-sync
CHANGED
@@ -1,8 +1,9 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
|
-
|
3
|
-
require "thor"
|
4
2
|
$LOAD_PATH.unshift File.expand_path('../../lib', __FILE__)
|
5
3
|
|
4
|
+
require 'thor'
|
5
|
+
require 'update_check'
|
6
|
+
DO_UPDATE_CHECK=true
|
6
7
|
thor = File.expand_path('../../tasks', __FILE__)
|
7
8
|
Dir.glob(File.join(thor, '/**/*.thor')).each { |taskfile|
|
8
9
|
load taskfile
|
data/lib/config.rb
CHANGED
@@ -1,8 +1,31 @@
|
|
1
1
|
require 'pp'
|
2
2
|
require 'pathname'
|
3
|
+
require 'yaml'
|
3
4
|
# this has basically completely reused from Thor::runner.rb - thank you!
|
4
5
|
|
5
6
|
module DockerSyncConfig
|
7
|
+
def global_config_location
|
8
|
+
return File.expand_path('~/.docker-sync-global.yml')
|
9
|
+
end
|
10
|
+
|
11
|
+
def global_config
|
12
|
+
global_config_path = global_config_location
|
13
|
+
date = DateTime.new(2001, 1, 1) #paste
|
14
|
+
defaults = {'update_check'=>true, 'update_last_check' => date.iso8601(9), 'update_enforce' => true}
|
15
|
+
if File.exist?(global_config_path)
|
16
|
+
config = YAML.load_file(global_config_path)
|
17
|
+
config = defaults.merge(config)
|
18
|
+
return config
|
19
|
+
else
|
20
|
+
return defaults
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
def global_config_save(config)
|
25
|
+
global_config_path = global_config_location
|
26
|
+
File.open(global_config_path, 'w') {|f| f.write config.to_yaml }
|
27
|
+
end
|
28
|
+
|
6
29
|
def find_config
|
7
30
|
files = find_config_file
|
8
31
|
if files.length > 0
|
@@ -63,63 +63,82 @@ module Docker_Sync
|
|
63
63
|
return args
|
64
64
|
end
|
65
65
|
|
66
|
+
def get_container_name
|
67
|
+
return "#{@sync_name}"
|
68
|
+
end
|
69
|
+
|
70
|
+
def get_volume_name
|
71
|
+
return @sync_name
|
72
|
+
end
|
73
|
+
|
66
74
|
# starts a rsync docker container listening on the specific port
|
67
75
|
# this container exposes a named volume and is on one side used as the rsync-endpoint for the
|
68
76
|
# local rsync command, on the other side the volume is mounted into the app-container to share the code / content
|
69
77
|
def start_container
|
70
78
|
say_status 'ok', 'Starting rsync', :white
|
71
|
-
|
79
|
+
container_name = get_container_name
|
80
|
+
volume_name = get_volume_name
|
81
|
+
running = `docker ps --filter 'status=running' --filter 'name=#{container_name}' | grep #{container_name}`
|
72
82
|
if running == '' # container is yet not running
|
73
|
-
say_status 'ok', "#{
|
74
|
-
exists = `docker ps --filter "status=exited" --filter "name=#{
|
83
|
+
say_status 'ok', "#{container_name} container not running", :white if @options['verbose']
|
84
|
+
exists = `docker ps --filter "status=exited" --filter "name=#{container_name}" | grep #{container_name}`
|
75
85
|
if exists == '' # container has yet not been created
|
76
|
-
say_status 'ok', "creating #{
|
77
|
-
|
78
|
-
user_mapping =
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
user_mapping = "#{user_mapping} -e OWNERID=#{@options['sync_userid']}"
|
83
|
-
end
|
84
|
-
elsif @options.key?('sync_userid')
|
85
|
-
raise("#{@sync_name}: You have set a sync_userid but no sync_user - you need to set both")
|
86
|
-
end
|
87
|
-
|
88
|
-
group_mapping = ''
|
89
|
-
if @options.key?('sync_group')
|
90
|
-
group_mapping = "-e GROUP=#{@options['sync_group']}"
|
91
|
-
if @options.key?('sync_groupid')
|
92
|
-
group_mapping = "#{group_mapping} -e GROUPID=#{@options['sync_groupid']}"
|
93
|
-
end
|
94
|
-
elsif @options.key?('sync_groupid')
|
95
|
-
raise("#{@sync_name}: You have set a sync_groupid but no sync_group - you need to set both")
|
96
|
-
end
|
97
|
-
|
98
|
-
cmd = "docker run -p '#{@options['sync_host_port']}:873' -v #{@sync_name}:#{@options['dest']} #{user_mapping} #{group_mapping} -e VOLUME=#{@options['dest']} --name #{@sync_name} -d eugenmayer/rsync"
|
86
|
+
say_status 'ok', "creating #{container_name} container", :white if @options['verbose']
|
87
|
+
|
88
|
+
user_mapping = get_user_mapping
|
89
|
+
group_mapping = get_group_mapping
|
90
|
+
|
91
|
+
cmd = "docker run -p '#{@options['sync_host_port']}:873' -v #{volume_name}:#{@options['dest']} #{user_mapping} #{group_mapping} -e VOLUME=#{@options['dest']} --name #{container_name} -d eugenmayer/rsync"
|
99
92
|
else # container already created, just start / reuse it
|
100
|
-
say_status 'ok', "starting #{
|
101
|
-
cmd = "docker start #{
|
93
|
+
say_status 'ok', "starting #{container_name} container", :white if @options['verbose']
|
94
|
+
cmd = "docker start #{container_name}"
|
102
95
|
end
|
103
96
|
say_status 'command', cmd, :white if @options['verbose']
|
104
97
|
`#{cmd}` || raise('Start failed')
|
105
98
|
else
|
106
|
-
say_status 'ok', "#{
|
99
|
+
say_status 'ok', "#{container_name} container still running", :blue if @options['verbose']
|
107
100
|
end
|
108
|
-
say_status 'ok', "starting initial #{@
|
101
|
+
say_status 'ok', "#{container_name}: starting initial sync of #{@options['src']}", :white if @options['verbose']
|
109
102
|
# this sleep is needed since the container could be not started
|
110
103
|
sleep 1
|
111
104
|
sync
|
112
105
|
say_status 'success', 'Rsync server started', :green
|
113
106
|
end
|
114
107
|
|
108
|
+
def get_user_mapping
|
109
|
+
user_mapping = ''
|
110
|
+
if @options.key?('sync_user')
|
111
|
+
user_mapping = "-e OWNER=#{@options['sync_user']}"
|
112
|
+
if @options.key?('sync_userid')
|
113
|
+
user_mapping = "#{user_mapping} -e OWNERID=#{@options['sync_userid']}"
|
114
|
+
end
|
115
|
+
elsif @options.key?('sync_userid')
|
116
|
+
raise("#{get_container_name}: You have set a sync_userid but no sync_user - you need to set both")
|
117
|
+
end
|
118
|
+
return user_mapping
|
119
|
+
end
|
120
|
+
|
121
|
+
def get_group_mapping
|
122
|
+
group_mapping = ''
|
123
|
+
if @options.key?('sync_group')
|
124
|
+
group_mapping = "-e GROUP=#{@options['sync_group']}"
|
125
|
+
if @options.key?('sync_groupid')
|
126
|
+
group_mapping = "#{group_mapping} -e GROUPID=#{@options['sync_groupid']}"
|
127
|
+
end
|
128
|
+
elsif @options.key?('sync_groupid')
|
129
|
+
raise("#{get_container_name}: You have set a sync_groupid but no sync_group - you need to set both")
|
130
|
+
end
|
131
|
+
return group_mapping
|
132
|
+
end
|
133
|
+
|
115
134
|
def stop_container
|
116
|
-
`docker stop #{
|
135
|
+
`docker stop #{get_container_name}`
|
117
136
|
end
|
118
137
|
|
119
138
|
def reset_container
|
120
139
|
stop_container
|
121
|
-
`docker rm #{
|
122
|
-
`docker volume rm #{
|
140
|
+
`docker rm #{get_container_name}`
|
141
|
+
`docker volume rm #{get_volume_name}`
|
123
142
|
end
|
124
143
|
|
125
144
|
def clean
|
@@ -127,11 +146,11 @@ module Docker_Sync
|
|
127
146
|
end
|
128
147
|
|
129
148
|
def stop
|
130
|
-
say_status 'ok', "Stopping sync container #{
|
149
|
+
say_status 'ok', "Stopping sync container #{get_container_name}"
|
131
150
|
begin
|
132
151
|
stop_container
|
133
152
|
rescue Exception => e
|
134
|
-
say_status 'error', "Stopping failed of #{
|
153
|
+
say_status 'error', "Stopping failed of #{get_container_name}:", :red
|
135
154
|
puts e.message
|
136
155
|
end
|
137
156
|
end
|
@@ -39,14 +39,14 @@ module Docker_Sync
|
|
39
39
|
|
40
40
|
say_status 'command', cmd, :white if @options['verbose']
|
41
41
|
|
42
|
-
Open3.
|
43
|
-
if
|
42
|
+
stdout, stderr, exit_status = Open3.capture3(cmd)
|
43
|
+
if not exit_status.success?
|
44
44
|
say_status 'error', "Error starting sync, exit code #{$?.exitstatus}", :red
|
45
|
-
say_status 'message',
|
45
|
+
say_status 'message', stderr
|
46
46
|
else
|
47
47
|
say_status 'ok', "Synced #{@options['src']}", :white
|
48
48
|
if @options['verbose']
|
49
|
-
say_status 'output',
|
49
|
+
say_status 'output', stdout
|
50
50
|
end
|
51
51
|
end
|
52
52
|
end
|
@@ -64,6 +64,7 @@ module Docker_Sync
|
|
64
64
|
args.push('-batch')
|
65
65
|
args.push(@options['sync_args']) if @options.key?('sync_args')
|
66
66
|
args.push("socket://#{@options['sync_host_ip']}:#{@options['sync_host_port']}/")
|
67
|
+
args.push('-debug verbose') if @options['verbose']
|
67
68
|
if @options.key?('sync_user') || @options.key?('sync_group') || @options.key?('sync_groupid') || @options.key?('sync_userid')
|
68
69
|
raise('Unison does not support sync_user, sync_group, sync_groupid or sync_userid - please use rsync if you need that')
|
69
70
|
end
|
@@ -72,37 +73,48 @@ module Docker_Sync
|
|
72
73
|
|
73
74
|
def start_container
|
74
75
|
say_status 'ok', 'Starting unison', :white
|
75
|
-
|
76
|
+
container_name = get_container_name
|
77
|
+
volume_name = get_volume_name
|
78
|
+
|
79
|
+
running = `docker ps --filter 'status=running' --filter 'name=#{container_name}' | grep #{container_name}`
|
76
80
|
if running == ''
|
77
|
-
say_status 'ok', "#{
|
78
|
-
exists = `docker ps --filter "status=exited" --filter "name=#{
|
81
|
+
say_status 'ok', "#{container_name} container not running", :white if @options['verbose']
|
82
|
+
exists = `docker ps --filter "status=exited" --filter "name=#{container_name}" | grep #{container_name}`
|
79
83
|
if exists == ''
|
80
|
-
say_status 'ok', "creating #{
|
81
|
-
cmd = "docker run -p '#{@options['sync_host_port']}:#{UNISON_CONTAINER_PORT}' -v #{
|
84
|
+
say_status 'ok', "creating #{container_name} container", :white if @options['verbose']
|
85
|
+
cmd = "docker run -p '#{@options['sync_host_port']}:#{UNISON_CONTAINER_PORT}' -v #{volume_name}:#{@options['dest']} -e UNISON_VERSION=#{UNISON_VERSION} -e UNISON_WORKING_DIR=#{@options['dest']} --name #{container_name} -d #{UNISON_IMAGE}"
|
82
86
|
else
|
83
|
-
say_status 'ok', "starting #{
|
84
|
-
cmd = "docker start #{
|
87
|
+
say_status 'ok', "starting #{container_name} container", :white if @options['verbose']
|
88
|
+
cmd = "docker start #{container_name}"
|
85
89
|
end
|
86
90
|
say_status 'command', cmd, :white if @options['verbose']
|
87
91
|
`#{cmd}` || raise('Start failed')
|
88
92
|
else
|
89
|
-
say_status 'ok', "#{
|
93
|
+
say_status 'ok', "#{container_name} container still running", :blue
|
90
94
|
end
|
91
|
-
say_status 'ok', "starting initial #{
|
95
|
+
say_status 'ok', "starting initial #{container_name} of src", :white if @options['verbose']
|
92
96
|
# this sleep is needed since the container could be not started
|
93
97
|
sleep 1
|
94
98
|
sync
|
95
99
|
say_status 'success', 'Unison server started', :green
|
96
100
|
end
|
97
101
|
|
102
|
+
def get_container_name
|
103
|
+
return "#{@sync_name}"
|
104
|
+
end
|
105
|
+
|
106
|
+
def get_volume_name
|
107
|
+
return @sync_name
|
108
|
+
end
|
109
|
+
|
98
110
|
def stop_container
|
99
|
-
`docker stop #{
|
111
|
+
`docker stop #{get_container_name}`
|
100
112
|
end
|
101
113
|
|
102
114
|
def reset_container
|
103
115
|
stop_container
|
104
|
-
`docker rm #{
|
105
|
-
`docker volume rm #{
|
116
|
+
`docker rm #{get_container_name}`
|
117
|
+
`docker volume rm #{get_volume_name}`
|
106
118
|
end
|
107
119
|
|
108
120
|
def clean
|
@@ -110,11 +122,11 @@ module Docker_Sync
|
|
110
122
|
end
|
111
123
|
|
112
124
|
def stop
|
113
|
-
say_status 'ok', "Stopping sync container #{
|
125
|
+
say_status 'ok', "Stopping sync container #{get_container_name}"
|
114
126
|
begin
|
115
127
|
stop_container
|
116
128
|
rescue Exception => e
|
117
|
-
say_status 'error', "Stopping failed of #{
|
129
|
+
say_status 'error', "Stopping failed of #{get_container_name}:", :red
|
118
130
|
puts e.message
|
119
131
|
end
|
120
132
|
end
|
data/lib/update_check.rb
ADDED
@@ -0,0 +1,63 @@
|
|
1
|
+
require 'gem_update_checker'
|
2
|
+
require 'thor/actions'
|
3
|
+
require 'config'
|
4
|
+
|
5
|
+
class UpdateChecker
|
6
|
+
include Thor::Shell
|
7
|
+
include DockerSyncConfig
|
8
|
+
@config
|
9
|
+
def initialize
|
10
|
+
@config = global_config
|
11
|
+
end
|
12
|
+
|
13
|
+
def run
|
14
|
+
unless @config['update_check']
|
15
|
+
say_status 'hint','Skipping up-to-date check since it has been disabled in yout ~/.docker-sync-global.yml configuration',:yellow
|
16
|
+
return
|
17
|
+
end
|
18
|
+
unless should_run
|
19
|
+
return
|
20
|
+
end
|
21
|
+
check_and_warn(@config['update_enforce'])
|
22
|
+
end
|
23
|
+
|
24
|
+
def should_run
|
25
|
+
now = DateTime.now
|
26
|
+
last_check = DateTime.iso8601(@config['update_last_check'])
|
27
|
+
check_after_days = 2
|
28
|
+
if now - last_check > check_after_days
|
29
|
+
return true
|
30
|
+
end
|
31
|
+
|
32
|
+
return false
|
33
|
+
end
|
34
|
+
|
35
|
+
def get_current_version
|
36
|
+
path = File.expand_path('../../', __FILE__)
|
37
|
+
return File.read("#{path}/VERSION")
|
38
|
+
end
|
39
|
+
|
40
|
+
def docker_sync_update_check
|
41
|
+
gem_name = 'docker-sync'
|
42
|
+
current_version = get_current_version
|
43
|
+
checker = GemUpdateChecker::Client.new(gem_name, current_version)
|
44
|
+
return checker
|
45
|
+
end
|
46
|
+
|
47
|
+
def check_and_warn(update_enforced = true)
|
48
|
+
# update the timestamp
|
49
|
+
now = DateTime.now
|
50
|
+
@config['update_last_check'] = now.iso8601(9)
|
51
|
+
global_config_save(@config)
|
52
|
+
|
53
|
+
check = docker_sync_update_check
|
54
|
+
if check.update_available
|
55
|
+
say_status 'warning',"There is an update (#{check.latest_version}) available (current version #{check.current_version}). Please update before you continue",:yellow
|
56
|
+
if yes?("Shall i update docker-sync to #{check.latest_version} for you?")
|
57
|
+
system('gem update docker-sync')
|
58
|
+
else
|
59
|
+
exit 1 if update_enforced
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
data/tasks/sync.thor
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
require 'docker_sync/sync_manager'
|
2
2
|
require 'config'
|
3
3
|
require 'preconditions'
|
4
|
+
require 'update_check'
|
4
5
|
|
5
6
|
class Sync < Thor
|
6
7
|
include DockerSyncConfig
|
@@ -11,6 +12,10 @@ class Sync < Thor
|
|
11
12
|
|
12
13
|
desc 'start', 'Start all sync configurations in this project'
|
13
14
|
def start
|
15
|
+
# do run update check in the start command only
|
16
|
+
updates = UpdateChecker.new
|
17
|
+
updates.run
|
18
|
+
|
14
19
|
begin
|
15
20
|
check_all_preconditions
|
16
21
|
rescue Exception => e
|
@@ -82,6 +87,7 @@ class Sync < Thor
|
|
82
87
|
desc 'list', 'List all sync-points of the project configuration path'
|
83
88
|
method_option :verbose, :default => false, :type => :boolean, :desc => 'Verbose output'
|
84
89
|
def list
|
90
|
+
pp Gem.configuration
|
85
91
|
begin
|
86
92
|
check_all_preconditions
|
87
93
|
rescue Exception => e
|
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.0.
|
4
|
+
version: 0.0.9
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Eugen Mayer
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-07-
|
11
|
+
date: 2016-07-10 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: thor
|
@@ -24,6 +24,20 @@ dependencies:
|
|
24
24
|
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: gem_update_checker
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
27
41
|
description: Sync your code live to docker-containers without losing any performance
|
28
42
|
on OSX
|
29
43
|
email: eugen.mayer@kontextwork.de
|
@@ -33,6 +47,7 @@ extensions: []
|
|
33
47
|
extra_rdoc_files: []
|
34
48
|
files:
|
35
49
|
- Thorfile
|
50
|
+
- VERSION
|
36
51
|
- bin/docker-sync
|
37
52
|
- lib/config.rb
|
38
53
|
- lib/docker_sync/sync_manager.rb
|
@@ -42,6 +57,7 @@ files:
|
|
42
57
|
- lib/docker_sync/watch_strategy/fswatch.rb
|
43
58
|
- lib/execution.rb
|
44
59
|
- lib/preconditions.rb
|
60
|
+
- lib/update_check.rb
|
45
61
|
- tasks/sync.thor
|
46
62
|
homepage: https://github.com/EugenMayer/docker_sync
|
47
63
|
licenses:
|