docker-sync 0.7.1 → 1.0.1

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
  SHA256:
3
- metadata.gz: d08392b2115f84c6dd7d37cb28232b4193523d4bb8e45860a9be061cefd88fb5
4
- data.tar.gz: 18626e0ea9919d701dee2787d32457314bbe4abee642ce26ce23c3a02b5e5145
3
+ metadata.gz: 440a1277f902234557ce07713930f28cf69e95fa6ff77ee095128fe407b2a6da
4
+ data.tar.gz: 65643b530ee3cfa703fa03140d07545a459f0e6414ccc4ef1fbb4bcc9485bb79
5
5
  SHA512:
6
- metadata.gz: bf0b3f26f0eb4f2d99b95336e13669e4abef9db285b240011660d5d19bd89485b4940f523adbd1d8bbb6b412af3e251a8e21c4e4d9cd40b43676a897452bcdc5
7
- data.tar.gz: dbc9ec63c1b187f181e9bf180507cb724a7e54010dc145e80a882f020eab19051400496f72e0b8c5cd078fa8130bd29fce74ab6a188d6162d012dfb70a6e3823
6
+ metadata.gz: 1bd8e762ee2d4eaff553501371169439c5fb511670a4a6937110d16965c9da0bfdac7ec0298a8b2dc2f8548333fd120c1174986320ce314dcfcd86ffc03b3329
7
+ data.tar.gz: f8528c8f0747cafb57ae66f638e78128ee561adeb77b7c9d3f8cf439fb0324f5637cca4dd48d6916952bc27baa35e6fcf9e14a7da7ac888211d3670dd31cf1c0
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.7.1
1
+ 1.0.1
@@ -0,0 +1,126 @@
1
+ begin
2
+ require 'pty'
3
+ rescue LoadError
4
+ # for Windows support, tolerate a missing PTY module
5
+ end
6
+
7
+ module DockerSync
8
+ # based on `Backticks::Command` from `Backticks` gem
9
+ class Command
10
+ FOREVER = 86_400 * 365
11
+ CHUNK = 1_024
12
+
13
+ # @return [Integer] child process ID
14
+ attr_reader :pid
15
+
16
+ # @return [nil,Process::Status] result of command if it has ended; nil if still running
17
+ attr_reader :status
18
+
19
+ # @return [String] all input that has been captured so far
20
+ attr_reader :captured_input
21
+
22
+ # @return [String] all output that has been captured so far
23
+ attr_reader :captured_output
24
+
25
+ # @return [String] all output to stderr that has been captured so far
26
+ attr_reader :captured_error
27
+
28
+ # Run a command. The parameters are same as `Kernel#spawn`.
29
+ #
30
+ # Usage:
31
+ # run('docker-compose', '--file=joe.yml', 'up', '-d', 'mysvc')
32
+ def self.run(*argv, dir: nil)
33
+ nopty = !defined?(PTY)
34
+
35
+ stdin_r, stdin = nopty ? IO.pipe : PTY.open
36
+ stdout, stdout_w = nopty ? IO.pipe : PTY.open
37
+ stderr, stderr_w = IO.pipe
38
+
39
+ chdir = dir || Dir.pwd
40
+ pid = spawn(*argv, in: stdin_r, out: stdout_w, err: stderr_w, chdir: chdir)
41
+
42
+ stdin_r.close
43
+ stdout_w.close
44
+ stderr_w.close
45
+
46
+ self.new(pid, stdin, stdout, stderr)
47
+ end
48
+
49
+ def initialize(pid, stdin, stdout, stderr)
50
+ @pid = pid
51
+ @stdin = stdin
52
+ @stdout = stdout
53
+ @stderr = stderr
54
+ @status = nil
55
+
56
+ @captured_input = String.new(encoding: Encoding::BINARY)
57
+ @captured_output = String.new(encoding: Encoding::BINARY)
58
+ @captured_error = String.new(encoding: Encoding::BINARY)
59
+ end
60
+
61
+ def success?
62
+ status.success?
63
+ end
64
+
65
+ def join(limit = FOREVER)
66
+ return self if @status
67
+
68
+ tf = Time.now + limit
69
+ until (t = Time.now) >= tf
70
+ capture(tf - t)
71
+ res = Process.waitpid(@pid, Process::WNOHANG)
72
+ if res
73
+ @status = $?
74
+ return self
75
+ end
76
+ end
77
+
78
+ nil
79
+ end
80
+
81
+ private
82
+
83
+ def capture(limit)
84
+ streams = [@stdout, @stderr]
85
+ streams << STDIN if STDIN.tty?
86
+
87
+ ready, = IO.select(streams, [], [], limit)
88
+
89
+ # proxy STDIN to child's stdin
90
+ if ready && ready.include?(STDIN)
91
+ data = STDIN.readpartial(CHUNK) rescue nil
92
+ if data
93
+ @captured_input << data
94
+ @stdin.write(data)
95
+ else
96
+ # our own STDIN got closed; proxy this fact to the child
97
+ @stdin.close unless @stdin.closed?
98
+ end
99
+ end
100
+
101
+ # capture child's stdout and maybe proxy to STDOUT
102
+ if ready && ready.include?(@stdout)
103
+ data = @stdout.readpartial(CHUNK) rescue nil
104
+ if data
105
+ @captured_output << data
106
+ STDOUT.write(data)
107
+ fresh_output = data
108
+ end
109
+ end
110
+
111
+ # capture child's stderr and maybe proxy to STDERR
112
+ if ready && ready.include?(@stderr)
113
+ data = @stderr.readpartial(CHUNK) rescue nil
114
+ if data
115
+ @captured_error << data
116
+ STDERR.write(data)
117
+ end
118
+ end
119
+ fresh_output
120
+ rescue Interrupt
121
+ # Proxy Ctrl+C to the child
122
+ Process.kill('INT', @pid) rescue nil
123
+ raise
124
+ end
125
+ end
126
+ end
@@ -1,5 +1,6 @@
1
- require 'docker/compose'
2
1
  require 'pp'
2
+ require 'docker-sync/docker_compose_session'
3
+
3
4
  class ComposeManager
4
5
  include Thor::Shell
5
6
  @compose_session
@@ -30,7 +31,7 @@ class ComposeManager
30
31
  compose_files.push compose_dev_path
31
32
  end
32
33
  end
33
- @compose_session = Docker::Compose::Session.new(dir:'./', :file => compose_files)
34
+ @compose_session = DockerSync::DockerComposeSession.new(dir: './', files: compose_files)
34
35
  end
35
36
 
36
37
  def run
@@ -5,7 +5,11 @@ module DockerSync
5
5
  def self.docker_for_mac?
6
6
  return false unless Environment.mac?
7
7
  return @docker_for_mac if defined? @docker_for_mac
8
- @docker_for_mac = Environment.system('pgrep -q com.docker.hyperkit')
8
+
9
+ # com.docker.hyperkit for old virtualization engine
10
+ # com.docker.virtualization for new virtualization engine
11
+ # see https://docs.docker.com/desktop/mac/#enable-the-new-apple-virtualization-framework
12
+ @docker_for_mac = Environment.system('pgrep -q com.docker.hyperkit') || Environment.system('pgrep -q com.docker.virtualization')
9
13
  end
10
14
 
11
15
  def self.docker_toolbox?
@@ -0,0 +1,46 @@
1
+ require 'docker-sync/command'
2
+
3
+ module DockerSync
4
+ # based on `Docker::Compose::Compose` from `docker-compose` gem
5
+ class DockerComposeSession
6
+ def initialize(dir: nil, files: nil)
7
+ @dir = dir
8
+ @files = files || [] # Array[String]
9
+ @last_command = nil
10
+ end
11
+
12
+ def up(build: false)
13
+ args = []
14
+ args << '--build' if build
15
+
16
+ run!('up', *args)
17
+ end
18
+
19
+ def stop
20
+ run!('stop')
21
+ end
22
+
23
+ def down
24
+ run!('down')
25
+ end
26
+
27
+ private
28
+
29
+ def run!(*args)
30
+ # file_args and args should be Array of String
31
+ file_args = @files.map { |file| "--file=#{file}" }
32
+
33
+ @last_command = Command.run('docker-compose', *file_args, *args, dir: @dir).join
34
+ status = @last_command.status
35
+ out = @last_command.captured_output
36
+ err = @last_command.captured_error
37
+ unless status.success?
38
+ desc = (out + err).strip.lines.first || '(no output)'
39
+ message = format("'%s' failed with status %s: %s", args.first, status.to_s, desc)
40
+ raise message
41
+ end
42
+
43
+ out
44
+ end
45
+ end
46
+ end
@@ -21,5 +21,9 @@ module DockerSync
21
21
  def self.system(cmd)
22
22
  defined?(Bundler) ? Bundler.unbundled_system(cmd) : Kernel.system(cmd)
23
23
  end
24
+
25
+ def self.default_ignores()
26
+ ['.docker-sync/daemon.log', '.docker-sync/daemon.pid']
27
+ end
24
28
  end
25
29
  end
@@ -20,11 +20,7 @@ module DockerSync
20
20
  @options = options
21
21
  @sync_name = sync_name
22
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:2.51.3-4.12.0-AMD64'
27
- end
23
+ @docker_image = @options.key?('image') ? @options['image'] : 'ghcr.io/eugenmayer/unison:2.52.1-4.12.0'
28
24
 
29
25
  begin
30
26
  Dependencies::Docker.ensure!
@@ -187,7 +183,7 @@ module DockerSync
187
183
  end
188
184
 
189
185
  unless @options['sync_excludes'].nil?
190
- expanded_ignore_strings = @options['sync_excludes'].map do |pattern|
186
+ expanded_ignore_strings = @options['sync_excludes'].append(Environment.default_ignores).flatten!.map do |pattern|
191
187
  if exclude_type == 'none'
192
188
  # the ignore type like Name / Path are part of the pattern
193
189
  ignore_string = "#{pattern}"
@@ -61,8 +61,10 @@ module DockerSync
61
61
 
62
62
  def sync_options
63
63
  args = []
64
- unless @options['sync_excludes'].nil?
65
- args = @options['sync_excludes'].map { |pattern| "--exclude='#{pattern}'" } + args
64
+ excludes_list = @options['sync_excludes'].append(Environment.default_ignores).flatten!
65
+
66
+ unless excludes_list.nil?
67
+ args = excludes_list.map { |pattern| "--exclude='#{pattern}'" } + args
66
68
  end
67
69
  args.push('-ap')
68
70
  args.push(@options['sync_args']) if @options.key?('sync_args')
@@ -19,11 +19,7 @@ module DockerSync
19
19
  @options = options
20
20
  @sync_name = sync_name
21
21
  # if a custom image is set, apply it
22
- @docker_image = if @options.key?('image')
23
- @options['image']
24
- else
25
- 'eugenmayer/unison:2.51.3-4.12.0-AMD64'
26
- end
22
+ @docker_image = @options.key?('image') ? @options['image'] : 'ghcr.io/eugenmayer/unison:2.52.1-4.12.0'
27
23
  begin
28
24
  Dependencies::Unison.ensure!
29
25
  Dependencies::Unox.ensure! if Environment.mac?
@@ -106,7 +102,7 @@ module DockerSync
106
102
  exclude_type = @options['sync_excludes_type'] unless @options['sync_excludes_type'].nil?
107
103
 
108
104
  unless @options['sync_excludes'].nil?
109
- expanded_ignore_strings = @options['sync_excludes'].map do |pattern|
105
+ expanded_ignore_strings = @options['sync_excludes'].append(Environment.default_ignores).flatten!.map do |pattern|
110
106
  ignore_string = if exclude_type == 'none'
111
107
  # the ignore type like Name / Path are part of the pattern
112
108
  pattern.to_s
@@ -139,6 +135,8 @@ module DockerSync
139
135
 
140
136
  # cares about conflict resolution
141
137
  def sync_prefer
138
+ sync_host_port = get_host_port(get_container_name, UNISON_CONTAINER_PORT)
139
+
142
140
  case @options.fetch('sync_prefer', 'default')
143
141
  when 'default' then "-prefer '#{@options['src']}' -copyonconflict" # thats our default, if nothing is set
144
142
  when 'src' then "-prefer '#{@options['src']}'"
@@ -212,7 +210,7 @@ module DockerSync
212
210
  say_status 'ok', "starting initial sync of #{container_name}", :white if @options['verbose']
213
211
  # wait until container is started, then sync:
214
212
  sync_host_port = get_host_port(get_container_name, UNISON_CONTAINER_PORT)
215
- cmd = "unison -testserver #{@options['src']} \"socket://#{@options['sync_host_ip']}:#{sync_host_port}\""
213
+ cmd = "unison -testserver \"#{@options['src']}\" \"socket://#{@options['sync_host_ip']}:#{sync_host_port}\""
216
214
  say_status 'command', cmd, :white if @options['verbose']
217
215
  attempt = 0
218
216
  max_attempt = @options['max_attempt'] || 5
@@ -4,8 +4,6 @@ require 'docker-sync/config/global_config'
4
4
 
5
5
  class UpdateChecker
6
6
  include Thor::Shell
7
- @config
8
- @newer_image_found
9
7
 
10
8
  def initialize
11
9
  @config = DockerSync::GlobalConfig.load
@@ -5,7 +5,6 @@ require 'docker-sync/update_check'
5
5
 
6
6
  class UpgradeChecker
7
7
  include Thor::Shell
8
- @config
9
8
  def initialize
10
9
  @config = DockerSync::GlobalConfig.load
11
10
  end
@@ -2,7 +2,6 @@ require 'docker-sync'
2
2
  require 'docker-sync/sync_manager'
3
3
  require 'docker-sync/update_check'
4
4
  require 'docker-sync/upgrade_check'
5
- require 'docker/compose'
6
5
  require 'docker-sync/compose'
7
6
  require 'docker-sync/config/project_config'
8
7
 
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.7.1
4
+ version: 1.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Eugen Mayer
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-12-16 00:00:00.000000000 Z
11
+ date: 2022-09-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: thor
@@ -16,20 +16,20 @@ dependencies:
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: '1.0'
19
+ version: '1.2'
20
20
  - - ">="
21
21
  - !ruby/object:Gem::Version
22
- version: 1.0.0
22
+ version: 1.2.0
23
23
  type: :runtime
24
24
  prerelease: false
25
25
  version_requirements: !ruby/object:Gem::Requirement
26
26
  requirements:
27
27
  - - "~>"
28
28
  - !ruby/object:Gem::Version
29
- version: '1.0'
29
+ version: '1.2'
30
30
  - - ">="
31
31
  - !ruby/object:Gem::Version
32
- version: 1.0.0
32
+ version: 1.2.0
33
33
  - !ruby/object:Gem::Dependency
34
34
  name: gem_update_checker
35
35
  requirement: !ruby/object:Gem::Requirement
@@ -50,26 +50,6 @@ dependencies:
50
50
  - - ">="
51
51
  - !ruby/object:Gem::Version
52
52
  version: 0.2.0
53
- - !ruby/object:Gem::Dependency
54
- name: docker-compose
55
- requirement: !ruby/object:Gem::Requirement
56
- requirements:
57
- - - "~>"
58
- - !ruby/object:Gem::Version
59
- version: '1.1'
60
- - - ">="
61
- - !ruby/object:Gem::Version
62
- version: 1.1.7
63
- type: :runtime
64
- prerelease: false
65
- version_requirements: !ruby/object:Gem::Requirement
66
- requirements:
67
- - - "~>"
68
- - !ruby/object:Gem::Version
69
- version: '1.1'
70
- - - ">="
71
- - !ruby/object:Gem::Version
72
- version: 1.1.7
73
53
  - !ruby/object:Gem::Dependency
74
54
  name: terminal-notifier
75
55
  requirement: !ruby/object:Gem::Requirement
@@ -90,54 +70,54 @@ dependencies:
90
70
  requirements:
91
71
  - - "~>"
92
72
  - !ruby/object:Gem::Version
93
- version: '2.1'
73
+ version: '2.8'
94
74
  - - ">="
95
75
  - !ruby/object:Gem::Version
96
- version: 2.1.1
76
+ version: 2.8.1
97
77
  type: :runtime
98
78
  prerelease: false
99
79
  version_requirements: !ruby/object:Gem::Requirement
100
80
  requirements:
101
81
  - - "~>"
102
82
  - !ruby/object:Gem::Version
103
- version: '2.1'
83
+ version: '2.8'
104
84
  - - ">="
105
85
  - !ruby/object:Gem::Version
106
- version: 2.1.1
86
+ version: 2.8.1
107
87
  - !ruby/object:Gem::Dependency
108
88
  name: daemons
109
89
  requirement: !ruby/object:Gem::Requirement
110
90
  requirements:
111
91
  - - "~>"
112
92
  - !ruby/object:Gem::Version
113
- version: '1.2'
93
+ version: '1.4'
114
94
  - - ">="
115
95
  - !ruby/object:Gem::Version
116
- version: 1.2.3
96
+ version: 1.4.1
117
97
  type: :runtime
118
98
  prerelease: false
119
99
  version_requirements: !ruby/object:Gem::Requirement
120
100
  requirements:
121
101
  - - "~>"
122
102
  - !ruby/object:Gem::Version
123
- version: '1.2'
103
+ version: '1.4'
124
104
  - - ">="
125
105
  - !ruby/object:Gem::Version
126
- version: 1.2.3
106
+ version: 1.4.1
127
107
  - !ruby/object:Gem::Dependency
128
108
  name: os
129
109
  requirement: !ruby/object:Gem::Requirement
130
110
  requirements:
131
111
  - - ">="
132
112
  - !ruby/object:Gem::Version
133
- version: '0'
113
+ version: 1.0.0
134
114
  type: :runtime
135
115
  prerelease: false
136
116
  version_requirements: !ruby/object:Gem::Requirement
137
117
  requirements:
138
118
  - - ">="
139
119
  - !ruby/object:Gem::Version
140
- version: '0'
120
+ version: 1.0.0
141
121
  - !ruby/object:Gem::Dependency
142
122
  name: pry
143
123
  requirement: !ruby/object:Gem::Requirement
@@ -152,6 +132,20 @@ dependencies:
152
132
  - - ">="
153
133
  - !ruby/object:Gem::Version
154
134
  version: '0'
135
+ - !ruby/object:Gem::Dependency
136
+ name: rdoc
137
+ requirement: !ruby/object:Gem::Requirement
138
+ requirements:
139
+ - - "<="
140
+ - !ruby/object:Gem::Version
141
+ version: 6.3.2
142
+ type: :development
143
+ prerelease: false
144
+ version_requirements: !ruby/object:Gem::Requirement
145
+ requirements:
146
+ - - "<="
147
+ - !ruby/object:Gem::Version
148
+ version: 6.3.2
155
149
  description: Sync your code live to docker-containers without losing any performance
156
150
  on OSX
157
151
  email: eugen.mayer@kontextwork.de
@@ -169,6 +163,7 @@ files:
169
163
  - bin/docker-sync-daemon
170
164
  - bin/docker-sync-stack
171
165
  - lib/docker-sync.rb
166
+ - lib/docker-sync/command.rb
172
167
  - lib/docker-sync/compose.rb
173
168
  - lib/docker-sync/config/config_locator.rb
174
169
  - lib/docker-sync/config/config_serializer.rb
@@ -188,6 +183,7 @@ files:
188
183
  - lib/docker-sync/dependencies/rsync.rb
189
184
  - lib/docker-sync/dependencies/unison.rb
190
185
  - lib/docker-sync/dependencies/unox.rb
186
+ - lib/docker-sync/docker_compose_session.rb
191
187
  - lib/docker-sync/environment.rb
192
188
  - lib/docker-sync/execution.rb
193
189
  - lib/docker-sync/sync_manager.rb
@@ -224,7 +220,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
224
220
  - !ruby/object:Gem::Version
225
221
  version: '0'
226
222
  requirements: []
227
- rubygems_version: 3.1.4
223
+ rubygems_version: 3.1.6
228
224
  signing_key:
229
225
  specification_version: 4
230
226
  summary: Docker Sync - Fast and efficient way to sync code to docker-containers