Class: Wip::ComposeBridge
- Inherits:
-
Object
- Object
- Wip::ComposeBridge
- Defined in:
- lib/wip/compose_bridge.rb
Overview
Builds argument arrays for wslc-compose invocations, delegating orchestration to a real compose.yml instead of wip's own dependencies:/network handling.
Constant Summary collapse
- FILENAMES =
%w[compose.yml compose.yaml docker-compose.yml docker-compose.yaml].freeze
- INSTALL_HINT =
No default candidates: wip doesn't favor any one compose-for-wslc implementation. compose.command must name the one you've installed.
<<~HINT.chomp wip doesn't bundle or pin a compose-for-wslc implementation — install one and set compose.command in wip.yml to its binary name or path, e.g.: https://github.com/bacarndiaye/wslc-compose https://github.com/inuyume/wslc-compose HINT
Class Method Summary collapse
- .file_path(config) ⇒ Object
- .for(config, resolver: CommandResolver.new(candidates: [], label: 'compose command', install_hint: INSTALL_HINT)) ⇒ Object
Instance Method Summary collapse
- #down ⇒ Object
- #exec(service, arguments, interactive: true) ⇒ Object
-
#initialize(compose_command:, file:, project: nil) ⇒ ComposeBridge
constructor
A new instance of ComposeBridge.
- #logs(services: [], follow: true) ⇒ Object
- #up(detach: true) ⇒ Object
Constructor Details
#initialize(compose_command:, file:, project: nil) ⇒ ComposeBridge
Returns a new instance of ComposeBridge.
36 37 38 39 40 |
# File 'lib/wip/compose_bridge.rb', line 36 def initialize(compose_command:, file:, project: nil) @compose_command = compose_command @file = file @project = project end |
Class Method Details
.file_path(config) ⇒ Object
24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/wip/compose_bridge.rb', line 24 def self.file_path(config) base = Pathname(config.path).dirname configured = config.compose_file # Relative compose.file is resolved against wip.yml, not the current directory, # so `wip` behaves the same from any subdirectory (matching auto-detection below). return base.join(configured). if configured FILENAMES.map { |name| base.join(name) }.find(&:file?) || raise(ConfigError, "compose mode: no compose file found next to #{config.path} " \ "(looked for #{FILENAMES.join(', ')})") end |
.for(config, resolver: CommandResolver.new(candidates: [], label: 'compose command', install_hint: INSTALL_HINT)) ⇒ Object
18 19 20 21 22 |
# File 'lib/wip/compose_bridge.rb', line 18 def self.for(config, resolver: CommandResolver.new(candidates: [], label: 'compose command', install_hint: INSTALL_HINT)) new(compose_command: resolver.resolve(config.compose_command), file: file_path(config), project: config.compose_project) end |
Instance Method Details
#down ⇒ Object
48 |
# File 'lib/wip/compose_bridge.rb', line 48 def down = base.push('down') |
#exec(service, arguments, interactive: true) ⇒ Object
50 51 52 53 54 |
# File 'lib/wip/compose_bridge.rb', line 50 def exec(service, arguments, interactive: true) command = base.push('exec') command << '-T' unless interactive command.push(service.to_s).concat(arguments) end |
#logs(services: [], follow: true) ⇒ Object
56 57 58 59 60 |
# File 'lib/wip/compose_bridge.rb', line 56 def logs(services: [], follow: true) command = base.push('logs') command << '-f' if follow command.concat(services.map(&:to_s)) end |
#up(detach: true) ⇒ Object
42 43 44 45 46 |
# File 'lib/wip/compose_bridge.rb', line 42 def up(detach: true) command = base.push('up') command << '-d' if detach command end |