Class: UffizziCore::ComposeFile::DependenciesService

Inherits:
Object
  • Object
show all
Defined in:
app/services/uffizzi_core/compose_file/dependencies_service.rb

Constant Summary collapse

ENV_FILE_TYPE =
'env_file'
CONFIG_TYPE =
'config'

Class Method Summary collapse

Class Method Details

.base_file_params(dependency, container) ⇒ Object



43
44
45
46
47
48
49
# File 'app/services/uffizzi_core/compose_file/dependencies_service.rb', line 43

def base_file_params(dependency, container)
  {
    content: dependency[:content],
    path: dependency[:path],
    container_name: container[:container_name],
  }
end

.build_configs_dependencies(container, compose_path, dependencies_params) ⇒ Object



31
32
33
34
35
36
37
38
39
40
41
# File 'app/services/uffizzi_core/compose_file/dependencies_service.rb', line 31

def build_configs_dependencies(container, compose_path, dependencies_params)
  configs = container[:configs]
  return [] unless configs.present?

  configs.map do |config|
    dependency = dependencies_params.detect { |item| item[:path] == config[:source] }
    source = build_source_path(compose_path, dependency[:path])

    base_file_params(dependency, container).merge(source: source, type: CONFIG_TYPE)
  end
end

.build_dependencies(compose_data, compose_path, dependencies_params) ⇒ Object



8
9
10
11
12
13
14
15
16
17
# File 'app/services/uffizzi_core/compose_file/dependencies_service.rb', line 8

def build_dependencies(compose_data, compose_path, dependencies_params)
  dependencies = compose_data[:containers].map do |container|
    env_file_dependencies = build_env_files_dependencies(container, compose_path, dependencies_params)
    configs_dependencies = build_configs_dependencies(container, compose_path, dependencies_params)

    env_file_dependencies + configs_dependencies
  end

  dependencies.compact.flatten
end

.build_env_files_dependencies(container, compose_path, dependencies_params) ⇒ Object



19
20
21
22
23
24
25
26
27
28
29
# File 'app/services/uffizzi_core/compose_file/dependencies_service.rb', line 19

def build_env_files_dependencies(container, compose_path, dependencies_params)
  env_files = container[:env_file]
  return [] unless env_files.present?

  env_files.map do |path|
    dependency = dependencies_params.detect { |item| item[:path] == path }
    source = build_source_path(compose_path, path)

    base_file_params(dependency, container).merge(source: source, type: ENV_FILE_TYPE)
  end
end

.build_source_path(compose_path, dependency_path) ⇒ Object



51
52
53
54
# File 'app/services/uffizzi_core/compose_file/dependencies_service.rb', line 51

def build_source_path(compose_path, dependency_path)
  prepared_compose_path = Pathname.new(compose_path).basename.to_s
  "#{prepared_compose_path}/#{dependency_path}"
end