class Dip::Commands::Compose
Constants
- DOCKER_EMBEDDED_DNS
Attributes
argv[R]
config[R]
shell[R]
Public Class Methods
new(*argv, shell: true)
click to toggle source
# File lib/dip/commands/compose.rb, line 15 def initialize(*argv, shell: true) @argv = argv @shell = shell @config = ::Dip.config.compose || {} end
Public Instance Methods
execute()
click to toggle source
# File lib/dip/commands/compose.rb, line 21 def execute Dip.env["DIP_DNS"] ||= find_dns compose_argv = Array(find_files) + Array(cli_options) + argv exec_program("docker-compose", compose_argv, shell: shell) end
Private Instance Methods
cli_options()
click to toggle source
# File lib/dip/commands/compose.rb, line 47 def cli_options %i[project_name project_directory].flat_map do |name| next unless (value = config[name]) next unless value.is_a?(String) value = ::Dip.env.interpolate(value) ["--#{name.to_s.tr("_", "-")}", value] end.compact end
find_dns()
click to toggle source
# File lib/dip/commands/compose.rb, line 57 def find_dns name = Dip.env["DNSDOCK_CONTAINER"] || "dnsdock" net = Dip.env["FRONTEND_NETWORK"] || "frontend" IO.pipe do |r, w| Dip::Commands::DNS::IP .new(name: name, net: net) .execute(out: w, err: File::NULL, panic: false) w.close_write ip = r.readlines[0].to_s.strip ip.empty? ? DOCKER_EMBEDDED_DNS : ip end end
find_files()
click to toggle source
# File lib/dip/commands/compose.rb, line 31 def find_files return unless (files = config[:files]) if files.is_a?(Array) files.each_with_object([]) do |file_path, memo| file_path = ::Dip.env.interpolate(file_path) file_path = Pathname.new(file_path) file_path = Dip.config.file_path.parent.join(file_path).expand_path if file_path.relative? next unless file_path.exist? memo << "--file" memo << Shellwords.escape(file_path.to_s) end end end