module DockerCompose

Attributes

project_name[RW]
yaml[RW]
yaml_path[RW]

Public Class Methods

delete(options = {}) click to toggle source

Deletes the set of containers listed in your compose file.

@param options [Hash] @return [String]

@example

DockerCompose.delete
# File lib/docker_compose_ruby.rb, line 66
def delete(options = {})
  options = nil if options.empty?
  compose('delete',options)
end
pull(options = {}) click to toggle source

Ups the set of containers listed in your compose file.

@param options [Hash] @return [String]

@example

DockerCompose.up
# File lib/docker_compose_ruby.rb, line 54
def pull(options = {})
  options = nil if options.empty?
  compose('pull',options)
end
set_project_name(name) click to toggle source

Set Specific compose project name.

@param name [String] @return [String]

@example

DockerCompose.set_project_name('test_project')
# File lib/docker_compose_ruby.rb, line 30
def set_project_name(name)
  @project_name = "-p #{name}"
  name
end
set_yaml_path(path) click to toggle source

Set Path to Docker Compose Yaml File.

@param path [String] @return [String]

@example

DockerCompose.set_yaml_path('/Users/test/projects/docker-compose.yml')
# File lib/docker_compose_ruby.rb, line 18
def set_yaml_path(path)
  @yaml_path = "-f #{path}"
  @yaml = YAML.load_file(path)
end
start(options = {}) click to toggle source

Starts the set of containers listed in your compose file.

@param options [Hash] @return [String]

@example

DockerCompose.up
# File lib/docker_compose_ruby.rb, line 90
def start(options = {})
  options = nil if options.empty?
  compose('start', options)
end
stop(options = {}) click to toggle source

Stops the set of containers listed in your compose file.

@param options [Hash] @return [String]

@example

DockerCompose.stop
# File lib/docker_compose_ruby.rb, line 78
def stop(options = {})
  options = nil if options.empty?
  compose('stop', options)
end
up(options = {}) click to toggle source

Ups the set of containers listed in your compose file.

@param options [Hash] @return [String]

@example

DockerCompose.up
# File lib/docker_compose_ruby.rb, line 42
def up(options = {})
  options = nil if options.empty?
  compose('up',options)
end
version() click to toggle source

Displays the current version of Docker compose

@param options [Hash] @return [String]

@example

DockerCompose.version
# File lib/docker_compose_ruby.rb, line 102
def version
  compose('-v')
end

Private Class Methods

compose(command, options) click to toggle source
# File lib/docker_compose_ruby.rb, line 107
def compose(command, options)
  case command
  when 'up'
    system "docker-compose #{options} #{@yaml_path} #{@project_name} #{command} -d"
  when 'delete'
    system "docker-compose #{options} #{@yaml_path} #{@project_name} kill"
    system "docker-compose #{options} #{@yaml_path} #{@project_name} rm -f"
  when 'stop', 'start', 'version', 'pull'
    system "docker-compose #{options} #{@yaml_path} #{@project_name} #{command}"
  end
end