Class: ComposeManager

Inherits:
Object
  • Object
show all
Includes:
Thor::Shell
Defined in:
lib/docker-sync/compose.rb

Instance Method Summary collapse

Constructor Details

#initialize(global_options) ⇒ ComposeManager

Returns a new instance of ComposeManager.



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/docker-sync/compose.rb', line 7

def initialize(global_options)
  @global_options = global_options

  ### production docker-compose.yml
  compose_files = [File.expand_path('docker-compose.yml')]
  if @global_options.key?('compose-file-path')
    path = File.expand_path(@global_options['compose-file-path'])
    unless File.exist?(path)
      raise("Your referenced docker-compose file in docker-sync.yml was not found at #{@global_options['compose-file-path']}")
    end
    compose_files = [path]  # replace
  end

  ### development docker-compose-dev.yml
  if @global_options.key?('compose-dev-file-path')
    # explicit path given
    path = File.expand_path(@global_options['compose-dev-file-path'])
    unless File.exist?(path)
      raise("Your referenced docker-compose-dev file in docker-sync.yml was not found at #{@global_options['compose-dev-file-path']}")
    end
    say_status 'ok',"Found explicit docker-compose-dev.yml and using it from #{@global_options['compose-dev-file-path']}", :green
    compose_files.push path  # add
  else
    # try to find docker-compose-dev.yml
    e = compose_files.to_enum
    production_compose_file = File.expand_path(e.peek)
    working_dir = File.dirname(production_compose_file)
    compose_dev_path = "#{working_dir}/docker-compose-dev.yml"
    if File.exist?(compose_dev_path)
      say_status 'ok',"Found implicit docker-compose-dev.yml and using it from #{compose_dev_path}", :green
      compose_files.push compose_dev_path
    end
  end
  @compose_session = Docker::Compose::Session.new(dir:'./', :file => compose_files)
end

Instance Method Details

#cleanObject



53
54
55
# File 'lib/docker-sync/compose.rb', line 53

def clean
  @compose_session.down
end

#runObject



43
44
45
46
47
# File 'lib/docker-sync/compose.rb', line 43

def run
  say_status 'ok','starting compose',:white
  @compose_session.up
  say_status 'success','started compose',:green
end

#stopObject



49
50
51
# File 'lib/docker-sync/compose.rb', line 49

def stop
  @compose_session.stop
end