Class: UffizziCore::ActivityItemService

Inherits:
Object
  • Object
show all
Extended by:
DependencyInjectionConcern
Defined in:
app/services/uffizzi_core/activity_item_service.rb

Constant Summary collapse

COMPLETED_STATES =
['deployed', 'failed', 'cancelled'].freeze

Class Method Summary collapse

Methods included from DependencyInjectionConcern

ci_module, ci_session, controller_settings_service, deployment_memory_module, domain_module, find_build_parser_module, find_ingress_parser_module, find_volume_parser_module, notification_module, password_protection_module, template_memory_module, user_access_module

Class Method Details

.create_docker_item!(repo, container) ⇒ Object



9
10
11
12
13
14
15
16
17
18
19
20
# File 'app/services/uffizzi_core/activity_item_service.rb', line 9

def create_docker_item!(repo, container)
  activity_item_attributes = {
    namespace: repo.namespace,
    name: repo.name,
    container: container,
    deployment_id: container.deployment_id,
    type: UffizziCore::ActivityItem::Docker.name,
    tag: container.tag,
  }

  create_item!(activity_item_attributes)
end

.fail_deployment!(activity_item) ⇒ Object



22
23
24
25
26
27
28
29
# File 'app/services/uffizzi_core/activity_item_service.rb', line 22

def fail_deployment!(activity_item)
  deployment = activity_item.container.deployment
  last_event = activity_item.events.order_by_id.last

  activity_item.events.create(state: UffizziCore::Event.state.failed) unless last_event&.failed?

  UffizziCore::DeploymentService.fail!(deployment)
end

.manage_deploy_activity_item(activity_item) ⇒ Object



43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
# File 'app/services/uffizzi_core/activity_item_service.rb', line 43

def manage_deploy_activity_item(activity_item)
  container = activity_item.container
  deployment = container.deployment
  service = UffizziCore::ManageActivityItemsService.new(deployment)
  container_status_item = service.container_status_item(container)
  return if container_status_item.nil?

  status = container_status_item[:status]
  last_event = activity_item.events.order_by_id.last
  activity_item.events.create(state: status) if last_event&.state != status

  return handle_failed_status(activity_item, deployment) if failed?(status)

  if deployed?(status) && UffizziCore::ContainerService.ingress_container?(container)
    deployment.update!(last_deploy_at: last_event.created_at)
    deployment.deployment_events.create!(deployment_state: status)

    return
  end

  return unless [UffizziCore::Event.state.building, UffizziCore::Event.state.deploying].include?(status)

  UffizziCore::Deployment::ManageDeployActivityItemJob.perform_in(5.seconds, activity_item.id)
end

.update_docker_digest!(activity_item) ⇒ Object



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

def update_docker_digest!(activity_item)
  container = activity_item.container
  repo = container.repo
  credential = UffizziCore::RepoService.credential(repo)
  container_registry_service = UffizziCore::ContainerRegistryService.init_by_subclass(repo.type)
  digest = container_registry_service.digest(credential, activity_item.image, activity_item.tag)

  activity_item.update!(digest: digest)

  activity_item
end