Class: UffizziCore::ActivityItemService

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

Constant Summary collapse

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

Class Method Summary collapse

Class Method Details

.create_docker_item!(repo, container) ⇒ Object



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

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

.disable_deployment!(activity_item) ⇒ Object



20
21
22
23
24
25
26
# File 'app/services/uffizzi_core/activity_item_service.rb', line 20

def disable_deployment!(activity_item)
  deployment = activity_item.container.deployment

  activity_item.events.create(state: UffizziCore::Event.state.failed)

  UffizziCore::DeploymentService.disable!(deployment)
end

.fail_deployment!(activity_item) ⇒ Object



28
29
30
31
32
33
34
# File 'app/services/uffizzi_core/activity_item_service.rb', line 28

def fail_deployment!(activity_item)
  deployment = activity_item.container.deployment

  activity_item.events.create(state: UffizziCore::Event.state.failed)

  UffizziCore::DeploymentService.fail!(deployment)
end

.manage_deploy_activity_item(activity_item) ⇒ Object



57
58
59
60
61
62
63
64
65
66
67
68
69
70
# File 'app/services/uffizzi_core/activity_item_service.rb', line 57

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)
  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 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



36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'app/services/uffizzi_core/activity_item_service.rb', line 36

def update_docker_digest!(activity_item)
  container = activity_item.container
  repo = container.repo
  credential = UffizziCore::RepoService.credential(repo)

  digest = case repo.type
           when UffizziCore::Repo::DockerHub.name
             UffizziCore::DockerHubService.digest(credential, activity_item.image, activity_item.tag)
           when UffizziCore::Repo::Azure.name
             UffizziCore::AzureService.digest(credential, activity_item.image, activity_item.tag)
           when UffizziCore::Repo::Google.name
             UffizziCore::GoogleService.digest(credential, activity_item.image, activity_item.tag)
           when UffizziCore::Repo::Amazon.name
             UffizziCore::AmazonService.digest(credential, activity_item.image, activity_item.tag)
  end

  activity_item.update!(digest: digest)

  activity_item
end