class Dockmeister::Cli

Constants

DOCKER_COMPOSE_FILENAME
DOCKMEISTER_CONFIGURATION_FILE

Public Class Methods

new(base_path) click to toggle source
# File lib/dockmeister/cli.rb, line 8
def initialize(base_path)
  @base_path = base_path
  @services = load_config["services"]
end

Public Instance Methods

build(*options) click to toggle source
# File lib/dockmeister/cli.rb, line 18
def build(*options)
  compose

  Dockmeister::ScriptRunner.new(@base_path, @services).pre_build!

  unless Kernel.system(command_with_options("build", options))
    puts "Failed to build the Docker containers."
    exit 1
  end

  Dockmeister::ScriptRunner.new(@base_path, @services).post_build!
end
compose(*options) click to toggle source
# File lib/dockmeister/cli.rb, line 13
def compose(*options)
  composed = Dockmeister::Composer.new(@base_path, @services).compose
  File.open(compose_file_path, "w") { |f| f.write(composed.to_yaml) }
end
compose_command() click to toggle source
# File lib/dockmeister/cli.rb, line 35
def compose_command
  "docker-compose --file #{compose_file_path}"
end
up(*options) click to toggle source
# File lib/dockmeister/cli.rb, line 31
def up(*options)
  Kernel.exec(command_with_options("up", options))
end

Private Instance Methods

command_with_options(command, options) click to toggle source
# File lib/dockmeister/cli.rb, line 45
def command_with_options(command, options)
  "#{compose_command} #{command} #{options.join(" ")}".strip
end
compose_file_path() click to toggle source
# File lib/dockmeister/cli.rb, line 41
def compose_file_path
  File.join(@base_path, DOCKER_COMPOSE_FILENAME)
end
load_config() click to toggle source
# File lib/dockmeister/cli.rb, line 49
def load_config
  file = File.join(@base_path, DOCKMEISTER_CONFIGURATION_FILE)

  unless File.exists?(file)
    puts "Missing dockmeister.yml configuration file"
    exit 1
  end

  config = ::YAML.load_file(file)

  unless config
    puts "Invalid dockmeister.yml configuration file"
    exit 1
  end

  config
end