uffizzi_core 2.0.7 → 2.0.9
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/clients/uffizzi_core/controller_client.rb +2 -2
- data/app/controllers/uffizzi_core/api/cli/v1/projects/deployments/containers/logs_controller.rb +1 -1
- data/app/controllers/uffizzi_core/application_controller.rb +5 -3
- data/app/errors/uffizzi_core/registry_not_supported_error.rb +4 -0
- data/app/forms/uffizzi_core/api/cli/v1/account/credential/create_form.rb +1 -1
- data/app/forms/uffizzi_core/api/cli/v1/account/credential/update_form.rb +1 -1
- data/app/forms/uffizzi_core/api/cli/v1/compose_file/check_credentials_form.rb +8 -1
- data/app/forms/uffizzi_core/api/cli/v1/compose_file/template_form.rb +2 -0
- data/app/forms/uffizzi_core/api/cli/v1/template/create_form.rb +2 -55
- data/app/lib/uffizzi_core/concerns/models/credential.rb +22 -17
- data/app/lib/uffizzi_core/concerns/models/event.rb +2 -2
- data/app/lib/uffizzi_core/concerns/models/repo.rb +0 -1
- data/app/lib/uffizzi_core/concerns/models/template.rb +16 -0
- data/app/models/uffizzi_core/credential.rb +3 -0
- data/app/serializers/uffizzi_core/api/cli/v1/projects/deployment_serializer.rb +0 -5
- data/app/serializers/uffizzi_core/api/cli/v1/projects/deployments/container_serializer.rb +1 -9
- data/app/serializers/uffizzi_core/controller/create_credential/credential_serializer.rb +1 -1
- data/app/services/uffizzi_core/activity_item_service.rb +2 -11
- data/app/services/uffizzi_core/compose_file/builders/container_builder_service.rb +33 -82
- data/app/services/uffizzi_core/compose_file/container_service.rb +0 -72
- data/app/services/uffizzi_core/compose_file_service.rb +6 -28
- data/app/services/uffizzi_core/{amazon/credential_service.rb → container_registry/amazon_service.rb} +20 -2
- data/app/services/uffizzi_core/container_registry/azure_service.rb +21 -0
- data/app/services/uffizzi_core/{docker_hub_service.rb → container_registry/docker_hub_service.rb} +7 -3
- data/app/services/uffizzi_core/{docker_registry_service.rb → container_registry/docker_registry_service.rb} +15 -1
- data/app/services/uffizzi_core/{github_container_registry/credential_service.rb → container_registry/github_container_registry_service.rb} +7 -4
- data/app/services/uffizzi_core/container_registry/google_service.rb +27 -0
- data/app/services/uffizzi_core/container_registry_service.rb +91 -0
- data/app/services/uffizzi_core/logs_service.rb +1 -0
- data/app/services/uffizzi_core/manage_activity_items_service.rb +2 -13
- data/app/services/uffizzi_core/repo_service.rb +2 -19
- data/config/locales/en.activerecord.yml +1 -1
- data/config/locales/en.yml +9 -0
- data/lib/uffizzi_core/version.rb +1 -1
- metadata +10 -17
- data/app/lib/uffizzi_core/concerns/models/build.rb +0 -47
- data/app/models/uffizzi_core/build.rb +0 -5
- data/app/repositories/uffizzi_core/build_repo.rb +0 -23
- data/app/services/uffizzi_core/amazon_service.rb +0 -31
- data/app/services/uffizzi_core/azure/credential_service.rb +0 -18
- data/app/services/uffizzi_core/credential_service.rb +0 -45
- data/app/services/uffizzi_core/docker_hub/credential_service.rb +0 -15
- data/app/services/uffizzi_core/docker_registry/credential_service.rb +0 -21
- data/app/services/uffizzi_core/google/credential_service.rb +0 -18
- data/app/services/uffizzi_core/google_service.rb +0 -21
- data/app/services/uffizzi_core/template_service.rb +0 -21
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0e4678fb73f3c46832c31d239796e6eb99bbe66b58aef0af348d470030139312
|
4
|
+
data.tar.gz: d03ff11d2723b851f01fe597ba96b6e250f68ae2d190905aa70d269bd10f0ff3
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: fb063735799a3a24ddc60ee808d30e67bcb90831f3e0058ee93fa0d1cea575f8949b1bc91410d781f4e38baf9cb9b9ecfed387cfe5c58bdeaecaf916a07698cb
|
7
|
+
data.tar.gz: 03311442753ac1af1439287b170280e4d689d827a8dbabbffbc910045131a7ca5d35dbf5ed3dd7945fb49fd0e0d5502d5eba41f2499232887e78e04f7671fc60
|
@@ -39,8 +39,8 @@ class UffizziCore::ControllerClient
|
|
39
39
|
get("/deployments/#{deployment_id}/containers/metrics")
|
40
40
|
end
|
41
41
|
|
42
|
-
def deployment_container_logs(deployment_id:, container_name:, limit:)
|
43
|
-
get("/deployments/#{deployment_id}/containers/#{container_name}/logs?limit=#{limit}")
|
42
|
+
def deployment_container_logs(deployment_id:, container_name:, limit:, previous:)
|
43
|
+
get("/deployments/#{deployment_id}/containers/#{container_name}/logs?limit=#{limit}&previous=#{previous}")
|
44
44
|
end
|
45
45
|
|
46
46
|
def deployment_containers_events(deployment_id:)
|
@@ -1,7 +1,7 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
class UffizziCore::ApplicationController < ActionController::Base
|
4
|
-
include Pundit
|
4
|
+
include Pundit::Authorization
|
5
5
|
include UffizziCore::ResponseService
|
6
6
|
include UffizziCore::AuthManagement
|
7
7
|
include UffizziCore::AuthorizationConcern
|
@@ -12,8 +12,10 @@ class UffizziCore::ApplicationController < ActionController::Base
|
|
12
12
|
|
13
13
|
protect_from_forgery with: :exception
|
14
14
|
RESCUABLE_EXCEPTIONS = [RuntimeError, TypeError, NameError, ArgumentError, SyntaxError].freeze
|
15
|
-
|
16
|
-
|
15
|
+
unless Rails.env.test?
|
16
|
+
rescue_from *RESCUABLE_EXCEPTIONS do |exception|
|
17
|
+
render_server_error(exception)
|
18
|
+
end
|
17
19
|
end
|
18
20
|
rescue_from ActiveRecord::RecordNotFound do |exception|
|
19
21
|
render_not_found(exception)
|
@@ -17,7 +17,7 @@ class UffizziCore::Api::Cli::V1::Account::Credential::CreateForm < UffizziCore::
|
|
17
17
|
end
|
18
18
|
|
19
19
|
def check_credential_correctness
|
20
|
-
errors.add(:username, :incorrect) unless
|
20
|
+
errors.add(:username, :incorrect, type: type.text) unless correct?
|
21
21
|
end
|
22
22
|
|
23
23
|
def credential_exists?
|
@@ -16,6 +16,6 @@ class UffizziCore::Api::Cli::V1::Account::Credential::UpdateForm < UffizziCore::
|
|
16
16
|
end
|
17
17
|
|
18
18
|
def check_credential_correctness
|
19
|
-
errors.add(:username, :incorrect) unless
|
19
|
+
errors.add(:username, :incorrect) unless correct?
|
20
20
|
end
|
21
21
|
end
|
@@ -15,7 +15,14 @@ class UffizziCore::Api::Cli::V1::ComposeFile::CheckCredentialsForm
|
|
15
15
|
compose_payload = { compose_file: compose_file }
|
16
16
|
compose_data = UffizziCore::ComposeFileService.parse(compose_content, compose_payload)
|
17
17
|
|
18
|
-
|
18
|
+
containers = compose_data[:containers]
|
19
|
+
containers.map do |container|
|
20
|
+
container_registry_service = UffizziCore::ContainerRegistryService.init_by_container(container)
|
21
|
+
credential = container_registry_service.credential(credentials)
|
22
|
+
next credential if container_registry_service.image_available?(credentials)
|
23
|
+
|
24
|
+
raise UffizziCore::ComposeFile::CredentialError.new(I18n.t('compose.unprocessable_image', value: container_registry_service.type))
|
25
|
+
end
|
19
26
|
rescue UffizziCore::ComposeFile::CredentialError => e
|
20
27
|
errors.add(:credentials, e.message)
|
21
28
|
end
|
@@ -39,6 +39,8 @@ class UffizziCore::Api::Cli::V1::ComposeFile::TemplateForm
|
|
39
39
|
errors.add(SECRETS_ERROR_KEY, template_build_error.message)
|
40
40
|
when UffizziCore::ComposeFile::BuildError
|
41
41
|
errors.add(TEMPLATE_BUILD_ERROR_KEY, template_build_error.message)
|
42
|
+
when StandardError
|
43
|
+
raise template_build_error
|
42
44
|
end
|
43
45
|
end
|
44
46
|
end
|
@@ -1,72 +1,19 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
class UffizziCore::Api::Cli::V1::Template::CreateForm < UffizziCore::Template
|
4
|
-
include UffizziCore::ApplicationForm
|
5
|
-
|
6
|
-
permit :name,
|
7
|
-
payload: {
|
8
|
-
containers_attributes: [
|
9
|
-
:image,
|
10
|
-
:tag,
|
11
|
-
:port,
|
12
|
-
:public,
|
13
|
-
:memory_limit,
|
14
|
-
:memory_request,
|
15
|
-
:entrypoint,
|
16
|
-
:command,
|
17
|
-
:receive_incoming_requests,
|
18
|
-
:continuously_deploy,
|
19
|
-
:service_name,
|
20
|
-
:name,
|
21
|
-
{ variables: [:name, :value],
|
22
|
-
additional_subdomains: [],
|
23
|
-
secret_variables: [:name, :value],
|
24
|
-
volumes: [:source, :target, :type, :read_only],
|
25
|
-
healthcheck: [:test, :interval, :timeout, :retries, :start_period, :disable, { test: [] }],
|
26
|
-
repo_attributes: [
|
27
|
-
:namespace,
|
28
|
-
:name,
|
29
|
-
:slug,
|
30
|
-
:type,
|
31
|
-
:description,
|
32
|
-
:repository_id,
|
33
|
-
:is_private,
|
34
|
-
:branch,
|
35
|
-
:kind,
|
36
|
-
:dockerfile_path,
|
37
|
-
:dockerfile_context_path,
|
38
|
-
:deploy_preview_when_pull_request_is_opened,
|
39
|
-
:delete_preview_when_pull_request_is_closed,
|
40
|
-
:deploy_preview_when_image_tag_is_created,
|
41
|
-
:delete_preview_when_image_tag_is_updated,
|
42
|
-
:share_to_github,
|
43
|
-
:delete_preview_after,
|
44
|
-
{ args: [:name, :value] },
|
45
|
-
],
|
46
|
-
container_config_files_attributes: [
|
47
|
-
:config_file_id,
|
48
|
-
:mount_path,
|
49
|
-
],
|
50
|
-
container_host_volume_files_attributes: [
|
51
|
-
:host_volume_file_id,
|
52
|
-
:source_path,
|
53
|
-
] },
|
54
|
-
],
|
55
|
-
}
|
56
|
-
|
57
4
|
validate :check_max_memory_limit
|
58
5
|
validate :check_max_memory_request
|
59
6
|
|
60
7
|
private
|
61
8
|
|
62
9
|
def check_max_memory_limit
|
63
|
-
return if
|
10
|
+
return if valid_containers_memory_limit?
|
64
11
|
|
65
12
|
errors.add(:payload, :max_memory_limit_error, max: project.account.container_memory_limit)
|
66
13
|
end
|
67
14
|
|
68
15
|
def check_max_memory_request
|
69
|
-
return if
|
16
|
+
return if valid_containers_memory_request?
|
70
17
|
|
71
18
|
errors.add(:payload, :max_memory_request_error, max: project.account.container_memory_limit)
|
72
19
|
end
|
@@ -11,6 +11,15 @@ module UffizziCore::Concerns::Models::Credential
|
|
11
11
|
|
12
12
|
self.table_name = UffizziCore.table_names[:credentials]
|
13
13
|
|
14
|
+
const_set(:CREDENTIAL_TYPES, [
|
15
|
+
'UffizziCore::Credential::Amazon',
|
16
|
+
'UffizziCore::Credential::Azure',
|
17
|
+
'UffizziCore::Credential::DockerHub',
|
18
|
+
'UffizziCore::Credential::DockerRegistry',
|
19
|
+
'UffizziCore::Credential::GithubContainerRegistry',
|
20
|
+
'UffizziCore::Credential::Google',
|
21
|
+
])
|
22
|
+
|
14
23
|
belongs_to :account
|
15
24
|
|
16
25
|
before_destroy :remove_token
|
@@ -35,28 +44,24 @@ module UffizziCore::Concerns::Models::Credential
|
|
35
44
|
end
|
36
45
|
end
|
37
46
|
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
def docker_hub?
|
43
|
-
type == UffizziCore::Credential::DockerHub.name
|
47
|
+
UffizziCore::ContainerRegistryService.sources.each do |t|
|
48
|
+
define_method :"#{t}?" do
|
49
|
+
type == "UffizziCore::Credential::#{t.to_s.camelize}"
|
50
|
+
end
|
44
51
|
end
|
45
52
|
|
46
|
-
def
|
47
|
-
|
48
|
-
|
53
|
+
def correct?
|
54
|
+
credential = self
|
55
|
+
return false unless credential
|
49
56
|
|
50
|
-
|
51
|
-
|
52
|
-
end
|
57
|
+
container_registry_service = UffizziCore::ContainerRegistryService.init_by_subclass(credential.type)
|
58
|
+
status = container_registry_service.credential_correct?(credential)
|
53
59
|
|
54
|
-
|
55
|
-
|
56
|
-
|
60
|
+
if credential.persisted? && credential.active? && !status
|
61
|
+
Rails.logger.warn("Wrong credential: credential_correct? credential_id=#{credential.id}")
|
62
|
+
end
|
57
63
|
|
58
|
-
|
59
|
-
type == UffizziCore::Credential::Amazon.name
|
64
|
+
status
|
60
65
|
end
|
61
66
|
|
62
67
|
private
|
@@ -9,8 +9,8 @@ module UffizziCore::Concerns::Models::Event
|
|
9
9
|
|
10
10
|
self.table_name = UffizziCore.table_names[:events]
|
11
11
|
|
12
|
-
enumerize :state, in: [:queued, :successful, :deployed, :failed, :building, :timeout, :cancelled, :deploying],
|
13
|
-
scope: true
|
12
|
+
enumerize :state, in: [:waiting, :queued, :successful, :deployed, :failed, :building, :timeout, :cancelled, :deploying],
|
13
|
+
predicates: true, scope: true
|
14
14
|
|
15
15
|
belongs_to :activity_item, touch: true
|
16
16
|
end
|
@@ -13,7 +13,6 @@ module UffizziCore::Concerns::Models::Repo
|
|
13
13
|
|
14
14
|
belongs_to :project
|
15
15
|
has_one :container, inverse_of: :repo, dependent: :destroy
|
16
|
-
has_many :builds, dependent: :destroy
|
17
16
|
|
18
17
|
validates :dockerfile_path, presence: true, if: :dockerfile?
|
19
18
|
validates :delete_preview_after, numericality: { greater_than: 0, only_integer: true }, allow_nil: true
|
@@ -19,5 +19,21 @@ module UffizziCore::Concerns::Models::Template
|
|
19
19
|
|
20
20
|
validates :name, presence: true
|
21
21
|
validates :name, uniqueness: { scope: :project }, if: -> { compose_file.blank? || compose_file.kind.main? }
|
22
|
+
|
23
|
+
def valid_containers_memory_limit?
|
24
|
+
containers_attributes = payload['containers_attributes']
|
25
|
+
container_memory_limit = project.account.container_memory_limit
|
26
|
+
return true if container_memory_limit.nil?
|
27
|
+
|
28
|
+
containers_attributes.all? { |container| container['memory_limit'].to_i <= container_memory_limit }
|
29
|
+
end
|
30
|
+
|
31
|
+
def valid_containers_memory_request?
|
32
|
+
containers_attributes = payload['containers_attributes']
|
33
|
+
container_memory_limit = project.account.container_memory_limit
|
34
|
+
return true if container_memory_limit.nil?
|
35
|
+
|
36
|
+
containers_attributes.all? { |container| container['memory_request'].to_i <= container_memory_limit }
|
37
|
+
end
|
22
38
|
end
|
23
39
|
end
|
@@ -12,7 +12,6 @@ class UffizziCore::Api::Cli::V1::Projects::DeploymentSerializer < UffizziCore::B
|
|
12
12
|
:preview_url,
|
13
13
|
:tag,
|
14
14
|
:branch,
|
15
|
-
:commit,
|
16
15
|
:image_id,
|
17
16
|
:ingress_container_ready,
|
18
17
|
:ingress_container_state,
|
@@ -35,10 +34,6 @@ class UffizziCore::Api::Cli::V1::Projects::DeploymentSerializer < UffizziCore::B
|
|
35
34
|
object.ingress_container&.repo&.branch
|
36
35
|
end
|
37
36
|
|
38
|
-
def commit
|
39
|
-
object.ingress_container&.repo&.builds&.deployed&.last&.commit.to_s.slice(0..5)
|
40
|
-
end
|
41
|
-
|
42
37
|
def image_id
|
43
38
|
object.ingress_container&.repo&.name
|
44
39
|
end
|
@@ -9,15 +9,7 @@ class UffizziCore::Api::Cli::V1::Projects::Deployments::ContainerSerializer < Uf
|
|
9
9
|
|
10
10
|
def name
|
11
11
|
image_name = object.image.split('/').pop
|
12
|
-
|
13
|
-
container_name = "#{image_name}:#{object.tag}"
|
14
|
-
|
15
|
-
if !commit.nil?
|
16
|
-
short_commit_hash = commit.slice(0..5)
|
17
|
-
container_name = "#{container_name}@#{short_commit_hash}"
|
18
|
-
end
|
19
|
-
|
20
|
-
container_name
|
12
|
+
"#{image_name}:#{object.tag}"
|
21
13
|
end
|
22
14
|
|
23
15
|
def secret_variables
|
@@ -11,7 +11,7 @@ class UffizziCore::Controller::CreateCredential::CredentialSerializer < UffizziC
|
|
11
11
|
|
12
12
|
def password
|
13
13
|
if object.amazon?
|
14
|
-
UffizziCore::
|
14
|
+
UffizziCore::ContainerRegistry::AmazonService.access_token(object)
|
15
15
|
else
|
16
16
|
object.password
|
17
17
|
end
|
@@ -37,17 +37,8 @@ class UffizziCore::ActivityItemService
|
|
37
37
|
container = activity_item.container
|
38
38
|
repo = container.repo
|
39
39
|
credential = UffizziCore::RepoService.credential(repo)
|
40
|
-
|
41
|
-
digest =
|
42
|
-
when UffizziCore::Repo::DockerHub.name
|
43
|
-
UffizziCore::DockerHubService.digest(credential, activity_item.image, activity_item.tag)
|
44
|
-
when UffizziCore::Repo::Azure.name
|
45
|
-
UffizziCore::AzureService.digest(credential, activity_item.image, activity_item.tag)
|
46
|
-
when UffizziCore::Repo::Google.name
|
47
|
-
UffizziCore::GoogleService.digest(credential, activity_item.image, activity_item.tag)
|
48
|
-
when UffizziCore::Repo::Amazon.name
|
49
|
-
UffizziCore::AmazonService.digest(credential, activity_item.image, activity_item.tag)
|
50
|
-
end
|
40
|
+
container_registry_service = UffizziCore::ContainerRegistryService.init_by_subclass(repo.type)
|
41
|
+
digest = container_registry_service.digest(credential, activity_item.image, activity_item.tag)
|
51
42
|
|
52
43
|
activity_item.update!(digest: digest)
|
53
44
|
|
@@ -21,13 +21,11 @@ class UffizziCore::ComposeFile::Builders::ContainerBuilderService
|
|
21
21
|
healthcheck_data = container_data[:healthcheck] || {}
|
22
22
|
volumes_data = container_data[:volumes] || []
|
23
23
|
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
host_volumes_dependencies =
|
29
|
-
compose_dependencies, container_name
|
30
|
-
)
|
24
|
+
github_deps_service = UffizziCore::ComposeFile::GithubDependenciesService
|
25
|
+
|
26
|
+
env_file_dependencies = github_deps_service.env_file_dependencies_for_container(compose_dependencies, container_name)
|
27
|
+
configs_dependencies = github_deps_service.configs_dependencies_for_container(compose_dependencies, container_name)
|
28
|
+
host_volumes_dependencies = github_deps_service.host_volumes_dependencies_for_container(compose_dependencies, container_name)
|
31
29
|
is_ingress = ingress_container?(container_name, ingress_data)
|
32
30
|
repo_attributes = repo_attributes(container_data, continuous_preview_global_data)
|
33
31
|
additional_subdomains = is_ingress ? ingress_data.fetch(:additional_subdomains, []) : []
|
@@ -59,6 +57,10 @@ class UffizziCore::ComposeFile::Builders::ContainerBuilderService
|
|
59
57
|
|
60
58
|
private
|
61
59
|
|
60
|
+
def container_registry(container_data)
|
61
|
+
@container_registry ||= UffizziCore::ContainerRegistryService.init_by_container(container_data)
|
62
|
+
end
|
63
|
+
|
62
64
|
def repo_attributes(container_data, continuous_preview_global_data)
|
63
65
|
repo_attributes = build_repo_attributes(container_data)
|
64
66
|
continuous_preview_container_data = container_data[:'x-uffizzi-continuous-preview'] || container_data[:'x-uffizzi-continuous-previews']
|
@@ -66,6 +68,20 @@ class UffizziCore::ComposeFile::Builders::ContainerBuilderService
|
|
66
68
|
set_continuous_preview_attributes_to_repo(repo_attributes, continuous_preview_global_data.to_h, continuous_preview_container_data.to_h)
|
67
69
|
end
|
68
70
|
|
71
|
+
def build_repo_attributes(container_data)
|
72
|
+
container_registry = container_registry(container_data)
|
73
|
+
repo_type = container_registry.repo_type.name
|
74
|
+
raise UffizziCore::ComposeFile::BuildError, I18n.t('compose.invalid_repo_type') if repo_type.blank?
|
75
|
+
|
76
|
+
image_data = container_registry.image_data
|
77
|
+
if container_registry.image_available?(credentials)
|
78
|
+
docker_repo_builder = UffizziCore::ComposeFile::Builders::DockerRepoBuilderService.new(repo_type)
|
79
|
+
return docker_repo_builder.build_attributes(image_data)
|
80
|
+
end
|
81
|
+
|
82
|
+
raise UffizziCore::ComposeFile::BuildError, I18n.t('compose.unprocessable_image', value: container_registry.type)
|
83
|
+
end
|
84
|
+
|
69
85
|
def set_continuous_preview_attributes_to_repo(repo_attributes, global_data, container_data)
|
70
86
|
condition_attributes = [
|
71
87
|
:deploy_preview_when_pull_request_is_opened,
|
@@ -78,16 +94,17 @@ class UffizziCore::ComposeFile::Builders::ContainerBuilderService
|
|
78
94
|
condition_attributes.each do |attribute|
|
79
95
|
repo_attributes[attribute] = select_continuous_preview_attribute(global_data[attribute], container_data[attribute], false)
|
80
96
|
end
|
81
|
-
|
82
|
-
|
83
|
-
|
97
|
+
|
98
|
+
global = global_data.dig(:delete_preview_after, :value)
|
99
|
+
local = container_data.dig(:delete_preview_after, :value)
|
100
|
+
repo_attributes[:delete_preview_after] = select_continuous_preview_attribute(global, local, nil)
|
84
101
|
|
85
102
|
repo_attributes
|
86
103
|
end
|
87
104
|
|
88
105
|
def select_continuous_preview_attribute(global_attribute, local_attribute, default_attribute)
|
89
|
-
return local_attribute if
|
90
|
-
return global_attribute if
|
106
|
+
return local_attribute if local_attribute.present?
|
107
|
+
return global_attribute if global_attribute.present?
|
91
108
|
|
92
109
|
default_attribute
|
93
110
|
end
|
@@ -104,24 +121,15 @@ class UffizziCore::ComposeFile::Builders::ContainerBuilderService
|
|
104
121
|
|
105
122
|
def image(container_data, image_data, build_data, credentials)
|
106
123
|
if image_data.present?
|
107
|
-
image_name(
|
124
|
+
container_registry(container_data).image_name(credentials)
|
108
125
|
else
|
109
126
|
"#{build_data[:account_name]}/#{build_data[:repository_name]}"
|
110
127
|
end
|
111
128
|
end
|
112
129
|
|
113
|
-
def image_name(container_data
|
114
|
-
|
115
|
-
|
116
|
-
!UffizziCore::ComposeFile::ContainerService.github_container_registry?(container_data) &&
|
117
|
-
!UffizziCore::ComposeFile::ContainerService.docker_registry?(container_data)
|
118
|
-
image_data[:name]
|
119
|
-
elsif UffizziCore::ComposeFile::ContainerService.docker_registry?(container_data) &&
|
120
|
-
credential_by_scope(credentials, :docker_registry).nil?
|
121
|
-
[image_data[:registry_url], image_data[:namespace], image_data[:name]].compact.join('/')
|
122
|
-
else
|
123
|
-
"#{image_data[:namespace]}/#{image_data[:name]}"
|
124
|
-
end
|
130
|
+
def image_name(container_data)
|
131
|
+
container_registry = container_registry(container_data)
|
132
|
+
container_registry.image_name(credentials)
|
125
133
|
end
|
126
134
|
|
127
135
|
def ingress_container?(container_name, ingress)
|
@@ -130,13 +138,11 @@ class UffizziCore::ComposeFile::Builders::ContainerBuilderService
|
|
130
138
|
|
131
139
|
def entrypoint(container_data)
|
132
140
|
entrypoint = container_data[:entrypoint]
|
133
|
-
|
134
141
|
entrypoint.present? ? entrypoint.to_s : nil
|
135
142
|
end
|
136
143
|
|
137
144
|
def command(container_data)
|
138
145
|
command = container_data[:command]
|
139
|
-
|
140
146
|
command.present? ? command.to_s : nil
|
141
147
|
end
|
142
148
|
|
@@ -169,59 +175,12 @@ class UffizziCore::ComposeFile::Builders::ContainerBuilderService
|
|
169
175
|
memory_value
|
170
176
|
end
|
171
177
|
|
172
|
-
def build_repo_attributes(container_data)
|
173
|
-
repo_type = repo_type(container_data)
|
174
|
-
image_data = container_data[:image]
|
175
|
-
|
176
|
-
case repo_type
|
177
|
-
when UffizziCore::Repo::DockerHub.name
|
178
|
-
build_docker_repo_attributes(image_data, credentials, :docker_hub, UffizziCore::Repo::DockerHub.name)
|
179
|
-
when UffizziCore::Repo::DockerRegistry.name
|
180
|
-
build_docker_repo_attributes(image_data, credentials, :docker_registry, UffizziCore::Repo::DockerRegistry.name)
|
181
|
-
when UffizziCore::Repo::Azure.name
|
182
|
-
build_docker_repo_attributes(image_data, credentials, :azure, UffizziCore::Repo::Azure.name)
|
183
|
-
when UffizziCore::Repo::Google.name
|
184
|
-
build_docker_repo_attributes(image_data, credentials, :google, UffizziCore::Repo::Google.name)
|
185
|
-
when UffizziCore::Repo::GithubContainerRegistry.name
|
186
|
-
build_docker_repo_attributes(image_data, credentials, :github_container_registry, UffizziCore::Repo::GithubContainerRegistry.name)
|
187
|
-
when UffizziCore::Repo::Amazon.name
|
188
|
-
build_docker_repo_attributes(image_data, credentials, :amazon, UffizziCore::Repo::Amazon.name)
|
189
|
-
else
|
190
|
-
raise UffizziCore::ComposeFile::BuildError, I18n.t('compose.invalid_repo_type')
|
191
|
-
end
|
192
|
-
end
|
193
|
-
|
194
|
-
def repo_type(container_data)
|
195
|
-
if UffizziCore::ComposeFile::ContainerService.azure?(container_data)
|
196
|
-
UffizziCore::Repo::Azure.name
|
197
|
-
elsif UffizziCore::ComposeFile::ContainerService.docker_hub?(container_data)
|
198
|
-
UffizziCore::Repo::DockerHub.name
|
199
|
-
elsif UffizziCore::ComposeFile::ContainerService.docker_registry?(container_data)
|
200
|
-
UffizziCore::Repo::DockerRegistry.name
|
201
|
-
elsif UffizziCore::ComposeFile::ContainerService.google?(container_data)
|
202
|
-
UffizziCore::Repo::Google.name
|
203
|
-
elsif UffizziCore::ComposeFile::ContainerService.github_container_registry?(container_data)
|
204
|
-
UffizziCore::Repo::GithubContainerRegistry.name
|
205
|
-
elsif UffizziCore::ComposeFile::ContainerService.amazon?(container_data)
|
206
|
-
UffizziCore::Repo::Amazon.name
|
207
|
-
end
|
208
|
-
end
|
209
|
-
|
210
178
|
def continuously_deploy(deploy_data)
|
211
179
|
return :disabled if deploy_data[:auto] == false
|
212
180
|
|
213
181
|
:enabled
|
214
182
|
end
|
215
183
|
|
216
|
-
def build_docker_repo_attributes(image_data, credentials, scope, repo_type)
|
217
|
-
credential = credential_by_scope(credentials, scope)
|
218
|
-
if UffizziCore::ComposeFile::ContainerService.image_available?(credential, image_data, scope)
|
219
|
-
return docker_builder(repo_type).build_attributes(image_data)
|
220
|
-
end
|
221
|
-
|
222
|
-
raise UffizziCore::ComposeFile::BuildError, I18n.t('compose.unprocessable_image', value: scope)
|
223
|
-
end
|
224
|
-
|
225
184
|
def variables(variables_data, dependencies)
|
226
185
|
variables_builder.build_attributes(variables_data, dependencies)
|
227
186
|
end
|
@@ -243,15 +202,7 @@ class UffizziCore::ComposeFile::Builders::ContainerBuilderService
|
|
243
202
|
.build_attributes(host_volumes_data, host_volumes_dependencies, project)
|
244
203
|
end
|
245
204
|
|
246
|
-
def docker_builder(type)
|
247
|
-
@docker_builder ||= UffizziCore::ComposeFile::Builders::DockerRepoBuilderService.new(type)
|
248
|
-
end
|
249
|
-
|
250
205
|
def variables_builder
|
251
206
|
@variables_builder ||= UffizziCore::ComposeFile::Builders::VariablesBuilderService.new(project)
|
252
207
|
end
|
253
|
-
|
254
|
-
def credential_by_scope(credentials, scope)
|
255
|
-
credentials.send(scope).first
|
256
|
-
end
|
257
208
|
end
|
@@ -2,48 +2,6 @@
|
|
2
2
|
|
3
3
|
class UffizziCore::ComposeFile::ContainerService
|
4
4
|
class << self
|
5
|
-
def azure?(container)
|
6
|
-
registry_url = container.dig(:image, :registry_url)
|
7
|
-
|
8
|
-
registry_url.present? && registry_url.include?('azurecr.io')
|
9
|
-
end
|
10
|
-
|
11
|
-
def google?(container)
|
12
|
-
registry_url = container.dig(:image, :registry_url)
|
13
|
-
|
14
|
-
registry_url.present? && registry_url.include?('gcr.io')
|
15
|
-
end
|
16
|
-
|
17
|
-
def amazon?(container)
|
18
|
-
registry_url = container.dig(:image, :registry_url)
|
19
|
-
|
20
|
-
registry_url.present? && registry_url.include?('amazonaws.com')
|
21
|
-
end
|
22
|
-
|
23
|
-
def docker_hub?(container)
|
24
|
-
registry_url = container.dig(:image, :registry_url)
|
25
|
-
repository_url = container.dig(:build, :repository_url)
|
26
|
-
|
27
|
-
registry_url.nil? && repository_url.nil?
|
28
|
-
end
|
29
|
-
|
30
|
-
def docker_registry?(container)
|
31
|
-
registry_url = container.dig(:image, :registry_url)
|
32
|
-
return false if registry_url.nil?
|
33
|
-
|
34
|
-
registry_domain_regexp = /(\w+\.\w{2,})(?::\d+)?\z/
|
35
|
-
registry_domain = registry_url.match(registry_domain_regexp)&.to_a&.last
|
36
|
-
return false if registry_domain.nil?
|
37
|
-
|
38
|
-
['amazonaws.com', 'azurecr.io', 'gcr.io', 'ghcr.io'].exclude?(registry_domain)
|
39
|
-
end
|
40
|
-
|
41
|
-
def github_container_registry?(container)
|
42
|
-
registry_url = container.dig(:image, :registry_url)
|
43
|
-
|
44
|
-
registry_url.present? && registry_url.include?('ghcr.io')
|
45
|
-
end
|
46
|
-
|
47
5
|
def has_secret?(container, secret)
|
48
6
|
container['secret_variables'].any? { |container_secret| container_secret['name'] == secret['name'] }
|
49
7
|
end
|
@@ -54,35 +12,5 @@ class UffizziCore::ComposeFile::ContainerService
|
|
54
12
|
|
55
13
|
container
|
56
14
|
end
|
57
|
-
|
58
|
-
def credential_for_container(container, credentials)
|
59
|
-
if UffizziCore::ComposeFile::ContainerService.azure?(container)
|
60
|
-
detect_credential(container, credentials, :azure)
|
61
|
-
elsif UffizziCore::ComposeFile::ContainerService.docker_hub?(container)
|
62
|
-
detect_credential(container, credentials, :docker_hub)
|
63
|
-
elsif UffizziCore::ComposeFile::ContainerService.google?(container)
|
64
|
-
detect_credential(container, credentials, :google)
|
65
|
-
end
|
66
|
-
end
|
67
|
-
|
68
|
-
def detect_credential(container, credentials, type)
|
69
|
-
credential = credentials.detect { |item| item.send("#{type}?") }
|
70
|
-
|
71
|
-
return credential if image_available?(credential, container[:image], type)
|
72
|
-
|
73
|
-
raise UffizziCore::ComposeFile::CredentialError.new(I18n.t('compose.unprocessable_image', value: type))
|
74
|
-
end
|
75
|
-
|
76
|
-
def image_available?(credential, image_data, type)
|
77
|
-
case type
|
78
|
-
when :docker_hub
|
79
|
-
UffizziCore::DockerHubService.image_available?(credential, image_data)
|
80
|
-
when :docker_registry
|
81
|
-
UffizziCore::DockerRegistryService.image_available?(credential, image_data)
|
82
|
-
else
|
83
|
-
# TODO check image availability in other registry types
|
84
|
-
credential.present?
|
85
|
-
end
|
86
|
-
end
|
87
15
|
end
|
88
16
|
end
|