Module: UffizziCore::ControllerService

Defined in:
app/services/uffizzi_core/controller_service.rb

Class Method Summary collapse

Class Method Details

.apply_config_file(deployment, config_file) ⇒ Object



5
6
7
8
9
10
11
# File 'app/services/uffizzi_core/controller_service.rb', line 5

def apply_config_file(deployment, config_file)
  body = {
    config_file: UffizziCore::Controller::ApplyConfigFile::ConfigFileSerializer.new(config_file).as_json,
  }

  controller_client.apply_config_file(deployment_id: deployment.id, config_file_id: config_file.id, body: body)
end

.apply_credential(deployment, credential) ⇒ Object



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

def apply_credential(deployment, credential)
  image = if credential.github_container_registry?
    deployment.containers.by_repo_type(UffizziCore::Repo::GithubContainerRegistry.name).first&.image
  end

  options = { image: image }

  body = UffizziCore::Controller::CreateCredential::CredentialSerializer.new(credential, options).as_json
  controller_client.apply_credential(deployment_id: deployment.id, body: body)
end

.create_deployment(deployment) ⇒ Object



13
14
15
16
# File 'app/services/uffizzi_core/controller_service.rb', line 13

def create_deployment(deployment)
  body = UffizziCore::Controller::CreateDeployment::DeploymentSerializer.new(deployment).as_json
  controller_client.create_deployment(deployment_id: deployment.id, body: body)
end

.delete_credential(deployment, credential) ⇒ Object



38
39
40
# File 'app/services/uffizzi_core/controller_service.rb', line 38

def delete_credential(deployment, credential)
  controller_client.delete_credential(deployment_id: deployment.id, credential_id: credential.id)
end

.delete_deployment(deployment_id) ⇒ Object



23
24
25
# File 'app/services/uffizzi_core/controller_service.rb', line 23

def delete_deployment(deployment_id)
  controller_client.delete_deployment(deployment_id: deployment_id)
end

.deploy_containers(deployment, containers) ⇒ Object



42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'app/services/uffizzi_core/controller_service.rb', line 42

def deploy_containers(deployment, containers)
  containers = containers.map do |container|
    UffizziCore::Controller::DeployContainers::ContainerSerializer.new(container).as_json(include: '**')
  end
  credentials = deployment.credentials.deployable.map do |credential|
    UffizziCore::Controller::DeployContainers::CredentialSerializer.new(credential).as_json
  end

  body = {
    containers: containers,
    credentials: credentials,
    deployment_url: UffizziCore::DeploymentService.build_preview_url(deployment),
  }

  controller_client.deploy_containers(deployment_id: deployment.id, body: body)
end

.deployment_exists?(deployment) ⇒ Boolean

Returns:

  • (Boolean)


59
60
61
# File 'app/services/uffizzi_core/controller_service.rb', line 59

def deployment_exists?(deployment)
  controller_client.deployment(deployment_id: deployment.id).code == 200
end

.fetch_deployment_events(deployment) ⇒ Object



63
64
65
# File 'app/services/uffizzi_core/controller_service.rb', line 63

def fetch_deployment_events(deployment)
  request_events(deployment) || []
end

.fetch_namespace(deployment) ⇒ Object



72
73
74
# File 'app/services/uffizzi_core/controller_service.rb', line 72

def fetch_namespace(deployment)
  controller_client.deployment(deployment_id: deployment.id).result || nil
end

.fetch_pods(deployment) ⇒ Object



67
68
69
70
# File 'app/services/uffizzi_core/controller_service.rb', line 67

def fetch_pods(deployment)
  pods = controller_client.deployment_containers(deployment_id: deployment.id).result || []
  pods.filter { |pod| pod..name.start_with?(Settings.controller.namespace_prefix) }
end

.update_deployment(deployment) ⇒ Object



18
19
20
21
# File 'app/services/uffizzi_core/controller_service.rb', line 18

def update_deployment(deployment)
  body = UffizziCore::Controller::UpdateDeployment::DeploymentSerializer.new(deployment).as_json
  controller_client.update_deployment(deployment_id: deployment.id, body: body)
end