devkitkat 0.1.25 → 0.1.26

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: 421aca57d9ed36e6ed5bc0555ece96e45ba98546c7df5ae643235648fd2978c8
4
- data.tar.gz: ffa96bdf80c4351dd19caaf3f85f57b3d4505c994c3e687755aafcb14a4599d8
3
+ metadata.gz: bc1ec65b940b53a2d04d473ed109dbd6b97256f09ac270f2b59edb607201b310
4
+ data.tar.gz: c14fa3b11c1fe1fd4e33e92fece3bfa9e5eaf3ad233cb34cf0e5b8dfe2783a10
5
5
  SHA512:
6
- metadata.gz: fec93d309ccd8de925dc2f7c055fb86573c6ec2adb22a10946c04b4a10b24afb12601540d914df0b86e259777e30ac5718fb5878f264b9fb33e324354f168a2b
7
- data.tar.gz: 36a6194e6db9d2464f8f24cf31f5c686ea2c83827bb24e3328ca1d023c546f1848ce4e73ce91979d8cfd531ce28be615a8ecd9797b131d027f0404edcd1934ed
6
+ metadata.gz: b331ae89d8c5cf523fe51b0b4cc36bad069b7f5750e7b8413ec4f41896ebcded43f680e42dfff6aa44bf4755aabf9d459e1f0c4c1e1243b80977baf787c06750
7
+ data.tar.gz: 78dcc4f8d93ddb3727c6f9ff254b9a4dd2ef406f7c95f07ae7bd6a216f622dc08b748811f3be5eec5d8822c2570375762d1f99063be2199589682cdc5ace505f
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- devkitkat (0.1.24)
4
+ devkitkat (0.1.25)
5
5
  activesupport (~> 6.0.0)
6
6
  colorize (~> 0.8.1)
7
7
  docker-api (~> 1.34.2)
@@ -10,36 +10,49 @@ module Devkitkat
10
10
  attr_reader :container
11
11
 
12
12
  def start
13
- if @container = find
13
+ @container = find
14
+
15
+ if command.interactive?
16
+ raise 'Container has not started yet for interactive session' unless @container
17
+ return
18
+ end
19
+
20
+ if @container
14
21
  container.restart
15
22
  else
16
23
  @container = create
17
- container.restart
24
+ container.start
18
25
  create_host_user
19
26
  end
20
27
  end
21
28
 
22
29
  def stop
30
+ return if command.interactive?
23
31
  raise 'Container has not started yet' unless container
24
32
 
25
33
  container.stop
26
34
  end
27
35
 
28
- def exec(cmds, params = {})
36
+ def exec(cmds, params = {}, &block)
29
37
  params.merge!(user: user_name)
30
- safe_exec(cmds, params)
38
+ safe_exec(cmds, params, &block)
31
39
  end
32
40
 
33
- def exec_as_root(cmds, params = {})
34
- safe_exec(cmds, params)
41
+ def exec_as_root(cmds, params = {}, &block)
42
+ safe_exec(cmds, params, &block)
43
+ end
44
+
45
+ def interactive_shell(cmd)
46
+ # container.exec([new_path], tty: true, stdin: STDIN) { |stream, chunk| print "#{stream}" }
47
+ Kernel.exec('docker', 'exec', '-ti', '--user', user_name, name, cmd)
35
48
  end
36
49
 
37
50
  private
38
51
 
39
- def safe_exec(cmds, params)
52
+ def safe_exec(cmds, params, &block)
40
53
  params.merge!(wait: 604800) # Default timeout is 1 minute, so setting 1 week instead
41
54
  stdout_messages, stderr_messages, exit_code =
42
- container.exec(cmds, params)
55
+ container.exec(cmds, params, &block)
43
56
 
44
57
  if exit_code != 0 || command.debug?
45
58
  puts "#{self.class.name} - #{__callee__}: stdout_messages: #{stdout_messages} stderr_messages: #{stderr_messages} exit_code: #{exit_code}"
@@ -55,11 +68,6 @@ module Devkitkat
55
68
  config.machine_image
56
69
  end
57
70
 
58
- def name
59
- @name ||=
60
- "#{config.application}-#{service.name}-#{Digest::SHA1.hexdigest(command.kit_root)[8..12]}"
61
- end
62
-
63
71
  def find
64
72
  ::Docker::Container.get(name)
65
73
  rescue ::Docker::Error::NotFoundError
@@ -123,6 +131,11 @@ module Devkitkat
123
131
  end
124
132
  end
125
133
 
134
+ def name
135
+ @name ||=
136
+ "#{config.application}-#{service.name}-#{Digest::SHA1.hexdigest(command.kit_root)[8..12]}"
137
+ end
138
+
126
139
  def user_name
127
140
  'devkitkat'
128
141
  end
@@ -14,7 +14,11 @@ module Devkitkat
14
14
  def execute(script_file)
15
15
  new_path = rewrite_root_path!(script_file)
16
16
 
17
- container.exec([new_path])
17
+ if command.interactive?
18
+ container.interactive_shell(new_path)
19
+ else
20
+ container.exec([new_path])
21
+ end
18
22
  end
19
23
 
20
24
  def cleanup
@@ -4,7 +4,9 @@ module Devkitkat
4
4
  class Exec < Base
5
5
  def to_script
6
6
  <<~EOS
7
- cd #{service.src_dir}
7
+ if [ -d "#{service.src_dir}" ]; then
8
+ cd #{service.src_dir}
9
+ fi
8
10
  #{command.args.join(' ')}
9
11
  EOS
10
12
  end
@@ -1,3 +1,3 @@
1
1
  module Devkitkat
2
- VERSION = "0.1.25"
2
+ VERSION = "0.1.26"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: devkitkat
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.25
4
+ version: 0.1.26
5
5
  platform: ruby
6
6
  authors:
7
7
  - Shinya Maeda
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-04-24 00:00:00.000000000 Z
11
+ date: 2020-04-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler