uffizzi_core 0.1.10 → 0.1.13

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 47eea084cd84fe9074609e526971df1417befd6d56d5d40e63a89023a9362602
4
- data.tar.gz: 5a05f8c69d95b3829464d08f7b854bda15200dbe835e1e47ecf1c5f42c88edaf
3
+ metadata.gz: 7d892c859a5a90f309d59a2fd110e3e99719d62f566cda4f7cb1f0815c700f4e
4
+ data.tar.gz: df8bed87726cc99d3401b129245a8bc0467d087550d3258f66f08c482f897f7e
5
5
  SHA512:
6
- metadata.gz: 11c3d78965eac3fb0e57783843f8b42fd03eb8fa334852d2364f5d79a6c613062fed607f11f386bbdc14941cac9d3d21448b8f82092e66eac9777979e13f8dca
7
- data.tar.gz: f02157e2b222d62729459a234952ee957897bfd94733b5ec9be52aa0a7e0770ddd0661ee5facdb7c630cfb76d111ededf6536b8a83c6617681600b58d773a0ab
6
+ metadata.gz: dc59d9a62a34892c5c50eb0b622e7a5e46ecd0e0cdbd826ea72fd0b27c88dc35ddd7c686b3b46b1aa16c2544374f5f96ca4588d41afb39433b8759fabba8484e
7
+ data.tar.gz: 070f387c4d12a5d662c392dfa715dd536d8100aa06978c072dbaee04bec52dd9aa126b396903610dbfc187dbac5542d7c7332d1b5a7df784210b21c1a31cea20
@@ -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,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,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
@@ -12,6 +12,10 @@ class UffizziCore::ComposeFile::ConfigOptionService
12
12
 
13
13
  def config_options(compose_data)
14
14
  compose_data.each_with_object([]) do |(key, value), keys|
15
+ if compose_data.equal?(value)
16
+ raise UffizziCore::ComposeFile::ParseError, I18n.t('compose.infinite_recursion', key: key)
17
+ end
18
+
15
19
  keys << key
16
20
  keys.concat(config_options(value)) if value.is_a?(Hash)
17
21
  end
@@ -158,7 +158,7 @@ module UffizziCore::ComposeFileService
158
158
 
159
159
  def load_compose_data(compose_content)
160
160
  begin
161
- compose_data = YAML.safe_load(compose_content)
161
+ compose_data = YAML.safe_load(compose_content, aliases: true)
162
162
  rescue Psych::SyntaxError
163
163
  raise UffizziCore::ComposeFile::ParseError, 'Invalid compose file'
164
164
  end
@@ -103,8 +103,9 @@ module UffizziCore::DeploymentService
103
103
  pull_request_payload = continuous_preview_payload['pull_request']
104
104
  repo_name = pull_request_payload['repository_full_name'].split('/').last
105
105
  deployment_name = name(deployment)
106
+ subdomain = "pr#{pull_request_payload['id']}-#{deployment_name}-#{repo_name}-#{project.slug}"
106
107
 
107
- "pr#{pull_request_payload['id']}-#{deployment_name}.#{repo_name}.#{project.slug}"
108
+ format_subdomain(subdomain)
108
109
  end
109
110
 
110
111
  def build_docker_continuous_preview_subdomain(deployment)
@@ -114,14 +115,17 @@ module UffizziCore::DeploymentService
114
115
  repo_name = docker_payload['image'].split('/').last.gsub('_', '-')
115
116
  image_tag = docker_payload['tag'].gsub('_', '-')
116
117
  deployment_name = name(deployment)
118
+ subdomain = "#{image_tag}-#{deployment_name}-#{repo_name}-#{project.slug}"
117
119
 
118
- "#{image_tag}-#{deployment_name}.#{repo_name}.#{project.slug}"
120
+ format_subdomain(subdomain)
119
121
  end
120
122
 
121
123
  def build_default_subdomain(deployment)
122
124
  deployment_name = name(deployment)
123
125
  slug = deployment.project.slug.to_s
124
- "#{deployment_name}.#{slug}"
126
+ subdomain = "#{deployment_name}-#{slug}"
127
+
128
+ format_subdomain(subdomain)
125
129
  end
126
130
 
127
131
  def build_preview_url(deployment)
@@ -291,5 +295,12 @@ module UffizziCore::DeploymentService
291
295
  container.variables.push(*envs)
292
296
  end
293
297
  end
298
+
299
+ def format_subdomain(full_subdomain_name)
300
+ subdomain_length_limit = Settings.deployment.subdomain.length_limit
301
+ return full_subdomain_name if full_subdomain_name.length <= subdomain_length_limit
302
+
303
+ full_subdomain_name.slice(0, subdomain_length_limit)
304
+ end
294
305
  end
295
306
  end
@@ -116,20 +116,26 @@ class UffizziCore::ManageActivityItemsService
116
116
  state = pod_container[:state][pod_container_status]
117
117
  reason = state&.reason
118
118
 
119
- Rails.logger.info("manage_activity_items get_status dep_id=#{container.deployment.id} pod_container: #{pod_container[:state].inspect}")
119
+ Rails.logger.info("manage_activity_items get_status dep_id=#{container.deployment.id} pod_container_status: #{pod_container_status}")
120
+ Rails.logger.info("manage_activity_items get_status dep_id=#{container.deployment.id} state: #{state}")
121
+ ap pod_container[:state]
120
122
 
121
123
  case pod_container_status.to_sym
122
124
  when :running
125
+ Rails.logger.info("manage_activity_items get_status dep_id=#{container.deployment.id} running")
123
126
  UffizziCore::Event.state.deployed
124
127
  when :terminated
128
+ Rails.logger.info("manage_activity_items get_status dep_id=#{container.deployment.id} terminated")
125
129
  UffizziCore::Event.state.failed
126
130
  when :waiting
131
+ Rails.logger.info("manage_activity_items get_status dep_id=#{container.deployment.id} waiting")
127
132
  return UffizziCore::Event.state.failed if ['CrashLoopBackOff'].include?(reason)
128
133
 
129
134
  raise UffizziCore::Deployment::ImagePullError, @deployment.id if ['ErrImagePull', 'ImagePullBackOff'].include?(reason)
130
135
 
131
136
  UffizziCore::Event.state.deploying
132
137
  else
138
+ Rails.logger.info("manage_activity_items get_status dep_id=#{container.deployment.id} else")
133
139
  UffizziCore::Event.state.deploying
134
140
  end
135
141
  end
@@ -59,6 +59,7 @@ en:
59
59
  invalid_healthcheck_command: "Service '%{name}' defines an invalid healthcheck: when 'test' is a list the first item must be either NONE, CMD or CMD-SHELL"
60
60
  string_or_array_error: "'%{option}' contains an invalid type, it should be a string, or an array"
61
61
  not_implemented: "'%{option}' option is not implemented"
62
+ infinite_recursion: "Found infinite recursion for key '%{key}'"
62
63
  secrets:
63
64
  duplicates_exists: Secret with key %{secrets} already exist.
64
65
  invalid_key_length: A secret key must be no longer than 256 characters.
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module UffizziCore
4
- VERSION = '0.1.10'
4
+ VERSION = '0.1.13'
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: uffizzi_core
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.10
4
+ version: 0.1.13
5
5
  platform: ruby
6
6
  authors:
7
7
  - Josh Thurman
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2022-05-27 00:00:00.000000000 Z
12
+ date: 2022-05-30 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: aasm
@@ -757,6 +757,9 @@ files:
757
757
  - app/jobs/uffizzi_core/deployment/delete_job.rb
758
758
  - app/jobs/uffizzi_core/deployment/deploy_containers_job.rb
759
759
  - app/jobs/uffizzi_core/deployment/manage_deploy_activity_item_job.rb
760
+ - app/lib/uffizzi_core/concerns/models/activity_item.rb
761
+ - app/lib/uffizzi_core/concerns/models/credential.rb
762
+ - app/lib/uffizzi_core/concerns/models/repo.rb
760
763
  - app/lib/uffizzi_core/rbac/user_access_service.rb
761
764
  - app/mailers/uffizzi_core/application_mailer.rb
762
765
  - app/models/concerns/uffizzi_core/hashid_concern.rb