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'
VOLUME_TYPE =
'volume'
DEPENDENCY_CONFIG_USE_KIND =
'config_map'
DEPENDENCY_VOLUME_USE_KIND =
'volume'

Class Method Summary collapse

Class Method Details

.base_file_params(dependency, container) ⇒ Object



72
73
74
75
76
77
78
# File 'app/services/uffizzi_core/compose_file/dependencies_service.rb', line 72

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



38
39
40
41
42
43
44
45
46
47
48
# File 'app/services/uffizzi_core/compose_file/dependencies_service.rb', line 38

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



11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'app/services/uffizzi_core/compose_file/dependencies_service.rb', line 11

def build_dependencies(compose_data, compose_path, dependencies_params)
  config_dependencies_params = dependencies_params.select { |d| d[:use_kind] == DEPENDENCY_CONFIG_USE_KIND }
  volume_dependencies_params = dependencies_params.select { |d| d[:use_kind] == DEPENDENCY_VOLUME_USE_KIND }

  dependencies = compose_data[:containers].map do |container|
    env_file_dependencies = build_env_files_dependencies(container, compose_path, config_dependencies_params)
    configs_dependencies = build_configs_dependencies(container, compose_path, config_dependencies_params)
    volumes_dependencies = build_volumes_dependencies(container, compose_path, volume_dependencies_params)

    env_file_dependencies + configs_dependencies + volumes_dependencies
  end

  dependencies.compact.flatten
end

.build_env_files_dependencies(container, compose_path, dependencies_params) ⇒ Object



26
27
28
29
30
31
32
33
34
35
36
# File 'app/services/uffizzi_core/compose_file/dependencies_service.rb', line 26

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



80
81
82
83
# File 'app/services/uffizzi_core/compose_file/dependencies_service.rb', line 80

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

.build_volumes_dependencies(container, compose_path, raw_dependencies) ⇒ Object



50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
# File 'app/services/uffizzi_core/compose_file/dependencies_service.rb', line 50

def build_volumes_dependencies(container, compose_path, raw_dependencies)
  container_volumes = container[:volumes]
  return [] unless container_volumes.present?

  container_volumes
    .select { |c| c[:type] == UffizziCore::ComposeFile::Parsers::Services::VolumesParserService::HOST_VOLUME_TYPE }
    .map do |container_volume|
      detected_raw_dependency = raw_dependencies.detect { |raw_dependency| raw_dependency[:source] == container_volume[:source] }
      builded_source = build_source_path(compose_path, detected_raw_dependency[:source])

      {
        content: detected_raw_dependency[:content],
        path: detected_raw_dependency[:path],
        container_name: container[:container_name],
        source: builded_source,
        raw_source: detected_raw_dependency[:source],
        type: VOLUME_TYPE,
        is_file: detected_raw_dependency[:is_file],
      }
    end
end

.host_volume_binary_content(dependency) ⇒ Object



85
86
87
# File 'app/services/uffizzi_core/compose_file/dependencies_service.rb', line 85

def host_volume_binary_content(dependency)
  Base64.decode64(dependency[:content])
end