devbox_launcher 0.3.0 → 0.3.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: 2b3edb043751826ec3d3dfec5c5cbfe867cecd1da4938f5f5b7fee2401903387
4
- data.tar.gz: 51d6d27541b6933ab9f7e2eca6a3c1d74bcf455fd6a447dabb9dcfe09852abb7
3
+ metadata.gz: 452b640a1f3b25789f24d33da5c41b46e974fa88ab0a4078eea5c4880cac1a00
4
+ data.tar.gz: 59a2965f4f0f1ca5a9758f30c4de941319b29bc5b8e9fbd9d0ea227fd6cab13e
5
5
  SHA512:
6
- metadata.gz: b213b9982c3c7ffbc16db6b2555e4ef1ed4ab7ff59a0a3e10bbd6a7c800ce60006615dedb2caae32353ea27331a9c89b97fc30b973b6e73bf85ba34d2c86bbae
7
- data.tar.gz: 0f6a627362ff12fb49e7f1f508ee374adaaff932ca248c8d88cfb3209ea28ec94521e1443b7144a66ea270fe896b53aeb740c042dea1134de2aa28ee568b70bb
6
+ metadata.gz: e5db95617c9d43d952acc269794bdde185eb6fb2dbd143e91e5715ae90596eda82813fc0b8f37716d1dec5689c1e19398052b396e42fa879b5cde6d54d06e3ef
7
+ data.tar.gz: '009f47d05871bfdae83c23736a21dfb2b9b617edba29acc7741a43d499b8c2927716561c6f9533c15c237c26f6edefe644f20f8714ded7ee980508752203ee9a'
data/CHANGELOG.md CHANGED
@@ -4,6 +4,10 @@ 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.3.1]
8
+ ### Fixed
9
+ - Recover when the devbox is in a shutdown cycle
10
+
7
11
  ## [0.3.0]
8
12
  ### Changed
9
13
  - Label sessions with devbox
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- devbox_launcher (0.3.0)
4
+ devbox_launcher (0.3.1)
5
5
  activesupport (~> 6.0)
6
6
  bcrypt_pbkdf (~> 1.0)
7
7
  ed25519 (~> 1.2)
@@ -14,24 +14,24 @@ PATH
14
14
  GEM
15
15
  remote: https://rubygems.org/
16
16
  specs:
17
- activesupport (6.0.2.1)
17
+ activesupport (6.0.3.1)
18
18
  concurrent-ruby (~> 1.0, >= 1.0.2)
19
19
  i18n (>= 0.7, < 2)
20
20
  minitest (~> 5.1)
21
21
  tzinfo (~> 1.1)
22
- zeitwerk (~> 2.2)
22
+ zeitwerk (~> 2.2, >= 2.2.2)
23
23
  bcrypt_pbkdf (1.0.1)
24
24
  byebug (11.0.1)
25
25
  coderay (1.1.2)
26
- concurrent-ruby (1.1.5)
26
+ concurrent-ruby (1.1.6)
27
27
  diff-lcs (1.3)
28
28
  ed25519 (1.2.4)
29
29
  i18n (1.8.2)
30
30
  concurrent-ruby (~> 1.0)
31
31
  method_source (0.9.2)
32
- minitest (5.14.0)
32
+ minitest (5.14.1)
33
33
  net-ssh (5.2.0)
34
- os (1.0.1)
34
+ os (1.1.0)
35
35
  pry (0.12.2)
36
36
  coderay (~> 1.1.0)
37
37
  method_source (~> 0.9.0)
@@ -56,9 +56,9 @@ GEM
56
56
  ssh-config (0.1.3)
57
57
  thor (1.0.1)
58
58
  thread_safe (0.3.6)
59
- tzinfo (1.2.6)
59
+ tzinfo (1.2.7)
60
60
  thread_safe (~> 0.1)
61
- zeitwerk (2.2.2)
61
+ zeitwerk (2.3.0)
62
62
 
63
63
  PLATFORMS
64
64
  ruby
@@ -16,3 +16,4 @@ end
16
16
 
17
17
  require "devbox_launcher/cli"
18
18
  require "devbox_launcher/watchman"
19
+ require "devbox_launcher/models/description"
@@ -17,9 +17,12 @@ module DevboxLauncher
17
17
  end
18
18
 
19
19
  config = CONFIG[account].with_indifferent_access
20
+ name = config[:box]
20
21
 
21
22
  username = account.gsub(/\W/, "_")
22
23
 
24
+ puts "Starting #{name}..."
25
+
23
26
  set_account_command = %Q(gcloud config set account #{account})
24
27
  set_account_stdout, set_account_stderr, set_account_status =
25
28
  Open3.capture3(set_account_command)
@@ -28,39 +31,11 @@ module DevboxLauncher
28
31
  set_project_stdout, set_project_stderr, set_project_status =
29
32
  Open3.capture3(set_project_command)
30
33
 
31
- name = config[:box]
32
-
33
- start_command = %Q(gcloud compute instances start #{name})
34
- start_stdout, start_stderr, start_status = Open3.capture3(start_command)
35
-
36
- puts "Fetching IP..."
37
- describe_command = %Q(gcloud compute instances describe #{name})
38
- describe_stdout, describe_stderr, describe_status =
39
- Open3.capture3(describe_command)
40
-
41
- if !describe_status.success?
42
- msg = "Problem fetching the IP address. "
43
- msg += "Please ensure you can call `#{describe_command}`.\n"
44
- msg += "Error:\n"
45
- msg += describe_stderr
46
- fail msg
47
- end
48
-
49
- description = YAML.load(describe_stdout)
34
+ start_box name, username
50
35
 
51
- ip = description["networkInterfaces"].first["accessConfigs"].
52
- find { |config| config["kind"] == "compute#accessConfig" }["natIP"]
36
+ wait_boot(name, username)
53
37
 
54
- puts "IP: #{ip}"
55
-
56
- hostname = "#{name}-devbox"
57
-
58
- set_ssh_config!(hostname, {
59
- username: username,
60
- ip: ip,
61
- })
62
-
63
- wait_boot(hostname, username)
38
+ hostname = hostname_for(name)
64
39
 
65
40
  reset_mutagen_session(
66
41
  mutagen_config: config[:mutagen],
@@ -74,13 +49,25 @@ module DevboxLauncher
74
49
  end
75
50
 
76
51
  no_commands do
77
- def wait_boot(hostname, username)
52
+ def wait_boot(name, username, tries: 1)
53
+ hostname = hostname_for(name)
54
+
78
55
  Net::SSH.start(hostname, username, timeout: WAIT_BOOT_IN_SECONDS) do |ssh|
79
56
  puts "[#{ssh.exec!('date').chomp}] Machine booted"
80
57
  end
81
58
  rescue Net::SSH::ConnectionTimeout, Net::SSH::Disconnect, Errno::ECONNRESET
82
59
  puts "Not booted. Waiting #{WAIT_BOOT_IN_SECONDS} seconds before trying again..."
83
- wait_boot hostname, username
60
+
61
+ sleep WAIT_BOOT_IN_SECONDS
62
+
63
+ description = describe(name)
64
+ if !description.running?
65
+ puts "Detected that the machine is not running " \
66
+ "(status is #{description.status}). Booting it..."
67
+ start_box name, username
68
+ end
69
+
70
+ wait_boot name, username, tries: tries+1
84
71
  end
85
72
 
86
73
  def set_ssh_config!(hostname, username:, ip:)
@@ -164,6 +151,41 @@ module DevboxLauncher
164
151
  watchman = Watchman.new(dir: alpha_dir)
165
152
  watchman.trigger("mutagen sync flush --label-selector=#{LABEL}")
166
153
  end
154
+
155
+ def start_box(name, username)
156
+ start_command = %Q(gcloud compute instances start #{name})
157
+ start_stdout, start_stderr, start_status = Open3.capture3(start_command)
158
+
159
+ desc = describe(name)
160
+ ip = desc.ip
161
+
162
+ set_ssh_config!(hostname_for(name), {
163
+ username: username,
164
+ ip: ip,
165
+ })
166
+ end
167
+
168
+ def describe(name)
169
+ puts "Fetching box's description..."
170
+
171
+ describe_command = %Q(gcloud compute instances describe #{name})
172
+ describe_stdout, describe_stderr, describe_status =
173
+ Open3.capture3(describe_command)
174
+
175
+ if !describe_status.success?
176
+ msg = "Problem fetching the description of #{name}. "
177
+ msg += "Please ensure you can call `#{describe_command}`.\n"
178
+ msg += "Error:\n"
179
+ msg += describe_stderr
180
+ fail msg
181
+ end
182
+
183
+ Description.new(describe_stdout)
184
+ end
185
+
186
+ def hostname_for(name)
187
+ [name, "devbox"].join("-")
188
+ end
167
189
  end
168
190
 
169
191
  end
@@ -1,3 +1,3 @@
1
1
  module DevboxLauncher
2
- VERSION = "0.3.0"
2
+ VERSION = "0.3.1"
3
3
  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.3.0
4
+ version: 0.3.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: 2020-01-24 00:00:00.000000000 Z
11
+ date: 2020-05-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -215,7 +215,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
215
215
  - !ruby/object:Gem::Version
216
216
  version: '0'
217
217
  requirements: []
218
- rubygems_version: 3.0.6
218
+ rubygems_version: 3.0.3
219
219
  signing_key:
220
220
  specification_version: 4
221
221
  summary: Conveniently launch your devbox