devbox_launcher 0.2.0 → 0.3.0

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: bb15ad0ea9b993eb803001449bff9970a345d12f872ae973a551e5899b3f3401
4
- data.tar.gz: c4586ec0d2658d7eba82d88550afc849342a5675d7dde501ff1cdf9aae838119
3
+ metadata.gz: 2b3edb043751826ec3d3dfec5c5cbfe867cecd1da4938f5f5b7fee2401903387
4
+ data.tar.gz: 51d6d27541b6933ab9f7e2eca6a3c1d74bcf455fd6a447dabb9dcfe09852abb7
5
5
  SHA512:
6
- metadata.gz: 0f244644671795da723b0eca23a9546fceabe1c98897362767070b2582c95b58fa94ad27ea57161cd0c2dbfd2a76518c8c0c5f693a724e732289c7a6dfbb8ee8
7
- data.tar.gz: 3f49c7aff85f9a3500e9da5139cfddd178734a9413cd5f0e03cb3d95b6b684864b3983a8242de5041ac744b34b490cb605902a1c7256bed3c9629f8d28ed6a6e
6
+ metadata.gz: b213b9982c3c7ffbc16db6b2555e4ef1ed4ab7ff59a0a3e10bbd6a7c800ce60006615dedb2caae32353ea27331a9c89b97fc30b973b6e73bf85ba34d2c86bbae
7
+ data.tar.gz: 0f6a627362ff12fb49e7f1f508ee374adaaff932ca248c8d88cfb3209ea28ec94521e1443b7144a66ea270fe896b53aeb740c042dea1134de2aa28ee568b70bb
data/.gitignore CHANGED
File without changes
data/.rspec CHANGED
File without changes
data/.travis.yml CHANGED
File without changes
data/CHANGELOG.md CHANGED
@@ -4,6 +4,14 @@ All notable changes to this project will be documented in this file.
4
4
  The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
5
5
  and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
6
6
 
7
- ## [Unreleased]
7
+ ## [0.3.0]
8
+ ### Changed
9
+ - Label sessions with devbox
10
+ - On linux, mutagen relies on watchman to detect changes
11
+
12
+ ### Fixed
13
+ - In Linux, mutagen no longer burns CPU every 10 seconds
14
+
15
+ ## [0.2.0]
8
16
  ### Added
9
- - Initial release
17
+ - Initial release
data/CODE_OF_CONDUCT.md CHANGED
File without changes
data/Gemfile CHANGED
File without changes
data/Gemfile.lock CHANGED
@@ -1,11 +1,13 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- devbox_launcher (0.2.0)
4
+ devbox_launcher (0.3.0)
5
5
  activesupport (~> 6.0)
6
6
  bcrypt_pbkdf (~> 1.0)
7
7
  ed25519 (~> 1.2)
8
8
  net-ssh (~> 5.2)
9
+ os (~> 1.0)
10
+ ruby-watchman (= 0.0.2)
9
11
  ssh-config (= 0.1.3)
10
12
  thor (~> 1.0)
11
13
 
@@ -22,7 +24,6 @@ GEM
22
24
  byebug (11.0.1)
23
25
  coderay (1.1.2)
24
26
  concurrent-ruby (1.1.5)
25
- deep_fetch (0.0.5)
26
27
  diff-lcs (1.3)
27
28
  ed25519 (1.2.4)
28
29
  i18n (1.8.2)
@@ -30,6 +31,7 @@ GEM
30
31
  method_source (0.9.2)
31
32
  minitest (5.14.0)
32
33
  net-ssh (5.2.0)
34
+ os (1.0.1)
33
35
  pry (0.12.2)
34
36
  coderay (~> 1.1.0)
35
37
  method_source (~> 0.9.0)
@@ -50,6 +52,7 @@ GEM
50
52
  diff-lcs (>= 1.2.0, < 2.0)
51
53
  rspec-support (~> 3.9.0)
52
54
  rspec-support (3.9.0)
55
+ ruby-watchman (0.0.2)
53
56
  ssh-config (0.1.3)
54
57
  thor (1.0.1)
55
58
  thread_safe (0.3.6)
@@ -68,4 +71,4 @@ DEPENDENCIES
68
71
  rspec (~> 3.0)
69
72
 
70
73
  BUNDLED WITH
71
- 2.0.2
74
+ 2.1.4
data/LICENSE.txt CHANGED
File without changes
data/README.md CHANGED
@@ -38,6 +38,8 @@ devbox start your-username
38
38
 
39
39
  If you want to mosh in immediately, add the `--mosh` switch.
40
40
 
41
+ Note: Linux users that sync mutagen sessions need to install [Watchman](https://facebook.github.io/watchman/).
42
+
41
43
  ## Development
42
44
 
43
45
  After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
data/Rakefile CHANGED
File without changes
@@ -39,4 +39,6 @@ Gem::Specification.new do |spec|
39
39
  spec.add_runtime_dependency "bcrypt_pbkdf", "~> 1.0"
40
40
  spec.add_runtime_dependency "ssh-config", "0.1.3"
41
41
  spec.add_runtime_dependency "activesupport", "~> 6.0"
42
+ spec.add_runtime_dependency "os", "~> 1.0"
43
+ spec.add_runtime_dependency "ruby-watchman", "0.0.2"
42
44
  end
@@ -3,6 +3,10 @@ require "ssh-config"
3
3
  require "open3"
4
4
  require "thor"
5
5
  require "net/ssh"
6
+ require "os"
7
+ require "ruby-watchman"
8
+ require 'socket'
9
+ require 'pathname'
6
10
  require "yaml"
7
11
  require "devbox_launcher/version"
8
12
 
@@ -11,3 +15,4 @@ module DevboxLauncher
11
15
  end
12
16
 
13
17
  require "devbox_launcher/cli"
18
+ require "devbox_launcher/watchman"
@@ -6,6 +6,7 @@ module DevboxLauncher
6
6
  SSH_CONFIG_PATH = File.expand_path("~/.ssh/config").freeze
7
7
  CONFIG_PATH = File.expand_path("~/.devbox_launcher.yml").freeze
8
8
  CONFIG = YAML.load_file(CONFIG_PATH).freeze
9
+ LABEL = "devbox".freeze
9
10
 
10
11
  desc "start configured box for account", "Start a devbox by account"
11
12
  option :mosh, type: :boolean, desc: "Mosh in"
@@ -103,8 +104,22 @@ module DevboxLauncher
103
104
 
104
105
  return if alpha_dir.nil? || beta_dir.nil?
105
106
 
106
- puts "Terminating all mutagen sessions..."
107
- terminate_mutagen_command = %Q(mutagen terminate --all)
107
+ terminate_mutagen_session
108
+ create_mutagen_session(
109
+ alpha_dir: alpha_dir,
110
+ beta_dir: beta_dir,
111
+ hostname: hostname,
112
+ )
113
+
114
+ if OS.linux?
115
+ watch_alpha(alpha_dir: alpha_dir)
116
+ end
117
+ end
118
+
119
+ def terminate_mutagen_session
120
+ puts "Terminating mutagen session..."
121
+ terminate_mutagen_command =
122
+ %Q(mutagen terminate --label-selector=#{LABEL})
108
123
  terminate_mutagen_stdout,
109
124
  terminate_mutagen_stderr,
110
125
  terminate_mutagen_status =
@@ -117,18 +132,24 @@ module DevboxLauncher
117
132
  "#{terminate_mutagen_stderr}"
118
133
  fail msg
119
134
  end
135
+ end
120
136
 
137
+ def create_mutagen_session(alpha_dir:, beta_dir:, hostname:)
121
138
  puts "Create mutagen session syncing local #{alpha_dir} " \
122
139
  "with #{hostname} #{beta_dir}"
140
+
123
141
  create_mutagen_command = [
124
142
  "mutagen sync create",
125
143
  alpha_dir,
126
144
  "#{hostname}:#{beta_dir}",
127
- ].join(" ")
145
+ "--label=#{LABEL}",
146
+ ]
147
+ create_mutagen_command << "--watch-mode-alpha=no-watch" if OS.linux?
148
+
128
149
  create_mutagen_stdout,
129
150
  create_mutagen_stderr,
130
151
  create_mutagen_status =
131
- Open3.capture3(create_mutagen_command)
152
+ Open3.capture3(create_mutagen_command.join(" "))
132
153
 
133
154
  if not create_mutagen_status.success?
134
155
  # mutagen prints to stdout and stderr
@@ -138,6 +159,11 @@ module DevboxLauncher
138
159
  fail msg
139
160
  end
140
161
  end
162
+
163
+ def watch_alpha(alpha_dir:)
164
+ watchman = Watchman.new(dir: alpha_dir)
165
+ watchman.trigger("mutagen sync flush --label-selector=#{LABEL}")
166
+ end
141
167
  end
142
168
 
143
169
  end
@@ -1,3 +1,3 @@
1
1
  module DevboxLauncher
2
- VERSION = "0.2.0"
2
+ VERSION = "0.3.0"
3
3
  end
@@ -0,0 +1,50 @@
1
+ module DevboxLauncher
2
+ class Watchman
3
+
4
+ attr_reader :dir
5
+
6
+ def initialize(dir:)
7
+ @dir = dir
8
+ end
9
+
10
+ def trigger(command)
11
+ UNIXSocket.open(sockname) do |socket|
12
+ root = Pathname.new(dir).expand_path.to_s
13
+ result = RubyWatchman.query(['watch-list'], socket)
14
+ roots = result['roots']
15
+ if !roots.include?(root)
16
+ # this path isn't being watched yet; try to set up watch
17
+ result = RubyWatchman.query(['watch-project', root], socket)
18
+
19
+ # root_restrict_files setting may prevent Watchman from working
20
+ raise "Unable to watch #{dir}" if result.has_key?('error')
21
+ end
22
+
23
+ query = ['trigger', root, {
24
+ 'name' => 'mutagen-sync',
25
+ 'expression' => ['match', '**/*', 'wholename'],
26
+ 'command' => command.split(" "),
27
+ }]
28
+ paths = RubyWatchman.query(query, socket)
29
+
30
+ # could return error if watch is removed
31
+ if paths.has_key?('error')
32
+ raise "Unable to set trigger. Error: #{paths['error']}"
33
+ end
34
+ end
35
+ end
36
+
37
+ def sockname
38
+ sockname = RubyWatchman.load(
39
+ %x{watchman --output-encoding=bser get-sockname}
40
+ )['sockname']
41
+
42
+ if !$?.exitstatus.zero?
43
+ raise "Failed to connect to watchman. Is it running?"
44
+ end
45
+
46
+ sockname
47
+ end
48
+
49
+ end
50
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: devbox_launcher
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ramon Tayag
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-01-19 00:00:00.000000000 Z
11
+ date: 2020-01-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -136,6 +136,34 @@ dependencies:
136
136
  - - "~>"
137
137
  - !ruby/object:Gem::Version
138
138
  version: '6.0'
139
+ - !ruby/object:Gem::Dependency
140
+ name: os
141
+ requirement: !ruby/object:Gem::Requirement
142
+ requirements:
143
+ - - "~>"
144
+ - !ruby/object:Gem::Version
145
+ version: '1.0'
146
+ type: :runtime
147
+ prerelease: false
148
+ version_requirements: !ruby/object:Gem::Requirement
149
+ requirements:
150
+ - - "~>"
151
+ - !ruby/object:Gem::Version
152
+ version: '1.0'
153
+ - !ruby/object:Gem::Dependency
154
+ name: ruby-watchman
155
+ requirement: !ruby/object:Gem::Requirement
156
+ requirements:
157
+ - - '='
158
+ - !ruby/object:Gem::Version
159
+ version: 0.0.2
160
+ type: :runtime
161
+ prerelease: false
162
+ version_requirements: !ruby/object:Gem::Requirement
163
+ requirements:
164
+ - - '='
165
+ - !ruby/object:Gem::Version
166
+ version: 0.0.2
139
167
  description:
140
168
  email:
141
169
  - ramon.tayag@gmail.com
@@ -163,6 +191,7 @@ files:
163
191
  - lib/devbox_launcher.rb
164
192
  - lib/devbox_launcher/cli.rb
165
193
  - lib/devbox_launcher/version.rb
194
+ - lib/devbox_launcher/watchman.rb
166
195
  homepage: https://github.com/bloom-solutions/devbox_launcher
167
196
  licenses:
168
197
  - MIT