uffizzi_core 2.1.6 → 2.1.7

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 2fa718cfa69dcdae6e76cb1808c513aa11ed894fdf7afef9bc383cb23c129e00
4
- data.tar.gz: 28679dfd137f683e33a71b64cfbfd7a5589588aa24f31f2a1a6f5284fa6b71d1
3
+ metadata.gz: 5d1187785a105e2f2d00f7b04e987a2340e7678215329613ca5795c44a3f790e
4
+ data.tar.gz: d77dfcbdb2a1a49bac3cc8a408d2c025a97fd5699bdc3fdfdf4812e46b708f10
5
5
  SHA512:
6
- metadata.gz: 693edec5e777a1d96df5e3bff4a871091eaf89de12ae94d53d17591dff7e8ec8a61d9cbcf6d8088aafef68cdb434398b4fb3aac1c3c46f07ee10a10585712ac4
7
- data.tar.gz: 9494c2246be34b70fcbe93f88315df66d08a7b13cb234c1a1552719e66b727093f44ad0f96f11d2b1b24002213fc8c5f00b906f4c7b159c5ad4949bdb4891df1
6
+ metadata.gz: '0229c075de1275071dccdfce43f54b9a37c556d6d704aea3f84ee1dc4351f41dd05f0f5a8c1c4b342abd4fd8ca2c4f054f9930a5702f01609eddf40f0b16cf54'
7
+ data.tar.gz: 2d3733720b7b39e24e96fe5f9ff993eb99c327e1fd5bcd30a8de65c733989b78f7a1d325408a95a0be0c81ed902ab9fa74c6c35a5436b169c190acb2a6b53ce3
@@ -37,10 +37,10 @@ module UffizziCore::DependencyInjectionConcern
37
37
  module_class(:notification_module)
38
38
  end
39
39
 
40
- def deployment_module
41
- return unless module_exists?(:deployment_module)
40
+ def domain_module
41
+ return unless module_exists?(:domain_module)
42
42
 
43
- module_class(:deployment_module)
43
+ module_class(:domain_module)
44
44
  end
45
45
 
46
46
  private
@@ -73,18 +73,6 @@ module UffizziCore::Concerns::Models::Deployment
73
73
  def preview_url
74
74
  "#{subdomain}.#{Settings.app.managed_dns_zone}"
75
75
  end
76
-
77
- def from_actions?
78
- from_github_actions? || from_gitlab_actions?
79
- end
80
-
81
- def from_github_actions?
82
- metadata.dig('labels', 'github', 'repository').present?
83
- end
84
-
85
- def from_gitlab_actions?
86
- metadata.dig('labels', 'gitlab', 'repo').present?
87
- end
88
76
  end
89
77
  # rubocop:enable Metrics/BlockLength
90
78
  end
@@ -0,0 +1,62 @@
1
+ # frozen_string_literal: true
2
+
3
+ class UffizziCore::Deployment::DomainService
4
+ class << self
5
+ include UffizziCore::DependencyInjectionConcern
6
+
7
+ def build_subdomain(deployment)
8
+ return domain_module.build_subdomain(deployment) if domain_module.present?
9
+ return build_docker_continuous_preview_subdomain(deployment) if deployment&.continuous_preview_payload&.fetch('docker', nil).present?
10
+
11
+ build_default_subdomain(deployment)
12
+ end
13
+
14
+ def update_subdomain!(deployment)
15
+ deployment.subdomain = build_subdomain(deployment)
16
+ deployment.save!
17
+ end
18
+
19
+ private
20
+
21
+ def build_docker_continuous_preview_subdomain(deployment)
22
+ project = deployment.project
23
+ continuous_preview_payload = deployment.continuous_preview_payload
24
+ docker_payload = continuous_preview_payload['docker']
25
+ repo_name = docker_payload['image'].split('/').last
26
+ image_tag = docker_payload['tag']
27
+ deployment_name = name(deployment)
28
+ subdomain = "#{image_tag}-#{deployment_name}-#{repo_name}-#{project.slug}"
29
+
30
+ format_subdomain(subdomain)
31
+ end
32
+
33
+ def build_default_subdomain(deployment)
34
+ deployment_name = name(deployment)
35
+ slug = deployment.project.slug.to_s
36
+ subdomain = "#{deployment_name}-#{slug}"
37
+
38
+ format_subdomain(subdomain)
39
+ end
40
+
41
+ def name(deployment)
42
+ "deployment-#{deployment.id}"
43
+ end
44
+
45
+ def format_subdomain(full_subdomain_name)
46
+ # Replace _ to - because RFC 1123 subdomain must consist of lower case alphanumeric characters,
47
+ # '-' or '.', and must start and end with an alphanumeric character
48
+ rfc_subdomain = full_subdomain_name.gsub('_', '-')
49
+ subdomain_length_limit = Settings.deployment.subdomain.length_limit
50
+ return rfc_subdomain if rfc_subdomain.length <= subdomain_length_limit
51
+
52
+ sliced_subdomain = rfc_subdomain.slice(0, subdomain_length_limit)
53
+ return sliced_subdomain.chop if sliced_subdomain.end_with?('-')
54
+
55
+ sliced_subdomain
56
+ end
57
+
58
+ def format_url_safe(name)
59
+ name.gsub(/ /, '-').gsub(/[^\w-]+/, '-')
60
+ end
61
+ end
62
+ end
@@ -88,57 +88,6 @@ class UffizziCore::DeploymentService
88
88
  compose_file.destroy!
89
89
  end
90
90
 
91
- def build_subdomain(deployment)
92
- return build_docker_continuous_preview_subdomain(deployment) if deployment&.continuous_preview_payload&.fetch('docker', nil).present?
93
- return build_pull_request_subdomain(deployment) if deployment.from_actions?
94
-
95
- build_default_subdomain(deployment)
96
- rescue UffizziCore::Deployment::LabelsNotFoundError
97
- build_default_subdomain(deployment)
98
- end
99
-
100
- def build_pull_request_subdomain(deployment)
101
- _, repo_name, pull_request_number = pull_request_data(deployment)
102
- raise UffizziCore::Deployment::LabelsNotFoundError if repo_name.nil? || pull_request_number.nil?
103
-
104
- formatted_repo_name = format_url_safe(repo_name.split('/').last.downcase)
105
- subdomain = "pr-#{pull_request_number}-#{name(deployment)}-#{formatted_repo_name}"
106
- format_subdomain(subdomain)
107
- end
108
-
109
- def update_subdomain!(deployment)
110
- deployment.subdomain = build_subdomain(deployment)
111
- deployment.save!
112
- end
113
-
114
- def build_docker_continuous_preview_subdomain(deployment)
115
- project = deployment.project
116
- continuous_preview_payload = deployment.continuous_preview_payload
117
- docker_payload = continuous_preview_payload['docker']
118
- repo_name = docker_payload['image'].split('/').last
119
- image_tag = docker_payload['tag']
120
- deployment_name = name(deployment)
121
- subdomain = "#{image_tag}-#{deployment_name}-#{repo_name}-#{project.slug}"
122
-
123
- format_subdomain(subdomain)
124
- end
125
-
126
- def build_default_subdomain(deployment)
127
- deployment_name = name(deployment)
128
- slug = deployment.project.slug.to_s
129
- subdomain = "#{deployment_name}-#{slug}"
130
-
131
- format_subdomain(subdomain)
132
- end
133
-
134
- def build_preview_url(deployment)
135
- "#{deployment.subdomain}.#{Settings.app.managed_dns_zone}"
136
- end
137
-
138
- def build_deployment_url(deployment)
139
- "#{Settings.app.host}/projects/#{deployment.project_id}/deployments"
140
- end
141
-
142
91
  def all_containers_have_unique_ports?(containers)
143
92
  ports = containers.map(&:port).compact
144
93
  containers.empty? || ports.size == ports.uniq.size
@@ -190,7 +139,7 @@ class UffizziCore::DeploymentService
190
139
 
191
140
  deployment.reload
192
141
 
193
- new_deployment_subdomain = build_subdomain(deployment)
142
+ new_deployment_subdomain = DomainService.build_subdomain(deployment)
194
143
 
195
144
  if new_deployment_subdomain != old_deployment_subdomain
196
145
  deployment.update(subdomain: new_deployment_subdomain)
@@ -199,10 +148,6 @@ class UffizziCore::DeploymentService
199
148
  UffizziCore::Deployment::DeployContainersJob.perform_async(deployment.id)
200
149
  end
201
150
 
202
- def name(deployment)
203
- "deployment-#{deployment.id}"
204
- end
205
-
206
151
  def pull_request_payload_present?(deployment)
207
152
  deployment.continuous_preview_payload.present? && deployment.continuous_preview_payload['pull_request'].present?
208
153
  end
@@ -216,7 +161,7 @@ class UffizziCore::DeploymentService
216
161
  private
217
162
 
218
163
  def run_deployment_creation_tasks(deployment)
219
- update_subdomain!(deployment)
164
+ UffizziCore::Deployment::DomainService.update_subdomain!(deployment)
220
165
 
221
166
  UffizziCore::Deployment::CreateJob.perform_async(deployment.id)
222
167
  end
@@ -275,7 +220,7 @@ class UffizziCore::DeploymentService
275
220
  envs.push('name' => 'UFFIZZI_URL', 'value' => "https://#{deployment.preview_url}")
276
221
  envs.push('name' => 'UFFIZZI_DOMAIN', 'value' => deployment.preview_url)
277
222
 
278
- preview_url = "https://#{deployment_module.build_preview_url(deployment)}" if deployment_module.present?
223
+ preview_url = "https://#{domain_module.build_preview_url(deployment)}" if domain_module.present?
279
224
  envs.push('name' => 'UFFIZZI_PREDICTABLE_URL', 'value' => preview_url || '')
280
225
 
281
226
  container.variables = [] if container.variables.nil?
@@ -283,40 +228,5 @@ class UffizziCore::DeploymentService
283
228
  container.variables.push(*envs)
284
229
  end
285
230
  end
286
-
287
- def format_subdomain(full_subdomain_name)
288
- # Replace _ to - because RFC 1123 subdomain must consist of lower case alphanumeric characters,
289
- # '-' or '.', and must start and end with an alphanumeric character
290
- rfc_subdomain = full_subdomain_name.gsub('_', '-')
291
- subdomain_length_limit = Settings.deployment.subdomain.length_limit
292
- return rfc_subdomain if rfc_subdomain.length <= subdomain_length_limit
293
-
294
- sliced_subdomain = rfc_subdomain.slice(0, subdomain_length_limit)
295
- return sliced_subdomain.chop if sliced_subdomain.end_with?('-')
296
-
297
- sliced_subdomain
298
- end
299
-
300
- def pull_request_data(deployment)
301
- return github_pull_request_data(deployment) if deployment.from_github_actions?
302
-
303
- gitlab_merge_request_data(deployment)
304
- end
305
-
306
- def github_pull_request_data(deployment)
307
- github_data = deployment.metadata.dig('labels', 'github')
308
-
309
- [:github, github_data['repository'], github_data.dig('event', 'number')]
310
- end
311
-
312
- def gitlab_merge_request_data(deployment)
313
- gitlab_data = deployment.metadata.dig('labels', 'gitlab')
314
-
315
- [:gitlab, gitlab_data['repo'], gitlab_data.dig('merge_request', 'number')]
316
- end
317
-
318
- def format_url_safe(name)
319
- name.gsub(/ /, '-').gsub(/[^\w-]+/, '-')
320
- end
321
231
  end
322
232
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module UffizziCore
4
- VERSION = '2.1.6'
4
+ VERSION = '2.1.7'
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: 2.1.6
4
+ version: 2.1.7
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: 2023-03-02 00:00:00.000000000 Z
12
+ date: 2023-03-06 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: aasm
@@ -779,7 +779,6 @@ files:
779
779
  - app/errors/uffizzi_core/compose_file_error.rb
780
780
  - app/errors/uffizzi_core/container_registry_error.rb
781
781
  - app/errors/uffizzi_core/deployment/image_pull_error.rb
782
- - app/errors/uffizzi_core/deployment/labels_not_found_error.rb
783
782
  - app/errors/uffizzi_core/deployment_not_found_error.rb
784
783
  - app/errors/uffizzi_core/registry_not_supported_error.rb
785
784
  - app/forms/uffizzi_core/api/cli/v1/account/credential/check_credential_form.rb
@@ -993,6 +992,7 @@ files:
993
992
  - app/services/uffizzi_core/container_registry_service.rb
994
993
  - app/services/uffizzi_core/container_service.rb
995
994
  - app/services/uffizzi_core/controller_service.rb
995
+ - app/services/uffizzi_core/deployment/domain_service.rb
996
996
  - app/services/uffizzi_core/deployment_service.rb
997
997
  - app/services/uffizzi_core/logs_service.rb
998
998
  - app/services/uffizzi_core/manage_activity_items_service.rb
@@ -1,4 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- class UffizziCore::Deployment::LabelsNotFoundError < StandardError
4
- end