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
@@ -0,0 +1,62 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module UffizziCore::Concerns::Models::Project
|
4
|
+
extend ActiveSupport::Concern
|
5
|
+
|
6
|
+
included do
|
7
|
+
include AASM
|
8
|
+
include UffizziCore::StateMachineConcern
|
9
|
+
include UffizziCore::ProjectRepo
|
10
|
+
|
11
|
+
self.table_name = UffizziCore.table_names[:projects]
|
12
|
+
|
13
|
+
belongs_to :account
|
14
|
+
|
15
|
+
has_many :repos
|
16
|
+
has_many :deployments, dependent: :destroy
|
17
|
+
has_many :user_projects, dependent: :destroy
|
18
|
+
has_many :users, through: :user_projects
|
19
|
+
has_many :invitations, as: :entityable
|
20
|
+
has_many :config_files, dependent: :destroy
|
21
|
+
has_many :templates, dependent: :destroy
|
22
|
+
has_many :credentials, through: :account
|
23
|
+
has_many :compose_files, dependent: :destroy
|
24
|
+
has_many :secrets, dependent: :destroy, as: :resource
|
25
|
+
|
26
|
+
validates :name, presence: true, uniqueness: { scope: :account, message: 'Name already exists' }
|
27
|
+
validates :slug, presence: true, uniqueness: { message: 'Project slug already taken' }
|
28
|
+
|
29
|
+
aasm(:state) do
|
30
|
+
state :active, initial: true
|
31
|
+
state :disabled
|
32
|
+
|
33
|
+
event :activate do
|
34
|
+
transitions from: [:disabled], to: :active
|
35
|
+
end
|
36
|
+
|
37
|
+
event :disable, after: :after_disable do
|
38
|
+
transitions from: [:active], to: :disabled
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
def after_disable
|
43
|
+
update(name: "#{name} deleted #{DateTime.current.strftime('%H:%M:%S-%m%d%Y')}")
|
44
|
+
update(slug: "#{slug} deleted #{DateTime.current.strftime('%H:%M:%S-%m%d%Y')}")
|
45
|
+
disable_deployments
|
46
|
+
end
|
47
|
+
|
48
|
+
def active_deployments
|
49
|
+
deployments.active
|
50
|
+
end
|
51
|
+
|
52
|
+
def disable_deployments
|
53
|
+
active_deployments.each do |deployment|
|
54
|
+
UffizziCore::DeploymentService.disable!(deployment)
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
def compose_file
|
59
|
+
compose_files.main.first
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module UffizziCore::Concerns::Models::Rating
|
4
|
+
extend ActiveSupport::Concern
|
5
|
+
|
6
|
+
included do
|
7
|
+
include AASM
|
8
|
+
|
9
|
+
self.table_name = UffizziCore.table_names[:ratings]
|
10
|
+
|
11
|
+
aasm(:state) do
|
12
|
+
state :active, initial: true
|
13
|
+
state :disabled
|
14
|
+
|
15
|
+
event :activate do
|
16
|
+
transitions from: [:disabled], to: :active
|
17
|
+
end
|
18
|
+
|
19
|
+
event :disable do
|
20
|
+
transitions from: [:active], to: :disabled
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module UffizziCore::Concerns::Models::Repo
|
4
|
+
extend ActiveSupport::Concern
|
5
|
+
|
6
|
+
included do
|
7
|
+
extend Enumerize
|
8
|
+
include UffizziCore::RepoRepo
|
9
|
+
|
10
|
+
self.table_name = UffizziCore.table_names[:repos]
|
11
|
+
|
12
|
+
enumerize :kind, in: [:buildpacks18, :dockerfile, :dotnet, :gatsby, :barestatic], predicates: true
|
13
|
+
|
14
|
+
belongs_to :project
|
15
|
+
has_one :container, inverse_of: :repo, dependent: :destroy
|
16
|
+
has_many :builds, dependent: :destroy
|
17
|
+
|
18
|
+
validates :dockerfile_path, presence: true, if: :dockerfile?
|
19
|
+
validates :delete_preview_after, numericality: { greater_than: 0, only_integer: true }, allow_nil: true
|
20
|
+
|
21
|
+
def docker_hub?
|
22
|
+
type == UffizziCore::Repo::DockerHub.name
|
23
|
+
end
|
24
|
+
|
25
|
+
def azure?
|
26
|
+
type == UffizziCore::Repo::Azure.name
|
27
|
+
end
|
28
|
+
|
29
|
+
def google?
|
30
|
+
type == UffizziCore::Repo::Google.name
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module UffizziCore::Concerns::Models::Role
|
4
|
+
extend ActiveSupport::Concern
|
5
|
+
|
6
|
+
included do
|
7
|
+
self.table_name = UffizziCore.table_names[:roles]
|
8
|
+
|
9
|
+
has_and_belongs_to_many :users, join_table: UffizziCore.table_names[:users_roles]
|
10
|
+
|
11
|
+
belongs_to :resource,
|
12
|
+
polymorphic: true,
|
13
|
+
optional: true
|
14
|
+
|
15
|
+
validates :resource_type,
|
16
|
+
inclusion: { in: Rolify.resource_types },
|
17
|
+
allow_nil: true
|
18
|
+
|
19
|
+
scopify
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module UffizziCore::Concerns::Models::Secret
|
4
|
+
extend ActiveSupport::Concern
|
5
|
+
|
6
|
+
included do
|
7
|
+
self.table_name = UffizziCore.table_names[:secrets]
|
8
|
+
|
9
|
+
belongs_to :resource, polymorphic: true
|
10
|
+
|
11
|
+
validates :name, presence: true, uniqueness: { scope: :resource }
|
12
|
+
end
|
13
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module UffizziCore::Concerns::Models::Template
|
4
|
+
extend ActiveSupport::Concern
|
5
|
+
|
6
|
+
included do
|
7
|
+
include UffizziCore::TemplateRepo
|
8
|
+
extend Enumerize
|
9
|
+
|
10
|
+
self.table_name = UffizziCore.table_names[:templates]
|
11
|
+
|
12
|
+
belongs_to :added_by, class_name: UffizziCore::User.name, foreign_key: :added_by_id
|
13
|
+
belongs_to :project, touch: true
|
14
|
+
belongs_to :compose_file, optional: true
|
15
|
+
|
16
|
+
has_many :deployments, dependent: :nullify
|
17
|
+
|
18
|
+
enumerize :creation_source, in: [:manual, :compose_file, :system], predicates: true, scope: true
|
19
|
+
|
20
|
+
validates :name, presence: true
|
21
|
+
validates :name, uniqueness: { scope: :project }, if: -> { compose_file.blank? || compose_file.kind.main? }
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,66 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module UffizziCore::Concerns::Models::User
|
4
|
+
extend ActiveSupport::Concern
|
5
|
+
|
6
|
+
included do
|
7
|
+
include AASM
|
8
|
+
include ActiveModel::Validations
|
9
|
+
include UffizziCore::StateMachineConcern
|
10
|
+
include UffizziCore::HashidConcern
|
11
|
+
include UffizziCore::UserRepo
|
12
|
+
extend Enumerize
|
13
|
+
|
14
|
+
self.table_name = UffizziCore.table_names[:users]
|
15
|
+
|
16
|
+
rolify({ role_cname: UffizziCore::Role.name, role_join_table_name: UffizziCore.table_names[:users_roles] })
|
17
|
+
|
18
|
+
has_secure_password
|
19
|
+
|
20
|
+
validates :email, presence: true, 'uffizzi_core/email': true, uniqueness: { case_sensitive: false }
|
21
|
+
validates :password, allow_nil: true, length: { minimum: 8 }, on: :update
|
22
|
+
|
23
|
+
has_many :memberships, dependent: :destroy
|
24
|
+
has_many :accounts, through: :memberships
|
25
|
+
has_many :user_projects, dependent: :destroy
|
26
|
+
has_many :projects, through: :user_projects
|
27
|
+
|
28
|
+
has_one_attached :avatar
|
29
|
+
|
30
|
+
enumerize :creation_source, in: UffizziCore.user_creation_sources, predicates: true
|
31
|
+
|
32
|
+
def organizational_account
|
33
|
+
accounts.find_by(kind: UffizziCore::Account.kind.organizational)
|
34
|
+
end
|
35
|
+
|
36
|
+
def active_projects
|
37
|
+
projects.active
|
38
|
+
end
|
39
|
+
|
40
|
+
def deployments
|
41
|
+
UffizziCore::Deployment.where(project_id: active_projects)
|
42
|
+
end
|
43
|
+
|
44
|
+
def full_name
|
45
|
+
"#{first_name} #{last_name}"
|
46
|
+
end
|
47
|
+
|
48
|
+
aasm(:state) do
|
49
|
+
state :initial, initial: true
|
50
|
+
state :active
|
51
|
+
state :disabled
|
52
|
+
|
53
|
+
event :activate do
|
54
|
+
transitions from: [:initial, :disabled], to: :active
|
55
|
+
end
|
56
|
+
|
57
|
+
event :disable do
|
58
|
+
transitions from: [:initial, :active], to: :disabled
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
def admin_access_to_project?(project)
|
63
|
+
projects.by_ids(project).by_accounts(memberships.by_role_admin.select(:account_id)).exists?
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module UffizziCore::Concerns::Models::UserProject
|
4
|
+
extend ActiveSupport::Concern
|
5
|
+
|
6
|
+
included do
|
7
|
+
extend Enumerize
|
8
|
+
|
9
|
+
self.table_name = UffizziCore.table_names[:user_projects]
|
10
|
+
|
11
|
+
enumerize :role, in: UffizziCore.user_project_roles, predicates: true
|
12
|
+
validates :role, presence: true
|
13
|
+
|
14
|
+
belongs_to :user
|
15
|
+
belongs_to :project
|
16
|
+
belongs_to :invited_by, class_name: UffizziCore::User.name, foreign_key: :invited_by_id, optional: true
|
17
|
+
end
|
18
|
+
end
|
@@ -1,83 +1,5 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
class UffizziCore::Account < UffizziCore::ApplicationRecord
|
4
|
-
include
|
5
|
-
include UffizziCore::StateMachineConcern
|
6
|
-
extend Enumerize
|
7
|
-
|
8
|
-
self.table_name = UffizziCore.table_names[:accounts]
|
9
|
-
|
10
|
-
enumerize :kind, in: [:personal, :organizational], scope: true, predicates: true
|
11
|
-
validates :kind, presence: true
|
12
|
-
validates :domain, uniqueness: true, if: :domain
|
13
|
-
|
14
|
-
belongs_to :owner, class_name: UffizziCore::User.name, foreign_key: :owner_id
|
15
|
-
|
16
|
-
has_many :memberships, dependent: :destroy
|
17
|
-
has_many :users, through: :memberships
|
18
|
-
has_many :credentials, dependent: :destroy
|
19
|
-
|
20
|
-
has_many :projects, dependent: :destroy
|
21
|
-
has_many :deployments, through: :projects
|
22
|
-
has_many :payments, dependent: :destroy
|
23
|
-
has_many :invitations, as: :entityable
|
24
|
-
|
25
|
-
aasm(:state) do
|
26
|
-
state :active, initial: true
|
27
|
-
state :payment_issue
|
28
|
-
state :disabled
|
29
|
-
state :draft
|
30
|
-
|
31
|
-
# next states should be removed after migration
|
32
|
-
state :trial
|
33
|
-
state :trial_expired
|
34
|
-
state :past_due
|
35
|
-
|
36
|
-
event :activate do
|
37
|
-
transitions from: [:payment_issue, :disabled, :trial, :trial_expired, :past_due, :draft], to: :active
|
38
|
-
end
|
39
|
-
|
40
|
-
event :raise_payment_issue, before_success: :update_payment_issue_date do
|
41
|
-
transitions from: [:active, :trial, :trial_expired, :past_due, :disabled], to: :payment_issue
|
42
|
-
end
|
43
|
-
|
44
|
-
event :disable, after: :disable_projects do
|
45
|
-
transitions from: [:active, :trial, :trial_expired, :past_due, :payment_issue], to: :disabled
|
46
|
-
end
|
47
|
-
end
|
48
|
-
|
49
|
-
aasm(:sso_state) do
|
50
|
-
state :connection_not_configured, initial: true
|
51
|
-
state :connection_disabled
|
52
|
-
state :connection_active
|
53
|
-
|
54
|
-
event :activate_connection do
|
55
|
-
transitions from: [:connection_not_configured, :connection_disabled], to: :connection_active
|
56
|
-
end
|
57
|
-
|
58
|
-
event :deactivate_connection do
|
59
|
-
transitions from: [:connection_active], to: :connection_disabled
|
60
|
-
end
|
61
|
-
|
62
|
-
event :reset_connection do
|
63
|
-
transitions from: [:connection_active, :connection_disabled], to: :connection_not_configured
|
64
|
-
end
|
65
|
-
end
|
66
|
-
|
67
|
-
def update_payment_issue_date
|
68
|
-
update(payment_issue_at: DateTime.current)
|
69
|
-
end
|
70
|
-
|
71
|
-
def active_projects
|
72
|
-
projects.active
|
73
|
-
end
|
74
|
-
|
75
|
-
def disable_projects
|
76
|
-
active_projects.each(&:disable_deployments)
|
77
|
-
end
|
78
|
-
|
79
|
-
# This method is deprecated. Don't use it.
|
80
|
-
def user
|
81
|
-
users.find_by(memberships: { role: UffizziCore::Membership.role.admin })
|
82
|
-
end
|
4
|
+
include UffizziCore::Concerns::Models::Account
|
83
5
|
end
|
@@ -19,35 +19,5 @@
|
|
19
19
|
# @property meta [object]
|
20
20
|
|
21
21
|
class UffizziCore::ActivityItem < UffizziCore::ApplicationRecord
|
22
|
-
include UffizziCore::
|
23
|
-
|
24
|
-
self.table_name = UffizziCore.table_names[:activity_items]
|
25
|
-
|
26
|
-
belongs_to :deployment
|
27
|
-
belongs_to :container
|
28
|
-
belongs_to :build, optional: true
|
29
|
-
|
30
|
-
has_many :events, dependent: :destroy
|
31
|
-
|
32
|
-
scope :docker, -> {
|
33
|
-
where(type: UffizziCore::ActivityItem::Docker.name)
|
34
|
-
}
|
35
|
-
|
36
|
-
scope :github, -> {
|
37
|
-
where(type: UffizziCore::ActivityItem::Github.name)
|
38
|
-
}
|
39
|
-
|
40
|
-
def docker?
|
41
|
-
type == UffizziCore::ActivityItem::Docker.name
|
42
|
-
end
|
43
|
-
|
44
|
-
def image
|
45
|
-
[namespace, name].compact.join('/')
|
46
|
-
end
|
47
|
-
|
48
|
-
def full_image
|
49
|
-
return "#{image}:#{tag}" if docker?
|
50
|
-
|
51
|
-
''
|
52
|
-
end
|
22
|
+
include UffizziCore::Concerns::Models::ActivityItem
|
53
23
|
end
|
@@ -1,39 +1,5 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
class UffizziCore::Build < UffizziCore::ApplicationRecord
|
4
|
-
include UffizziCore::
|
5
|
-
|
6
|
-
self.table_name = UffizziCore.table_names[:builds]
|
7
|
-
|
8
|
-
BUILDING = 1
|
9
|
-
SUCCESS = 2
|
10
|
-
FAILED = 3
|
11
|
-
TIMEOUT = 4
|
12
|
-
CANCELLED = 5
|
13
|
-
|
14
|
-
belongs_to :repo
|
15
|
-
|
16
|
-
def successful?
|
17
|
-
status == SUCCESS
|
18
|
-
end
|
19
|
-
|
20
|
-
def unsuccessful?
|
21
|
-
[FAILED, TIMEOUT, CANCELLED].include?(status)
|
22
|
-
end
|
23
|
-
|
24
|
-
def failed?
|
25
|
-
status == FAILED
|
26
|
-
end
|
27
|
-
|
28
|
-
def building?
|
29
|
-
status == BUILDING
|
30
|
-
end
|
31
|
-
|
32
|
-
def timed_out?
|
33
|
-
status == TIMEOUT
|
34
|
-
end
|
35
|
-
|
36
|
-
def cancelled?
|
37
|
-
status == CANCELLED
|
38
|
-
end
|
4
|
+
include UffizziCore::Concerns::Models::Build
|
39
5
|
end
|
@@ -1,16 +1,5 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
class UffizziCore::Comment < UffizziCore::ApplicationRecord
|
4
|
-
include UffizziCore::
|
5
|
-
|
6
|
-
self.table_name = UffizziCore.table_names[:comments]
|
7
|
-
|
8
|
-
has_ancestry(cache_depth: true)
|
9
|
-
MAX_DEPTH_LEVEL = 1
|
10
|
-
|
11
|
-
belongs_to :user
|
12
|
-
belongs_to :commentable, polymorphic: true
|
13
|
-
|
14
|
-
validates :content, length: { maximum: 1500 }, presence: true
|
15
|
-
validates :ancestry_depth, numericality: { less_than_or_equal_to: MAX_DEPTH_LEVEL, only_integer: true }
|
4
|
+
include UffizziCore::Concerns::Models::Comment
|
16
5
|
end
|
@@ -10,48 +10,5 @@
|
|
10
10
|
# @property payload [string]
|
11
11
|
|
12
12
|
class UffizziCore::ComposeFile < UffizziCore::ApplicationRecord
|
13
|
-
include UffizziCore::
|
14
|
-
include AASM
|
15
|
-
extend Enumerize
|
16
|
-
|
17
|
-
self.table_name = UffizziCore.table_names[:compose_files]
|
18
|
-
|
19
|
-
belongs_to :project
|
20
|
-
belongs_to :added_by, class_name: UffizziCore::User.name, foreign_key: :added_by_id, optional: true
|
21
|
-
|
22
|
-
has_one :template, dependent: :destroy
|
23
|
-
has_many :config_files, dependent: :destroy
|
24
|
-
has_many :deployments, dependent: :nullify
|
25
|
-
|
26
|
-
enumerize :kind, in: [:main, :temporary], predicates: true, scope: :shallow, default: :main
|
27
|
-
|
28
|
-
validates :project, uniqueness: { scope: :project }, if: -> { kind.main? }
|
29
|
-
validates :source, presence: true
|
30
|
-
validates :source, uniqueness: { scope: :project }, if: -> { kind.main? }
|
31
|
-
|
32
|
-
aasm(:auto_deploy) do
|
33
|
-
state :disabled, initial: true
|
34
|
-
state :enabled
|
35
|
-
|
36
|
-
event :enable do
|
37
|
-
transitions from: [:disabled], to: :enabled
|
38
|
-
end
|
39
|
-
|
40
|
-
event :disable do
|
41
|
-
transitions from: [:enabled], to: :disabled
|
42
|
-
end
|
43
|
-
end
|
44
|
-
|
45
|
-
aasm(:state) do
|
46
|
-
state :valid_file, initial: true
|
47
|
-
state :invalid_file
|
48
|
-
|
49
|
-
event :set_valid do
|
50
|
-
transitions from: [:invalid_file], to: :valid_file
|
51
|
-
end
|
52
|
-
|
53
|
-
event :set_invalid do
|
54
|
-
transitions from: [:valid_file], to: :invalid_file
|
55
|
-
end
|
56
|
-
end
|
13
|
+
include UffizziCore::Concerns::Models::ComposeFile
|
57
14
|
end
|
@@ -8,17 +8,5 @@
|
|
8
8
|
# @property source [string]
|
9
9
|
|
10
10
|
class UffizziCore::ConfigFile < UffizziCore::ApplicationRecord
|
11
|
-
include UffizziCore::
|
12
|
-
extend Enumerize
|
13
|
-
|
14
|
-
self.table_name = UffizziCore.table_names[:config_files]
|
15
|
-
|
16
|
-
belongs_to :project
|
17
|
-
belongs_to :added_by, class_name: UffizziCore::User.name, foreign_key: :added_by_id, optional: true
|
18
|
-
belongs_to :compose_file, optional: true
|
19
|
-
|
20
|
-
has_many :container_config_files, dependent: :destroy
|
21
|
-
|
22
|
-
enumerize :kind, in: [:config_map, :secret], default: :config_map, predicates: true
|
23
|
-
enumerize :creation_source, in: [:manual, :compose_file, :system], predicates: true, scope: true
|
11
|
+
include UffizziCore::Concerns::Models::ConfigFile
|
24
12
|
end
|
@@ -12,89 +12,5 @@
|
|
12
12
|
# @property container_config_files [ConfigFile]
|
13
13
|
|
14
14
|
class UffizziCore::Container < UffizziCore::ApplicationRecord
|
15
|
-
include UffizziCore::
|
16
|
-
include AASM
|
17
|
-
include UffizziCore::StateMachineConcern
|
18
|
-
extend Enumerize
|
19
|
-
|
20
|
-
self.table_name = UffizziCore.table_names[:containers]
|
21
|
-
|
22
|
-
enumerize :kind, in: [:internal, :user], predicates: true
|
23
|
-
|
24
|
-
belongs_to :deployment, touch: true
|
25
|
-
belongs_to :repo, optional: true
|
26
|
-
|
27
|
-
has_many :activity_items, dependent: :destroy
|
28
|
-
has_many :container_config_files, dependent: :destroy
|
29
|
-
has_many :config_files, through: :container_config_files
|
30
|
-
|
31
|
-
attribute :public, :boolean, default: false
|
32
|
-
attribute :port, :integer, default: nil
|
33
|
-
|
34
|
-
enumerize :source, in: [:github], skip_validations: true
|
35
|
-
validates :port,
|
36
|
-
presence: true,
|
37
|
-
inclusion: { in: 0..65_535 },
|
38
|
-
uniqueness: { scope: :deployment_id },
|
39
|
-
if: :should_check_port
|
40
|
-
|
41
|
-
after_commit :check_target_port, on: :create
|
42
|
-
|
43
|
-
before_save :update_target_port_value, if: :will_save_change_to_port?
|
44
|
-
before_create :set_defaults
|
45
|
-
|
46
|
-
accepts_nested_attributes_for :repo
|
47
|
-
accepts_nested_attributes_for :container_config_files, allow_destroy: true
|
48
|
-
|
49
|
-
validates :variables, 'uffizzi_core/environment_variable_list': true, allow_nil: true
|
50
|
-
validates :secret_variables, 'uffizzi_core/environment_variable_list': true, allow_nil: true
|
51
|
-
validates :entrypoint, 'uffizzi_core/image_command_args': true, allow_nil: true
|
52
|
-
validates :command, 'uffizzi_core/image_command_args': true, allow_nil: true
|
53
|
-
validates :tag, presence: true
|
54
|
-
|
55
|
-
aasm :continuously_deploy, column: :continuously_deploy do
|
56
|
-
state :disabled, initial: true
|
57
|
-
state :enabled
|
58
|
-
end
|
59
|
-
|
60
|
-
aasm :state, column: :state do
|
61
|
-
state :active, initial: true
|
62
|
-
state :disabled
|
63
|
-
|
64
|
-
event :activate do
|
65
|
-
transitions from: [:disabled], to: :active
|
66
|
-
end
|
67
|
-
|
68
|
-
event :disable, after: :clean do
|
69
|
-
transitions from: [:active], to: :disabled
|
70
|
-
end
|
71
|
-
end
|
72
|
-
|
73
|
-
def image_name
|
74
|
-
"#{image}:#{tag}"
|
75
|
-
end
|
76
|
-
|
77
|
-
private
|
78
|
-
|
79
|
-
def should_check_port
|
80
|
-
public && active?
|
81
|
-
end
|
82
|
-
|
83
|
-
def clean
|
84
|
-
update(public: false, port: nil)
|
85
|
-
end
|
86
|
-
|
87
|
-
def set_defaults
|
88
|
-
update_target_port_value
|
89
|
-
end
|
90
|
-
|
91
|
-
def update_target_port_value
|
92
|
-
self.target_port = UffizziCore::ContainerService.target_port_value(self)
|
93
|
-
end
|
94
|
-
|
95
|
-
def check_target_port
|
96
|
-
if target_port && deployment.containers.where(target_port: target_port).size > 1
|
97
|
-
update(target_port: UffizziCore::DeploymentService.find_unused_port(deployment))
|
98
|
-
end
|
99
|
-
end
|
15
|
+
include UffizziCore::Concerns::Models::Container
|
100
16
|
end
|
@@ -1,8 +1,5 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
class UffizziCore::ContainerConfigFile < UffizziCore::ApplicationRecord
|
4
|
-
|
5
|
-
|
6
|
-
belongs_to :container
|
7
|
-
belongs_to :config_file
|
4
|
+
include UffizziCore::Concerns::Models::ContainerConfigFile
|
8
5
|
end
|
@@ -1,61 +1,5 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
class UffizziCore::Credential < UffizziCore::ApplicationRecord
|
4
|
-
include
|
5
|
-
include UffizziCore::CredentialRepo
|
6
|
-
|
7
|
-
self.table_name = UffizziCore.table_names[:credentials]
|
8
|
-
|
9
|
-
belongs_to :account
|
10
|
-
|
11
|
-
before_destroy :remove_token
|
12
|
-
|
13
|
-
validates :registry_url, presence: true
|
14
|
-
|
15
|
-
aasm :state, column: :state do
|
16
|
-
state :not_connected, initial: true
|
17
|
-
state :active
|
18
|
-
state :unauthorized
|
19
|
-
|
20
|
-
event :activate do
|
21
|
-
transitions from: [:not_connected, :unauthorized], to: :active
|
22
|
-
end
|
23
|
-
|
24
|
-
event :unauthorize do
|
25
|
-
transitions from: [:not_connected, :active], to: :unauthorized
|
26
|
-
end
|
27
|
-
end
|
28
|
-
|
29
|
-
def github_container_registry?
|
30
|
-
type == UffizziCore::Credential::GithubContainerRegistry.name
|
31
|
-
end
|
32
|
-
|
33
|
-
def docker_hub?
|
34
|
-
type == UffizziCore::Credential::DockerHub.name
|
35
|
-
end
|
36
|
-
|
37
|
-
def azure?
|
38
|
-
type == UffizziCore::Credential::Azure.name
|
39
|
-
end
|
40
|
-
|
41
|
-
def google?
|
42
|
-
type == UffizziCore::Credential::Google.name
|
43
|
-
end
|
44
|
-
|
45
|
-
def amazon?
|
46
|
-
type == UffizziCore::Credential::Amazon.name
|
47
|
-
end
|
48
|
-
|
49
|
-
private
|
50
|
-
|
51
|
-
def remove_token
|
52
|
-
account.projects.find_each do |project|
|
53
|
-
project.deployments.find_each do |deployment|
|
54
|
-
containers = deployment.containers
|
55
|
-
attributes = { continuously_deploy: UffizziCore::Container::STATE_DISABLED }
|
56
|
-
|
57
|
-
containers.with_docker_hub_repo.update_all(attributes) if docker_hub?
|
58
|
-
end
|
59
|
-
end
|
60
|
-
end
|
4
|
+
include UffizziCore::Concerns::Models::Credential
|
61
5
|
end
|