Module: Docker::Stack::Util

Included in:
InstallGenerator
Defined in:
lib/generators/docker/stack/util.rb

Constant Summary collapse

COMPOSE_FILE_VERSION =
'3.4'

Class Method Summary collapse

Class Method Details

.included(base) ⇒ Object



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
# File 'lib/generators/docker/stack/util.rb', line 8

def self.included(base)
  base.source_root File.expand_path('templates', __dir__)

  base.no_tasks do
    def compose_file_path(env = @env)
      ".docker-stack/#{project}-#{env}/docker-compose.yml"
    end

    def compose_file_full_path
      File.join(destination_root, compose_file_path)
    end

    def current_service_config
      create_file compose_file_path, empty_service_config.to_yaml unless File.exist?(compose_file_full_path)
      YAML.safe_load(File.read(compose_file_full_path))
    end

    def empty_service_config
      {
        'version'  => COMPOSE_FILE_VERSION,
        'volumes'  => {},
        'services' => {}
      }
    end

    def project
      @project ||= Controller.default_project_name
    end
  end
end