docker-sync 0.7.2 → 1.0.2

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: 88cce934f387bf527bd53628913c8bfe95b99533cea63a0ab45258fa66a4b185
4
- data.tar.gz: b7fa487477e4ba03b6082f8712a391e0ac7c15b1fde8c671b35436c2a244f35a
3
+ metadata.gz: 99de3e53b469050cd1cf2afd597aa4fabcc23338e4d6d5cd67ebb833fa1ff184
4
+ data.tar.gz: 4aadccbadd4ebeade4b3b5d214a900a411198c74aff3e813f71c9a6c4f297aaa
5
5
  SHA512:
6
- metadata.gz: 635d2f2a06c5f284395b1dbc67db3fbc616efca42650a3d912265d1c88239078776a9975c74394b1dfb4071a5ca9b9f85234fe4a530932b0da1176dbb9b1e55b
7
- data.tar.gz: 3e54b8c08bee9b846e9fdd8991b21370bc57b97bb0864b3a7f88712c775e72832902cf0134651ecd2ed6d33165c8496af48f8997f1429b41bc5643b3854621f2
6
+ metadata.gz: df858a48916d036de531a04ad6707cb71e5212f9883c0df2f6ad8d326ecf349b64c4f4d859794ccc2afc35d2fd9fba31c17afaeebcb395df2cf1c91b548d617b
7
+ data.tar.gz: 311975e4eacca8e19f2d5a3dc1f707850b5719e5ddb02d6f5250b777a5f738214534d691f54338d171f8e4a84d3d025e81a4a39b276758bdc2fc20c39caf4591
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.7.2
1
+ 1.0.2
@@ -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
@@ -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,9 @@ module DockerSync
61
61
 
62
62
  def sync_options
63
63
  args = []
64
+
64
65
  unless @options['sync_excludes'].nil?
65
- args = @options['sync_excludes'].map { |pattern| "--exclude='#{pattern}'" } + args
66
+ args = excludes_list.append(Environment.default_ignores).flatten!.map { |pattern| "--exclude='#{pattern}'" } + args
66
67
  end
67
68
  args.push('-ap')
68
69
  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?
@@ -105,6 +101,14 @@ module DockerSync
105
101
  exclude_type = 'Name'
106
102
  exclude_type = @options['sync_excludes_type'] unless @options['sync_excludes_type'].nil?
107
103
 
104
+ # use the 'Name' exclude type for all default ignores
105
+ # to prevent conflicts with the sync_excludes_type settings
106
+ unless Environment.default_ignores.nil?
107
+ expanded_ignore_strings = Environment.default_ignores.map do |pattern|
108
+ "-ignore='Name #{pattern}'"
109
+ end
110
+ end
111
+
108
112
  unless @options['sync_excludes'].nil?
109
113
  expanded_ignore_strings = @options['sync_excludes'].map do |pattern|
110
114
  ignore_string = if exclude_type == 'none'
@@ -139,6 +143,8 @@ module DockerSync
139
143
 
140
144
  # cares about conflict resolution
141
145
  def sync_prefer
146
+ sync_host_port = get_host_port(get_container_name, UNISON_CONTAINER_PORT)
147
+
142
148
  case @options.fetch('sync_prefer', 'default')
143
149
  when 'default' then "-prefer '#{@options['src']}' -copyonconflict" # thats our default, if nothing is set
144
150
  when 'src' then "-prefer '#{@options['src']}'"
@@ -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.2
4
+ version: 1.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Eugen Mayer
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-05-22 00:00:00.000000000 Z
11
+ date: 2022-09-13 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