uffizzi_core 0.2.0 → 0.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/app/forms/uffizzi_core/api/cli/v1/compose_file/create_form.rb +0 -2
- data/app/lib/uffizzi_core/concerns/models/account.rb +84 -0
- data/app/lib/uffizzi_core/concerns/models/activity_item.rb +39 -0
- data/app/lib/uffizzi_core/concerns/models/build.rb +47 -0
- data/app/lib/uffizzi_core/concerns/models/comment.rb +20 -0
- data/app/lib/uffizzi_core/concerns/models/compose_file.rb +60 -0
- data/app/lib/uffizzi_core/concerns/models/config_file.rb +21 -0
- data/app/lib/uffizzi_core/concerns/models/container.rb +95 -0
- data/app/lib/uffizzi_core/concerns/models/container_config_file.rb +12 -0
- data/app/lib/uffizzi_core/concerns/models/coupon.rb +9 -0
- data/app/lib/uffizzi_core/concerns/models/credential.rb +65 -0
- data/app/lib/uffizzi_core/concerns/models/deployment.rb +71 -0
- data/app/lib/uffizzi_core/concerns/models/event.rb +17 -0
- data/app/lib/uffizzi_core/concerns/models/invitation.rb +31 -0
- data/app/lib/uffizzi_core/concerns/models/membership.rb +20 -0
- data/app/lib/uffizzi_core/concerns/models/payment.rb +15 -0
- data/app/lib/uffizzi_core/concerns/models/price.rb +13 -0
- data/app/lib/uffizzi_core/concerns/models/product.rb +15 -0
- data/app/lib/uffizzi_core/concerns/models/project.rb +62 -0
- data/app/lib/uffizzi_core/concerns/models/rating.rb +24 -0
- data/app/lib/uffizzi_core/concerns/models/repo.rb +33 -0
- data/app/lib/uffizzi_core/concerns/models/role.rb +21 -0
- data/app/lib/uffizzi_core/concerns/models/secret.rb +13 -0
- data/app/lib/uffizzi_core/concerns/models/template.rb +23 -0
- data/app/lib/uffizzi_core/concerns/models/user.rb +66 -0
- data/app/lib/uffizzi_core/concerns/models/user_project.rb +18 -0
- data/app/models/uffizzi_core/account.rb +1 -79
- data/app/models/uffizzi_core/activity_item.rb +1 -31
- data/app/models/uffizzi_core/build.rb +1 -35
- data/app/models/uffizzi_core/comment.rb +1 -12
- data/app/models/uffizzi_core/compose_file.rb +1 -44
- data/app/models/uffizzi_core/config_file.rb +1 -13
- data/app/models/uffizzi_core/container.rb +1 -85
- data/app/models/uffizzi_core/container_config_file.rb +1 -4
- data/app/models/uffizzi_core/coupon.rb +1 -1
- data/app/models/uffizzi_core/credential.rb +1 -57
- data/app/models/uffizzi_core/deployment.rb +1 -63
- data/app/models/uffizzi_core/event.rb +1 -9
- data/app/models/uffizzi_core/invitation.rb +1 -23
- data/app/models/uffizzi_core/membership.rb +1 -12
- data/app/models/uffizzi_core/payment.rb +1 -7
- data/app/models/uffizzi_core/price.rb +1 -5
- data/app/models/uffizzi_core/product.rb +1 -7
- data/app/models/uffizzi_core/project.rb +1 -54
- data/app/models/uffizzi_core/rating.rb +1 -16
- data/app/models/uffizzi_core/repo.rb +1 -25
- data/app/models/uffizzi_core/role.rb +1 -13
- data/app/models/uffizzi_core/secret.rb +1 -5
- data/app/models/uffizzi_core/template.rb +1 -15
- data/app/models/uffizzi_core/user.rb +1 -58
- data/app/models/uffizzi_core/user_project.rb +1 -10
- data/app/repositories/uffizzi_core/template_repo.rb +14 -6
- data/lib/uffizzi_core/version.rb +1 -1
- data/lib/uffizzi_core.rb +2 -0
- metadata +27 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: adfd2aad21040ef9ab01dbd4057d37185b70a57d7886fad0add89e64ae4a1c77
|
4
|
+
data.tar.gz: d1b593337123b302cf5e5a4986be2806f806a8afd4a7f9292940222e1225c857
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b6d2ee7b78505a764da65fb0e100678b35b9f8e974105b8e1600ee61dd499b3546653a556fa1531bbd14c0a5043fbae85d2f23d3701f209802fdd3e6951d8e7c
|
7
|
+
data.tar.gz: 7fae0d641e8c2ec495fb2250931245a16893a2b9e88564c2e52cba0f94fa1cf9b4da1800cdc3606de53fcb1ea750e5e18bce39af405b34d6ac5cb1b459389334
|
@@ -6,8 +6,6 @@ class UffizziCore::Api::Cli::V1::ComposeFile::CreateForm < UffizziCore::ComposeF
|
|
6
6
|
permit :source, :path, :content
|
7
7
|
|
8
8
|
validates :source, presence: true
|
9
|
-
validates :source, uniqueness: { scope: :project_id, message: 'A compose file with the same source already exists for this project' },
|
10
|
-
if: -> { kind.main? }
|
11
9
|
validates :path, presence: true
|
12
10
|
validates :content, presence: true
|
13
11
|
end
|
@@ -0,0 +1,84 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module UffizziCore::Concerns::Models::Account
|
4
|
+
extend ActiveSupport::Concern
|
5
|
+
|
6
|
+
# rubocop:disable Metrics/BlockLength
|
7
|
+
included do
|
8
|
+
include AASM
|
9
|
+
include UffizziCore::StateMachineConcern
|
10
|
+
extend Enumerize
|
11
|
+
|
12
|
+
self.table_name = UffizziCore.table_names[:accounts]
|
13
|
+
|
14
|
+
enumerize :kind, in: [:personal, :organizational], scope: true, predicates: true
|
15
|
+
validates :kind, presence: true
|
16
|
+
validates :domain, uniqueness: true, if: :domain
|
17
|
+
|
18
|
+
belongs_to :owner, class_name: UffizziCore::User.name, foreign_key: :owner_id
|
19
|
+
|
20
|
+
has_many :memberships, dependent: :destroy
|
21
|
+
has_many :users, through: :memberships
|
22
|
+
has_many :credentials, dependent: :destroy
|
23
|
+
|
24
|
+
has_many :projects, dependent: :destroy
|
25
|
+
has_many :deployments, through: :projects
|
26
|
+
has_many :payments, dependent: :destroy
|
27
|
+
has_many :invitations, as: :entityable
|
28
|
+
|
29
|
+
aasm(:state) do
|
30
|
+
state :active, initial: true
|
31
|
+
state :payment_issue
|
32
|
+
state :disabled
|
33
|
+
state :draft
|
34
|
+
|
35
|
+
event :activate do
|
36
|
+
transitions from: [:payment_issue, :disabled, :draft], to: :active
|
37
|
+
end
|
38
|
+
|
39
|
+
event :raise_payment_issue, before_success: :update_payment_issue_date do
|
40
|
+
transitions from: [:active, :disabled], to: :payment_issue
|
41
|
+
end
|
42
|
+
|
43
|
+
event :disable, after: :disable_projects do
|
44
|
+
transitions from: [:active, :payment_issue], to: :disabled
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
aasm(:sso_state) do
|
49
|
+
state :connection_not_configured, initial: true
|
50
|
+
state :connection_disabled
|
51
|
+
state :connection_active
|
52
|
+
|
53
|
+
event :activate_connection do
|
54
|
+
transitions from: [:connection_not_configured, :connection_disabled], to: :connection_active
|
55
|
+
end
|
56
|
+
|
57
|
+
event :deactivate_connection do
|
58
|
+
transitions from: [:connection_active], to: :connection_disabled
|
59
|
+
end
|
60
|
+
|
61
|
+
event :reset_connection do
|
62
|
+
transitions from: [:connection_active, :connection_disabled], to: :connection_not_configured
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
def update_payment_issue_date
|
67
|
+
update(payment_issue_at: DateTime.current)
|
68
|
+
end
|
69
|
+
|
70
|
+
def active_projects
|
71
|
+
projects.active
|
72
|
+
end
|
73
|
+
|
74
|
+
def disable_projects
|
75
|
+
active_projects.each(&:disable_deployments)
|
76
|
+
end
|
77
|
+
|
78
|
+
# This method is deprecated. Don't use it.
|
79
|
+
def user
|
80
|
+
users.find_by(memberships: { role: UffizziCore::Membership.role.admin })
|
81
|
+
end
|
82
|
+
end
|
83
|
+
# rubocop:enable Metrics/BlockLength
|
84
|
+
end
|
@@ -0,0 +1,39 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module UffizziCore::Concerns::Models::ActivityItem
|
4
|
+
extend ActiveSupport::Concern
|
5
|
+
|
6
|
+
included do
|
7
|
+
include UffizziCore::ActivityItemRepo
|
8
|
+
|
9
|
+
self.table_name = UffizziCore.table_names[:activity_items]
|
10
|
+
|
11
|
+
belongs_to :deployment
|
12
|
+
belongs_to :container
|
13
|
+
belongs_to :build, optional: true
|
14
|
+
|
15
|
+
has_many :events, dependent: :destroy
|
16
|
+
|
17
|
+
scope :docker, -> {
|
18
|
+
where(type: UffizziCore::ActivityItem::Docker.name)
|
19
|
+
}
|
20
|
+
|
21
|
+
scope :github, -> {
|
22
|
+
where(type: UffizziCore::ActivityItem::Github.name)
|
23
|
+
}
|
24
|
+
|
25
|
+
def docker?
|
26
|
+
type == UffizziCore::ActivityItem::Docker.name
|
27
|
+
end
|
28
|
+
|
29
|
+
def image
|
30
|
+
[namespace, name].compact.join('/')
|
31
|
+
end
|
32
|
+
|
33
|
+
def full_image
|
34
|
+
return "#{image}:#{tag}" if docker?
|
35
|
+
|
36
|
+
''
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
@@ -0,0 +1,47 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module UffizziCore::Concerns::Models::Build
|
4
|
+
extend ActiveSupport::Concern
|
5
|
+
|
6
|
+
included do
|
7
|
+
include UffizziCore::BuildRepo
|
8
|
+
|
9
|
+
self.table_name = UffizziCore.table_names[:builds]
|
10
|
+
|
11
|
+
const_set(:BUILDING, 1)
|
12
|
+
const_set(:SUCCESS, 2)
|
13
|
+
const_set(:FAILED, 3)
|
14
|
+
const_set(:TIMEOUT, 4)
|
15
|
+
const_set(:CANCELLED, 5)
|
16
|
+
|
17
|
+
belongs_to :repo
|
18
|
+
|
19
|
+
def successful?
|
20
|
+
status == self.class::SUCCESS
|
21
|
+
end
|
22
|
+
|
23
|
+
def unsuccessful?
|
24
|
+
[self.class::FAILED, self.class::TIMEOUT, self.class::CANCELLED].include?(status)
|
25
|
+
end
|
26
|
+
|
27
|
+
def failed?
|
28
|
+
status == self.class::FAILED
|
29
|
+
end
|
30
|
+
|
31
|
+
def building?
|
32
|
+
status == self.class::BUILDING
|
33
|
+
end
|
34
|
+
|
35
|
+
def timed_out?
|
36
|
+
status == self.class::TIMEOUT
|
37
|
+
end
|
38
|
+
|
39
|
+
def cancelled?
|
40
|
+
status == self.class::CANCELLED
|
41
|
+
end
|
42
|
+
|
43
|
+
def ended?
|
44
|
+
[self.class::SUCCESS, self.class::FAILED, self.class::TIMEOUT, self.class::CANCELLED].include?(status)
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module UffizziCore::Concerns::Models::Comment
|
4
|
+
extend ActiveSupport::Concern
|
5
|
+
|
6
|
+
included do
|
7
|
+
include UffizziCore::CommentRepo
|
8
|
+
|
9
|
+
self.table_name = UffizziCore.table_names[:comments]
|
10
|
+
|
11
|
+
has_ancestry(cache_depth: true)
|
12
|
+
const_set(:MAX_DEPTH_LEVEL, 1)
|
13
|
+
|
14
|
+
belongs_to :user
|
15
|
+
belongs_to :commentable, polymorphic: true
|
16
|
+
|
17
|
+
validates :content, length: { maximum: 1500 }, presence: true
|
18
|
+
validates :ancestry_depth, numericality: { less_than_or_equal_to: self::MAX_DEPTH_LEVEL, only_integer: true }
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,60 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module UffizziCore::Concerns::Models::ComposeFile
|
4
|
+
extend ActiveSupport::Concern
|
5
|
+
|
6
|
+
included do
|
7
|
+
include UffizziCore::ComposeFileRepo
|
8
|
+
include AASM
|
9
|
+
extend Enumerize
|
10
|
+
|
11
|
+
self.table_name = UffizziCore.table_names[:compose_files]
|
12
|
+
|
13
|
+
belongs_to :project
|
14
|
+
belongs_to :added_by, class_name: UffizziCore::User.name, foreign_key: :added_by_id, optional: true
|
15
|
+
|
16
|
+
has_one :template, dependent: :destroy
|
17
|
+
has_many :config_files, dependent: :destroy
|
18
|
+
has_many :deployments, dependent: :nullify
|
19
|
+
|
20
|
+
enumerize :kind, in: [:main, :temporary], predicates: true, scope: :shallow, default: :main
|
21
|
+
|
22
|
+
validates :project, uniqueness: { scope: :project }, if: -> { kind.main? }
|
23
|
+
validates :source, presence: true
|
24
|
+
validate :main_compose_file_uniqueness, on: :create, if: -> { kind.main? }
|
25
|
+
|
26
|
+
aasm(:auto_deploy) do
|
27
|
+
state :disabled, initial: true
|
28
|
+
state :enabled
|
29
|
+
|
30
|
+
event :enable do
|
31
|
+
transitions from: [:disabled], to: :enabled
|
32
|
+
end
|
33
|
+
|
34
|
+
event :disable do
|
35
|
+
transitions from: [:enabled], to: :disabled
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
aasm(:state) do
|
40
|
+
state :valid_file, initial: true
|
41
|
+
state :invalid_file
|
42
|
+
|
43
|
+
event :set_valid do
|
44
|
+
transitions from: [:invalid_file], to: :valid_file
|
45
|
+
end
|
46
|
+
|
47
|
+
event :set_invalid do
|
48
|
+
transitions from: [:valid_file], to: :invalid_file
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
private
|
53
|
+
|
54
|
+
def main_compose_file_uniqueness
|
55
|
+
return unless project.compose_files.main.exists?
|
56
|
+
|
57
|
+
errors.add(:compose_file, 'A compose file already exist for this project')
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module UffizziCore::Concerns::Models::ConfigFile
|
4
|
+
extend ActiveSupport::Concern
|
5
|
+
|
6
|
+
included do
|
7
|
+
include UffizziCore::ConfigFileRepo
|
8
|
+
extend Enumerize
|
9
|
+
|
10
|
+
self.table_name = UffizziCore.table_names[:config_files]
|
11
|
+
|
12
|
+
belongs_to :project
|
13
|
+
belongs_to :added_by, class_name: UffizziCore::User.name, foreign_key: :added_by_id, optional: true
|
14
|
+
belongs_to :compose_file, optional: true
|
15
|
+
|
16
|
+
has_many :container_config_files, dependent: :destroy
|
17
|
+
|
18
|
+
enumerize :kind, in: [:config_map, :secret], default: :config_map, predicates: true
|
19
|
+
enumerize :creation_source, in: [:manual, :compose_file, :system], predicates: true, scope: true
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,95 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module UffizziCore::Concerns::Models::Container
|
4
|
+
extend ActiveSupport::Concern
|
5
|
+
|
6
|
+
# rubocop:disable Metrics/BlockLength
|
7
|
+
included do
|
8
|
+
include UffizziCore::ContainerRepo
|
9
|
+
include AASM
|
10
|
+
include UffizziCore::StateMachineConcern
|
11
|
+
extend Enumerize
|
12
|
+
|
13
|
+
self.table_name = UffizziCore.table_names[:containers]
|
14
|
+
|
15
|
+
enumerize :kind, in: [:internal, :user], predicates: true
|
16
|
+
|
17
|
+
belongs_to :deployment, touch: true
|
18
|
+
belongs_to :repo, optional: true
|
19
|
+
|
20
|
+
has_many :activity_items, dependent: :destroy
|
21
|
+
has_many :container_config_files, dependent: :destroy
|
22
|
+
has_many :config_files, through: :container_config_files
|
23
|
+
|
24
|
+
attribute :public, :boolean, default: false
|
25
|
+
attribute :port, :integer, default: nil
|
26
|
+
|
27
|
+
enumerize :source, in: [:github], skip_validations: true
|
28
|
+
validates :port,
|
29
|
+
presence: true,
|
30
|
+
inclusion: { in: 0..65_535 },
|
31
|
+
uniqueness: { scope: :deployment_id },
|
32
|
+
if: :should_check_port
|
33
|
+
|
34
|
+
after_commit :check_target_port, on: :create
|
35
|
+
|
36
|
+
before_save :update_target_port_value, if: :will_save_change_to_port?
|
37
|
+
before_create :set_defaults
|
38
|
+
|
39
|
+
accepts_nested_attributes_for :repo
|
40
|
+
accepts_nested_attributes_for :container_config_files, allow_destroy: true
|
41
|
+
|
42
|
+
validates :variables, 'uffizzi_core/environment_variable_list': true, allow_nil: true
|
43
|
+
validates :secret_variables, 'uffizzi_core/environment_variable_list': true, allow_nil: true
|
44
|
+
validates :entrypoint, 'uffizzi_core/image_command_args': true, allow_nil: true
|
45
|
+
validates :command, 'uffizzi_core/image_command_args': true, allow_nil: true
|
46
|
+
validates :tag, presence: true
|
47
|
+
|
48
|
+
aasm :continuously_deploy, column: :continuously_deploy do
|
49
|
+
state :disabled, initial: true
|
50
|
+
state :enabled
|
51
|
+
end
|
52
|
+
|
53
|
+
aasm :state, column: :state do
|
54
|
+
state :active, initial: true
|
55
|
+
state :disabled
|
56
|
+
|
57
|
+
event :activate do
|
58
|
+
transitions from: [:disabled], to: :active
|
59
|
+
end
|
60
|
+
|
61
|
+
event :disable, after: :clean do
|
62
|
+
transitions from: [:active], to: :disabled
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
def image_name
|
67
|
+
"#{image}:#{tag}"
|
68
|
+
end
|
69
|
+
|
70
|
+
private
|
71
|
+
|
72
|
+
def should_check_port
|
73
|
+
public && active?
|
74
|
+
end
|
75
|
+
|
76
|
+
def clean
|
77
|
+
update(public: false, port: nil)
|
78
|
+
end
|
79
|
+
|
80
|
+
def set_defaults
|
81
|
+
update_target_port_value
|
82
|
+
end
|
83
|
+
|
84
|
+
def update_target_port_value
|
85
|
+
self.target_port = UffizziCore::ContainerService.target_port_value(self)
|
86
|
+
end
|
87
|
+
|
88
|
+
def check_target_port
|
89
|
+
if target_port && deployment.containers.where(target_port: target_port).size > 1
|
90
|
+
update(target_port: UffizziCore::DeploymentService.find_unused_port(deployment))
|
91
|
+
end
|
92
|
+
end
|
93
|
+
end
|
94
|
+
# rubocop:enable Metrics/BlockLength
|
95
|
+
end
|
@@ -0,0 +1,12 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module UffizziCore::Concerns::Models::ContainerConfigFile
|
4
|
+
extend ActiveSupport::Concern
|
5
|
+
|
6
|
+
included do
|
7
|
+
self.table_name = UffizziCore.table_names[:container_config_files]
|
8
|
+
|
9
|
+
belongs_to :container
|
10
|
+
belongs_to :config_file
|
11
|
+
end
|
12
|
+
end
|
@@ -0,0 +1,65 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module UffizziCore::Concerns::Models::Credential
|
4
|
+
extend ActiveSupport::Concern
|
5
|
+
|
6
|
+
included do
|
7
|
+
include AASM
|
8
|
+
include UffizziCore::CredentialRepo
|
9
|
+
|
10
|
+
self.table_name = UffizziCore.table_names[:credentials]
|
11
|
+
|
12
|
+
belongs_to :account
|
13
|
+
|
14
|
+
before_destroy :remove_token
|
15
|
+
|
16
|
+
validates :registry_url, presence: true
|
17
|
+
|
18
|
+
aasm :state, column: :state do
|
19
|
+
state :not_connected, initial: true
|
20
|
+
state :active
|
21
|
+
state :unauthorized
|
22
|
+
|
23
|
+
event :activate do
|
24
|
+
transitions from: [:not_connected, :unauthorized], to: :active
|
25
|
+
end
|
26
|
+
|
27
|
+
event :unauthorize do
|
28
|
+
transitions from: [:not_connected, :active], to: :unauthorized
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
def github_container_registry?
|
33
|
+
type == UffizziCore::Credential::GithubContainerRegistry.name
|
34
|
+
end
|
35
|
+
|
36
|
+
def docker_hub?
|
37
|
+
type == UffizziCore::Credential::DockerHub.name
|
38
|
+
end
|
39
|
+
|
40
|
+
def azure?
|
41
|
+
type == UffizziCore::Credential::Azure.name
|
42
|
+
end
|
43
|
+
|
44
|
+
def google?
|
45
|
+
type == UffizziCore::Credential::Google.name
|
46
|
+
end
|
47
|
+
|
48
|
+
def amazon?
|
49
|
+
type == UffizziCore::Credential::Amazon.name
|
50
|
+
end
|
51
|
+
|
52
|
+
private
|
53
|
+
|
54
|
+
def remove_token
|
55
|
+
account.projects.find_each do |project|
|
56
|
+
project.deployments.find_each do |deployment|
|
57
|
+
containers = deployment.containers
|
58
|
+
attributes = { continuously_deploy: UffizziCore::Container::STATE_DISABLED }
|
59
|
+
|
60
|
+
containers.with_docker_hub_repo.update_all(attributes) if docker_hub?
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
@@ -0,0 +1,71 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module UffizziCore::Concerns::Models::Deployment
|
4
|
+
extend ActiveSupport::Concern
|
5
|
+
|
6
|
+
included do
|
7
|
+
include AASM
|
8
|
+
include UffizziCore::StateMachineConcern
|
9
|
+
include UffizziCore::DeploymentRepo
|
10
|
+
extend Enumerize
|
11
|
+
|
12
|
+
self.table_name = UffizziCore.table_names[:deployments]
|
13
|
+
|
14
|
+
enumerize :kind, in: [:standard, :performance, :enterprise, :free], predicates: true, default: :standard
|
15
|
+
|
16
|
+
belongs_to :project, touch: true
|
17
|
+
belongs_to :deployed_by, class_name: UffizziCore::User.name, foreign_key: :deployed_by_id, optional: true
|
18
|
+
belongs_to :template, optional: true
|
19
|
+
belongs_to :compose_file, optional: true
|
20
|
+
|
21
|
+
has_many :credentials, through: :project
|
22
|
+
has_many :containers, dependent: :destroy, index_errors: true
|
23
|
+
has_many :activity_items, dependent: :destroy
|
24
|
+
|
25
|
+
has_one :ingress_container, -> { where(receive_incoming_requests: true) }, class_name: UffizziCore::Container.name
|
26
|
+
|
27
|
+
validates :kind, presence: true
|
28
|
+
|
29
|
+
enumerize :creation_source, in: [:manual, :continuous_preview, :compose_file_manual, :compose_file_continuous_preview],
|
30
|
+
predicates: true, scope: true, default: :manual
|
31
|
+
|
32
|
+
accepts_nested_attributes_for :containers, allow_destroy: true
|
33
|
+
|
34
|
+
after_destroy_commit :clean
|
35
|
+
|
36
|
+
def active_containers
|
37
|
+
containers.active
|
38
|
+
end
|
39
|
+
|
40
|
+
aasm(:state) do
|
41
|
+
state :active, initial: true
|
42
|
+
state :failed
|
43
|
+
state :disabled
|
44
|
+
|
45
|
+
event :activate do
|
46
|
+
transitions from: [:disabled], to: :active
|
47
|
+
end
|
48
|
+
|
49
|
+
event :fail, after: :after_fail do
|
50
|
+
transitions from: [:active], to: :failed
|
51
|
+
end
|
52
|
+
|
53
|
+
event :disable, after: :after_disable do
|
54
|
+
transitions from: [:active, :failed], to: :disabled
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
def after_disable
|
59
|
+
clean
|
60
|
+
end
|
61
|
+
|
62
|
+
def after_fail
|
63
|
+
active_containers.each(&:disable!)
|
64
|
+
end
|
65
|
+
|
66
|
+
def clean
|
67
|
+
active_containers.each(&:disable!)
|
68
|
+
UffizziCore::Deployment::DeleteJob.perform_async(id)
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module UffizziCore::Concerns::Models::Event
|
4
|
+
extend ActiveSupport::Concern
|
5
|
+
|
6
|
+
included do
|
7
|
+
include UffizziCore::EventRepo
|
8
|
+
extend Enumerize
|
9
|
+
|
10
|
+
self.table_name = UffizziCore.table_names[:events]
|
11
|
+
|
12
|
+
enumerize :state, in: [:queued, :successful, :deployed, :failed, :building, :timeout, :cancelled, :deploying], predicates: true,
|
13
|
+
scope: true
|
14
|
+
|
15
|
+
belongs_to :activity_item, touch: true
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module UffizziCore::Concerns::Models::Invitation
|
4
|
+
extend ActiveSupport::Concern
|
5
|
+
|
6
|
+
included do
|
7
|
+
include AASM
|
8
|
+
include UffizziCore::StateMachineConcern
|
9
|
+
extend Enumerize
|
10
|
+
|
11
|
+
self.table_name = UffizziCore.table_names[:invitations]
|
12
|
+
|
13
|
+
enumerize :role, in: [:admin, :developer, :viewer], predicates: true
|
14
|
+
|
15
|
+
belongs_to :entityable, polymorphic: true
|
16
|
+
belongs_to :invited_by, class_name: UffizziCore::User.name, foreign_key: :invited_by_id
|
17
|
+
belongs_to :invitee, class_name: UffizziCore::User.name, foreign_key: :invitee_id, optional: true
|
18
|
+
|
19
|
+
validates :email, presence: true, 'uffizzi_core/email': true
|
20
|
+
validates :token, presence: true, uniqueness: true
|
21
|
+
|
22
|
+
aasm(:status) do
|
23
|
+
state :pending, initial: true
|
24
|
+
state :accepted
|
25
|
+
|
26
|
+
event :accept do
|
27
|
+
transitions from: :pending, to: :accepted
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module UffizziCore::Concerns::Models::Membership
|
4
|
+
extend ActiveSupport::Concern
|
5
|
+
|
6
|
+
included do
|
7
|
+
include UffizziCore::MembershipRepo
|
8
|
+
extend Enumerize
|
9
|
+
|
10
|
+
self.table_name = UffizziCore.table_names[:memberships]
|
11
|
+
|
12
|
+
enumerize :role, in: [:admin, :developer, :viewer], predicates: true
|
13
|
+
validates :role, presence: true
|
14
|
+
|
15
|
+
belongs_to :account
|
16
|
+
belongs_to :user
|
17
|
+
|
18
|
+
validates :role, presence: true
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module UffizziCore::Concerns::Models::Payment
|
4
|
+
extend ActiveSupport::Concern
|
5
|
+
|
6
|
+
included do
|
7
|
+
self.table_name = UffizziCore.table_names[:payments]
|
8
|
+
|
9
|
+
belongs_to :account
|
10
|
+
|
11
|
+
scope :succeeded, -> { where(status: :succeeded) }
|
12
|
+
scope :pending, -> { where(status: :pending) }
|
13
|
+
scope :failed, -> { where(status: :failed) }
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module UffizziCore::Concerns::Models::Product
|
4
|
+
extend ActiveSupport::Concern
|
5
|
+
|
6
|
+
included do
|
7
|
+
include UffizziCore::ProductRepo
|
8
|
+
|
9
|
+
self.table_name = UffizziCore.table_names[:products]
|
10
|
+
|
11
|
+
has_one :price, dependent: :destroy
|
12
|
+
|
13
|
+
UffizziCore::Product.inheritance_column = :sti
|
14
|
+
end
|
15
|
+
end
|