devbox_launcher 0.5.2 → 0.7.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 51aeda9106ca067ea8ceb40899eeced91677bebb5de13b036280190d22980e16
4
- data.tar.gz: b2852f7051db8ec6c4ce7e071aa256cab13b64af69455a774d4d18e9b949db75
3
+ metadata.gz: 73bbdd9915f666e004ef152b8749e333face998265474ecddbf5d01f55a30f01
4
+ data.tar.gz: af3b044ffff0318f3fdf622ef688685c7eba44068976703e32255038d79f26ea
5
5
  SHA512:
6
- metadata.gz: c84b3cb6f48286ea756546429c3e2d6bf6121b0f4632207bf37779e1f0a4611eb4126b6d24645a81b34738cb178c3cc06ec3046c606fa92a8bc65a71665474b0
7
- data.tar.gz: 2585520ba4fb389c731b9f8fcca88b453ac6dbb91e82b9a466341d32e68ee773a42b481f106a400d1d5f5ea31b12358db098fb53f7ae6e6312cd7ec117a6b500
6
+ metadata.gz: fb0e7f1d59c4a81faa72586cb618d24f3dc75f1a04711427a74846e34ab2fda3df2dac8098211d7734b3d3b5f4c010c6683a5f12efb36c8e13c30ace73291e70
7
+ data.tar.gz: 5d558bf0456db555941e8e5b6bf498af28280420f86dd0d2e3b438819a878528889cda7155a8e5050116a783a6f16dec3d47b2704238bbdd5a19230902a130e3
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,22 @@ 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
+ ## [0.7.1] - 2021-10-14
8
+ ### Fixed
9
+ - Explicitly require fileutils for Ruby 3.0 compatibility
10
+
11
+ ## [0.7.0] - 2021-09-23
12
+ ### Added
13
+ - Add ability to set a box's user and identity_file
14
+
15
+ ## [0.6.1] - 2021-09-22
16
+ ### Fixed
17
+ - Do not blow up if mutagen is not configured
18
+
19
+ ## [0.6.0] - 2021-09-21
20
+ ### Changed
21
+ - Ability to configure multiple boxes under one account
22
+
7
23
  ## [0.5.2] - 2021-05-31
8
24
  ### Added
9
25
  - Ignore VCS as recommended by mutagen
data/CODE_OF_CONDUCT.md CHANGED
File without changes
data/Gemfile CHANGED
File without changes
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- devbox_launcher (0.5.2)
4
+ devbox_launcher (0.7.1)
5
5
  activesupport (~> 6.0)
6
6
  bcrypt_pbkdf (~> 1.0)
7
7
  ed25519 (~> 1.2)
@@ -14,7 +14,7 @@ PATH
14
14
  GEM
15
15
  remote: https://rubygems.org/
16
16
  specs:
17
- activesupport (6.1.3.2)
17
+ activesupport (6.1.4.1)
18
18
  concurrent-ruby (~> 1.0, >= 1.0.2)
19
19
  i18n (>= 1.6, < 2)
20
20
  minitest (>= 5.1)
@@ -23,7 +23,7 @@ GEM
23
23
  bcrypt_pbkdf (1.1.0)
24
24
  byebug (11.0.1)
25
25
  coderay (1.1.2)
26
- concurrent-ruby (1.1.8)
26
+ concurrent-ruby (1.1.9)
27
27
  diff-lcs (1.3)
28
28
  ed25519 (1.2.4)
29
29
  i18n (1.8.10)
@@ -70,4 +70,4 @@ DEPENDENCIES
70
70
  rspec (~> 3.0)
71
71
 
72
72
  BUNDLED WITH
73
- 2.1.4
73
+ 2.2.27
data/LICENSE.txt CHANGED
File without changes
data/README.md CHANGED
@@ -16,17 +16,17 @@ Create the config file at `~/.devbox_launcher.yml` so you type less. This is an
16
16
 
17
17
  ```yml
18
18
  ramon@email.com:
19
- project: general-192303
20
- # zone not necessarily required, but sometimes starting the box
21
- # fails without this:
22
- zone: us-central1-a
23
- box: your-instance-name
24
- mutagen:
25
- alpha: /mnt/c/Users/me/src # local machine
26
- beta: ~/src # remote machine
19
+ - box: your-instance-name
20
+ project: general-192303
21
+ zone: us-central1-a
22
+ mutagen:
23
+ alpha: /mnt/c/Users/me/src # local machine
24
+ beta: ~/src # remote machine
27
25
  ramon@company.com:
28
- project: development-254604
29
- box: ramon
26
+ - project: development-254604
27
+ box: ramon
28
+ user: another_user # only needed if ramon_company_com is not the user
29
+ identity_file: /path/to/ssh-private # ~/.ssh/google_compute_engine by default
30
30
  ```
31
31
 
32
32
  To start and create the mutagen session:
@@ -35,7 +35,13 @@ To start and create the mutagen session:
35
35
  devbox start your-username
36
36
  ```
37
37
 
38
- If you want to mosh in immediately, add the `--mosh` switch. Yes, mosh needs to be [installed](https://mosh.org/) in your development machine.
38
+ - Want to ssh in immediately?
39
+ - Add `--ssh` switch
40
+ - Want to mosh in immediately?
41
+ - Add `--mosh` switch. Mosh needs to be [installed](https://mosh.org/) in your development machine.
42
+ - More than one box with the same Google Cloud account?
43
+ - Pass in the box in your command, via `devbox start user@domain.com/box-name`
44
+ - No need to configure `box:` in the YAML file
39
45
 
40
46
  Note: Linux users that sync mutagen sessions need to install [Watchman](https://facebook.github.io/watchman/).
41
47
 
data/Rakefile CHANGED
File without changes
@@ -9,6 +9,7 @@ module DevboxLauncher
9
9
 
10
10
  desc "start configured box for account", "Start a devbox by account"
11
11
  option :mosh, type: :boolean, desc: "Mosh in"
12
+ option :ssh, type: :boolean, desc: "SSH in"
12
13
 
13
14
  def start(account)
14
15
  Box.new(account, options).start
@@ -0,0 +1,22 @@
1
+ module DevboxLauncher
2
+ class AccountConfig
3
+
4
+ attr_reader :account_name
5
+
6
+ def initialize(account_name, config)
7
+ @account_name = account_name
8
+ @config = config
9
+ end
10
+
11
+ def find_box_config(box_name)
12
+ box_config = @config.find { |c| c["box"] == box_name }
13
+
14
+ if box_config.nil?
15
+ fail "No box config found for #{box_name} under account #{account_name}"
16
+ end
17
+
18
+ BoxConfig.new(box_config)
19
+ end
20
+
21
+ end
22
+ end
@@ -10,18 +10,21 @@ module DevboxLauncher
10
10
  ]
11
11
  WAIT_BOOT_IN_SECONDS = 10.freeze
12
12
  MAX_BOOT_RETRIES = 20
13
- DEFAULT_IDENTIFY_FILE_PATH = "~/.ssh/google_compute_engine".freeze
14
13
  SSH_CONFIG_PATH = File.expand_path("~/.ssh/config").freeze
15
14
  CONFIG_PATH = File.expand_path("~/.devbox_launcher.yml").freeze
16
15
  CONFIG = YAML.load_file(CONFIG_PATH).freeze
17
16
 
18
- attr_reader :account, :options
17
+ attr_reader :account_and_box_name, :options
19
18
 
20
- def initialize(account, options)
21
- @account = account
19
+ def initialize(account_and_box_name, options)
20
+ @account_and_box_name = account_and_box_name
22
21
  @options = options
23
22
  end
24
23
 
24
+ def account
25
+ @account ||= @account_and_box_name.split("/")[0]
26
+ end
27
+
25
28
  def start
26
29
  start_stdout, start_stderr, start_status =
27
30
  Open3.capture3(start_cmd)
@@ -32,7 +35,7 @@ module DevboxLauncher
32
35
 
33
36
  reset_mutagen_session
34
37
 
35
- connect_mosh
38
+ connect_mosh || connect_ssh
36
39
  end
37
40
 
38
41
  def start_cmd
@@ -46,6 +49,13 @@ module DevboxLauncher
46
49
  system(mosh_cmd)
47
50
  end
48
51
 
52
+ def connect_ssh
53
+ return if options[:ssh].nil?
54
+
55
+ ssh_cmd = %Q(ssh #{hostname})
56
+ system(ssh_cmd)
57
+ end
58
+
49
59
  def wait_boot(tries: 1)
50
60
  Net::SSH.start(hostname, username, timeout: WAIT_BOOT_IN_SECONDS) do |ssh|
51
61
  puts "[#{ssh.exec!('date').chomp}] Machine booted"
@@ -89,16 +99,16 @@ module DevboxLauncher
89
99
 
90
100
  def set_ssh_config!
91
101
  FileUtils.touch(SSH_CONFIG_PATH)
92
- config = ConfigFile.new
102
+ ssh_config = ConfigFile.new
93
103
  args = {
94
104
  "HostName" => description.ip,
95
105
  "User" => username,
96
- "IdentityFile" => DEFAULT_IDENTIFY_FILE_PATH,
106
+ "IdentityFile" => box_config.identity_file,
97
107
  }
98
108
  args.each do |key, value|
99
- config.set(hostname, key, value)
109
+ ssh_config.set(hostname, key, value)
100
110
  end
101
- config.save
111
+ ssh_config.save
102
112
  end
103
113
 
104
114
  def reset_mutagen_session
@@ -163,8 +173,31 @@ module DevboxLauncher
163
173
  watchman.trigger("mutagen sync flush --label-selector=#{label}")
164
174
  end
165
175
 
176
+ def box_name_from_config
177
+ passed_in_box_name = @account_and_box_name.split("/")[1]
178
+
179
+ case account_config.count
180
+ when 0
181
+ fail "You have to specify box configuration"
182
+ when 1
183
+ account_config.first[:box]
184
+ else
185
+ account_config[name]
186
+ end
187
+ end
188
+
166
189
  def name
167
- @name ||= config[:box]
190
+ return @name if @name
191
+ passed_in_box_name = @account_and_box_name.split("/")[1]
192
+
193
+ name = passed_in_box_name.presence || box_name_from_config
194
+
195
+ if name.blank?
196
+ fail "box name must be given either in the CLI or in config. " \
197
+ "See README.md."
198
+ end
199
+
200
+ @name = name
168
201
  end
169
202
 
170
203
  def hostname
@@ -172,28 +205,32 @@ module DevboxLauncher
172
205
  end
173
206
 
174
207
  def username
175
- @username ||= account.gsub(/\W/, "_")
208
+ @username ||= box_config.user || account.gsub(/\W/, "_")
176
209
  end
177
210
 
178
- def config
179
- return @config if @config
211
+ def account_config
212
+ return @account_config if @account_config
180
213
 
181
214
  if not CONFIG.has_key?(account)
182
215
  fail "No config in #{CONFIG_PATH} found for #{account}"
183
216
  end
184
217
 
185
- @config = CONFIG[account].with_indifferent_access
218
+ @account_config = AccountConfig.new(account, CONFIG[account])
219
+ end
220
+
221
+ def box_config
222
+ account_config.find_box_config(name)
186
223
  end
187
224
 
188
225
  def mutagen_config
189
- @mutagen_config ||= Mutagen.new(config[:mutagen])
226
+ @mutagen_config ||= box_config.mutagen_config
190
227
  end
191
228
 
192
229
  def cmd_args_for(method)
193
230
  args = {
194
- project: config[:project],
231
+ project: box_config.project,
195
232
  account: account,
196
- zone: config[:zone],
233
+ zone: box_config.zone,
197
234
  }.each_with_object([]) do |(key, val), arr|
198
235
  next if val.blank?
199
236
  arr << ["--#{key}", val].join("=")
@@ -0,0 +1,33 @@
1
+ module DevboxLauncher
2
+ class BoxConfig
3
+
4
+ DEFAULT_IDENTIFY_FILE_PATH = "~/.ssh/google_compute_engine".freeze
5
+
6
+ attr_reader :config
7
+
8
+ def initialize(config)
9
+ @config = config.with_indifferent_access
10
+ end
11
+
12
+ def mutagen_config
13
+ Mutagen.new(config[:mutagen])
14
+ end
15
+
16
+ def project
17
+ config[:project]
18
+ end
19
+
20
+ def zone
21
+ config[:zone]
22
+ end
23
+
24
+ def user
25
+ config[:user]
26
+ end
27
+
28
+ def identity_file
29
+ config[:identity_file] || DEFAULT_IDENTIFY_FILE_PATH
30
+ end
31
+
32
+ end
33
+ end
@@ -8,7 +8,8 @@ module DevboxLauncher
8
8
  end
9
9
 
10
10
  def configured?
11
- [config, alpha_dir, beta_dir].none?(&:nil?)
11
+ return false if config.nil?
12
+ [alpha_dir, beta_dir].all?(&:present?)
12
13
  end
13
14
 
14
15
  def alpha_dir
@@ -1,3 +1,3 @@
1
1
  module DevboxLauncher
2
- VERSION = "0.5.2"
2
+ VERSION = "0.7.1"
3
3
  end
@@ -3,6 +3,7 @@ require "active_support/core_ext/object/blank"
3
3
  require "ssh-config"
4
4
  require "open3"
5
5
  require "thor"
6
+ require "fileutils"
6
7
  require "net/ssh"
7
8
  require "os"
8
9
  require "ruby-watchman"
@@ -20,3 +21,5 @@ require "devbox_launcher/watchman"
20
21
  require "devbox_launcher/models/description"
21
22
  require "devbox_launcher/models/mutagen"
22
23
  require "devbox_launcher/models/box"
24
+ require "devbox_launcher/models/account_config"
25
+ require "devbox_launcher/models/box_config"
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.5.2
4
+ version: 0.7.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ramon Tayag
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-05-31 00:00:00.000000000 Z
11
+ date: 2021-10-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -190,7 +190,9 @@ files:
190
190
  - devbox_launcher.gemspec
191
191
  - lib/devbox_launcher.rb
192
192
  - lib/devbox_launcher/cli.rb
193
+ - lib/devbox_launcher/models/account_config.rb
193
194
  - lib/devbox_launcher/models/box.rb
195
+ - lib/devbox_launcher/models/box_config.rb
194
196
  - lib/devbox_launcher/models/description.rb
195
197
  - lib/devbox_launcher/models/mutagen.rb
196
198
  - lib/devbox_launcher/version.rb
@@ -218,7 +220,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
218
220
  - !ruby/object:Gem::Version
219
221
  version: '0'
220
222
  requirements: []
221
- rubygems_version: 3.1.4
223
+ rubygems_version: 3.1.6
222
224
  signing_key:
223
225
  specification_version: 4
224
226
  summary: Conveniently launch your devbox