wslc-wip 0.1.3 → 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: 996355115196c1437d3e06148ccc257c8d39dc5c98905643b979ff032de1775c
4
- data.tar.gz: c10bb414811f0e7ab33d3fcf5a80f360d8b4f61aa374120d03c394eca22b1429
3
+ metadata.gz: aacee07e7929d736a13e1a7a4812a52155431b311913a4e5fa25409f6c772f60
4
+ data.tar.gz: 31de690c5b1040a9d0cb0c12890f20cf8d07f1d3d57e74d44140d8af30d7e0f0
5
5
  SHA512:
6
- metadata.gz: b613505166cfdc3389ab84c7bdc4c226bdbc3c1943d75b4b9c1b2a31aea9e80f5e858aa6d4e2d68028aa66686c9239d1089841dbab55534a23c5bc42768e7bba
7
- data.tar.gz: 1a25e8fe70e97205d198560c48eb69cdeafc8a29716f43b2534636fb1f3fc7eb04da41907081e633eb5ec509d6e1fb383bbddae532b21324d649ee75b4b8b2b5
6
+ metadata.gz: 13e7a7c473c92063c6c9bc505ea72b03a8fab8269a6deb0ae2f27fb6309a2848477257b3d759b917eb2e6ddf86dc3b3144fbb98031e6548ece4ae2eaf14f166e
7
+ data.tar.gz: 494a24787a32f87479e8c984617e1928c54b43864b9a247da042281b138cd48795970e05ebb69b9805b31a8dd239a0c190f5554f9f427b29f81c1b9a42b669d9
data/README.md CHANGED
@@ -45,6 +45,8 @@ defaults:
45
45
  - "3000:3000"
46
46
  volumes:
47
47
  - ".:/app"
48
+ up:
49
+ command: server # `wip up` がコンテナ作成時にイメージへ渡す常駐コマンド(未指定ならイメージの既定 CMD)
48
50
  commands:
49
51
  rails:
50
52
  type: exec
@@ -82,6 +84,8 @@ commands:
82
84
  | `wip doctor` | WSL2、相互運用、WSLC、設定、アーキテクチャ、Git を診断 |
83
85
  | `wip config` | デフォルト適用済み設定(秘密値をマスク) |
84
86
  | `wip build -- --no-cache` | build 定義でイメージをビルド |
87
+ | `wip up [-d]` | `defaults.container` を起動(無ければ `up.command` 付きで作成)。`-d` でバックグラウンド実行 |
88
+ | `wip down` | `defaults.container` を停止・削除 |
85
89
  | `wip exec [--no-interactive] COMMAND...` | 既存コンテナ内で実行 |
86
90
  | `wip run [--no-interactive] COMMAND...` | `--rm` の新規コンテナで実行 |
87
91
  | `wip shell` | 定義済み shell、または `bash`、`sh` の順に起動 |
data/lib/wip/cli.rb CHANGED
@@ -51,6 +51,19 @@ module Wip
51
51
  execute(builder.build(settings: load_config.command('build') || {}, extra: extra))
52
52
  end
53
53
 
54
+ desc 'up', 'Start the configured container, creating it if necessary'
55
+ option :detach, type: :boolean, default: false, aliases: '-d'
56
+ def up
57
+ code = execute(builder.start(detach: options[:detach]), exit_on_failure: false)
58
+ execute(builder.up(detach: options[:detach])) if code != 0
59
+ end
60
+
61
+ desc 'down', 'Stop and remove the configured container'
62
+ def down
63
+ execute(builder.down, exit_on_failure: false)
64
+ execute(builder.remove, exit_on_failure: false)
65
+ end
66
+
54
67
  desc 'exec COMMAND...', 'Execute a command in the running container'
55
68
  option :interactive, type: :boolean, default: true
56
69
  def exec(*command)
@@ -69,7 +82,8 @@ module Wip
69
82
  configured = load_config.command('shell')
70
83
  return execute(builder.custom('shell', [])) if configured
71
84
 
72
- code = execute(builder.exec(['bash'], settings: { 'interactive' => true }, interactive: true))
85
+ code = execute(builder.exec(['bash'], settings: { 'interactive' => true }, interactive: true),
86
+ exit_on_failure: false)
73
87
  execute(builder.exec(['sh'], settings: { 'interactive' => true }, interactive: true)) if code != 0
74
88
  end
75
89
  map 'shell' => :shell_command
@@ -88,9 +102,9 @@ module Wip
88
102
  def resolver = CommandResolver.new
89
103
  def builder = CommandBuilder.new(wslc: resolver.resolve(load_config.wslc_command), config: load_config)
90
104
 
91
- def execute(command)
105
+ def execute(command, exit_on_failure: true)
92
106
  code = CommandRunner.new.run(command)
93
- exit(code) unless code.zero?
107
+ exit(code) if exit_on_failure && !code.zero?
94
108
  code
95
109
  end
96
110
  end
@@ -26,6 +26,30 @@ module Wip
26
26
  command.concat(options(values)).push(required(values, 'image')).concat(arguments)
27
27
  end
28
28
 
29
+ def up(detach: false)
30
+ values = @config.defaults
31
+ command = [@wslc, 'run', '--name', required(values, 'container')]
32
+ command << '-d' if detach
33
+ command << '-it' if !detach && tty?(true)
34
+ command.concat(options(values)).push(required(values, 'image'))
35
+ command.concat(Shellwords.split(@config.up_command.to_s)) if @config.up_command
36
+ command
37
+ end
38
+
39
+ def start(detach: false)
40
+ command = [@wslc, 'start', required(@config.defaults, 'container')]
41
+ command.push('-a', '-i') unless detach
42
+ command
43
+ end
44
+
45
+ def down
46
+ [@wslc, 'stop', required(@config.defaults, 'container')]
47
+ end
48
+
49
+ def remove
50
+ [@wslc, 'remove', '-f', required(@config.defaults, 'container')]
51
+ end
52
+
29
53
  def build(settings:, extra: [])
30
54
  values = @config.defaults.merge(settings)
31
55
  context = values['context'] || '.'
data/lib/wip/config.rb CHANGED
@@ -17,6 +17,7 @@ module Wip
17
17
  def wslc_command = @raw.dig('wslc', 'command') || 'auto'
18
18
  def commands = @raw['commands'] || {}
19
19
  def defaults = DEFAULTS.merge(@raw['defaults'] || {})
20
+ def up_command = @raw.dig('up', 'command')
20
21
 
21
22
  def command(name)
22
23
  entry = commands[name.to_s]
@@ -27,6 +28,7 @@ module Wip
27
28
 
28
29
  def to_h(redact: true)
29
30
  value = { 'version' => 1, 'wslc' => { 'command' => wslc_command }, 'defaults' => defaults,
31
+ 'up' => { 'command' => up_command },
30
32
  'commands' => commands.transform_values { |entry| defaults.merge('type' => 'exec').merge(entry) } }
31
33
  redact ? redact_secrets(value) : value
32
34
  end
@@ -36,6 +38,7 @@ module Wip
36
38
  def validate!
37
39
  raise ConfigError, "Unsupported configuration version: #{@raw['version']}" unless (@raw['version'] || 1) == 1
38
40
  raise ConfigError, 'commands must be a mapping' unless commands.is_a?(Hash)
41
+ raise ConfigError, 'up must be a mapping' if @raw.key?('up') && !@raw['up'].is_a?(Hash)
39
42
 
40
43
  commands.each { |name, entry| validate_command!(name, entry) }
41
44
  end
data/lib/wip/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Wip
4
- VERSION = '0.1.3'
4
+ VERSION = '0.3.0'
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: wslc-wip
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.3
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Wip contributors