uffizzi_core 0.6.0 → 0.7.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/app/controllers/uffizzi_core/api/cli/v1/projects/deployments_controller.rb +12 -4
- data/app/forms/uffizzi_core/api/cli/v1/deployment/create_form.rb +1 -0
- data/app/forms/uffizzi_core/api/cli/v1/deployment/update_form.rb +41 -40
- data/app/lib/uffizzi_core/concerns/models/container.rb +1 -1
- data/app/lib/uffizzi_core/concerns/models/credential.rb +5 -1
- data/app/repositories/uffizzi_core/deployment_repo.rb +4 -0
- data/app/serializers/uffizzi_core/api/cli/v1/projects/deployment_serializer.rb +2 -5
- data/app/serializers/uffizzi_core/api/cli/v1/projects/deployments_serializer/user_serializer.rb +7 -0
- data/app/serializers/uffizzi_core/api/cli/v1/projects/deployments_serializer.rb +14 -0
- data/app/services/uffizzi_core/compose_file/parsers/services/image_parser_service.rb +10 -7
- data/app/services/uffizzi_core/container_service.rb +1 -1
- data/app/services/uffizzi_core/deployment_service.rb +8 -5
- data/db/migrate/20220805164628_add_metadata_to_deployment.rb +7 -0
- data/lib/uffizzi_core/version.rb +1 -1
- metadata +5 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 25654d45dce9f26feb5a3cca55a5891bb389216e749512b2900898bec4a8da0b
|
4
|
+
data.tar.gz: cb7784c03bcffb216adc343ae30e0ef0c51e3038791da4fe0229b86179cdc8e9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c3b6ae9974961ae5d39e723264e6c72fa0f4dfa9f99085a6550a98af67afd6ddcbd92f98e7f815ff602bb7f6a3144d2f87ac9d61a58f228099b9dedd537ce6be
|
7
|
+
data.tar.gz: 572bcfcc9d1e3396d721a83a60c703db10c0b3848031e35b63aa26065b67ceb6fc11bb5278fd6b383e4686a5885758d45d69b0a3c3314cda4f6d93fc3a81d93b
|
@@ -14,7 +14,10 @@ class UffizziCore::Api::Cli::V1::Projects::DeploymentsController < UffizziCore::
|
|
14
14
|
# @response [Array<Deployment>] 200 OK
|
15
15
|
# @response 401 Not authorized
|
16
16
|
def index
|
17
|
-
|
17
|
+
search_labels = JSON.parse(q_param)
|
18
|
+
filtered_deployments = deployments.with_labels(search_labels)
|
19
|
+
|
20
|
+
respond_with filtered_deployments, each_serializer: UffizziCore::Api::Cli::V1::Projects::DeploymentsSerializer
|
18
21
|
end
|
19
22
|
|
20
23
|
# Get deployment information by id
|
@@ -51,7 +54,7 @@ class UffizziCore::Api::Cli::V1::Projects::DeploymentsController < UffizziCore::
|
|
51
54
|
errors = check_credentials(compose_file)
|
52
55
|
return render_errors(errors) if errors.present?
|
53
56
|
|
54
|
-
deployment = UffizziCore::DeploymentService.create_from_compose(compose_file, resource_project, current_user)
|
57
|
+
deployment = UffizziCore::DeploymentService.create_from_compose(compose_file, resource_project, current_user, metadata_params)
|
55
58
|
|
56
59
|
respond_with deployment
|
57
60
|
end
|
@@ -82,8 +85,9 @@ class UffizziCore::Api::Cli::V1::Projects::DeploymentsController < UffizziCore::
|
|
82
85
|
errors = check_credentials(compose_file)
|
83
86
|
return render_errors(errors) if errors.present?
|
84
87
|
|
85
|
-
deployment =
|
86
|
-
updated_deployment = UffizziCore::DeploymentService.update_from_compose(compose_file, resource_project, current_user, deployment
|
88
|
+
deployment = deployments.find(params[:id])
|
89
|
+
updated_deployment = UffizziCore::DeploymentService.update_from_compose(compose_file, resource_project, current_user, deployment,
|
90
|
+
metadata_params)
|
87
91
|
|
88
92
|
respond_with updated_deployment
|
89
93
|
end
|
@@ -171,6 +175,10 @@ class UffizziCore::Api::Cli::V1::Projects::DeploymentsController < UffizziCore::
|
|
171
175
|
params.permit(dependencies: [:name, :path, :source, :content])
|
172
176
|
end
|
173
177
|
|
178
|
+
def metadata_params
|
179
|
+
params[:metadata]
|
180
|
+
end
|
181
|
+
|
174
182
|
def render_invalid_file
|
175
183
|
render json: { errors: { state: ['Invalid compose file'] } }, status: :unprocessable_entity
|
176
184
|
end
|
@@ -3,46 +3,47 @@
|
|
3
3
|
class UffizziCore::Api::Cli::V1::Deployment::UpdateForm < UffizziCore::Deployment
|
4
4
|
include UffizziCore::ApplicationForm
|
5
5
|
|
6
|
-
permit
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
6
|
+
permit :metadata,
|
7
|
+
containers_attributes: [
|
8
|
+
:image,
|
9
|
+
:service_name,
|
10
|
+
:tag,
|
11
|
+
:port,
|
12
|
+
:public,
|
13
|
+
:memory_limit,
|
14
|
+
:memory_request,
|
15
|
+
:entrypoint,
|
16
|
+
:command,
|
17
|
+
:receive_incoming_requests,
|
18
|
+
:continuously_deploy,
|
19
|
+
{ variables: [:name, :value],
|
20
|
+
secret_variables: [:name, :value],
|
21
|
+
volumes: [:source, :target, :type, :read_only],
|
22
|
+
repo_attributes: [
|
23
|
+
:namespace,
|
24
|
+
:name,
|
25
|
+
:slug,
|
26
|
+
:type,
|
27
|
+
:description,
|
28
|
+
:is_private,
|
29
|
+
:repository_id,
|
30
|
+
:branch,
|
31
|
+
:kind,
|
32
|
+
:dockerfile_path,
|
33
|
+
:dockerfile_context_path,
|
34
|
+
:deploy_preview_when_pull_request_is_opened,
|
35
|
+
:delete_preview_when_pull_request_is_closed,
|
36
|
+
:deploy_preview_when_image_tag_is_created,
|
37
|
+
:delete_preview_when_image_tag_is_updated,
|
38
|
+
:share_to_github,
|
39
|
+
:delete_preview_after,
|
40
|
+
{ args: [:name, :value] },
|
41
|
+
],
|
42
|
+
container_config_files_attributes: [
|
43
|
+
:config_file_id,
|
44
|
+
:mount_path,
|
45
|
+
] },
|
46
|
+
]
|
46
47
|
|
47
48
|
validate :check_all_containers_have_unique_ports
|
48
49
|
validate :check_exists_ingress_container
|
@@ -45,7 +45,7 @@ module UffizziCore::Concerns::Models::Container
|
|
45
45
|
validates :command, 'uffizzi_core/image_command_args': true, allow_nil: true
|
46
46
|
validates :tag, presence: true
|
47
47
|
|
48
|
-
aasm :continuously_deploy, column: :continuously_deploy do
|
48
|
+
aasm :continuously_deploy, column: :continuously_deploy, namespace: :cd do
|
49
49
|
state :disabled, initial: true
|
50
50
|
state :enabled
|
51
51
|
end
|
@@ -27,6 +27,10 @@ module UffizziCore::Concerns::Models::Credential
|
|
27
27
|
event :unauthorize do
|
28
28
|
transitions from: [:not_connected, :active], to: :unauthorized
|
29
29
|
end
|
30
|
+
|
31
|
+
event :disconnect do
|
32
|
+
transitions from: [:active, :unauthorized], to: :not_connected
|
33
|
+
end
|
30
34
|
end
|
31
35
|
|
32
36
|
def github_container_registry?
|
@@ -59,7 +63,7 @@ module UffizziCore::Concerns::Models::Credential
|
|
59
63
|
account.projects.find_each do |project|
|
60
64
|
project.deployments.find_each do |deployment|
|
61
65
|
containers = deployment.containers
|
62
|
-
attributes = { continuously_deploy: UffizziCore::Container::
|
66
|
+
attributes = { continuously_deploy: UffizziCore::Container::STATE_CD_DISABLED }
|
63
67
|
|
64
68
|
containers.with_docker_hub_repo.update_all(attributes) if docker_hub?
|
65
69
|
end
|
@@ -12,5 +12,9 @@ module UffizziCore::DeploymentRepo
|
|
12
12
|
scope :active_for_credential_id, ->(credential_id) {
|
13
13
|
active.joins(project: :credentials).merge(UffizziCore::Project.active).where(credentials: { id: credential_id })
|
14
14
|
}
|
15
|
+
|
16
|
+
scope :with_labels, ->(labels) {
|
17
|
+
where("#{UffizziCore::Deployment.table_name}.metadata @> ?", labels.to_json)
|
18
|
+
}
|
15
19
|
end
|
16
20
|
end
|
@@ -16,16 +16,13 @@ class UffizziCore::Api::Cli::V1::Projects::DeploymentSerializer < UffizziCore::B
|
|
16
16
|
:image_id,
|
17
17
|
:ingress_container_ready,
|
18
18
|
:ingress_container_state,
|
19
|
-
:creation_source
|
19
|
+
:creation_source,
|
20
|
+
:metadata
|
20
21
|
|
21
22
|
has_many :containers
|
22
23
|
|
23
24
|
belongs_to :deployed_by
|
24
25
|
|
25
|
-
def deployed_by
|
26
|
-
object.deployed_by
|
27
|
-
end
|
28
|
-
|
29
26
|
def containers
|
30
27
|
object.containers.active
|
31
28
|
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
class UffizziCore::Api::Cli::V1::Projects::DeploymentsSerializer < UffizziCore::BaseSerializer
|
4
|
+
type :deployment
|
5
|
+
|
6
|
+
attributes :id,
|
7
|
+
:created_at,
|
8
|
+
:updated_at,
|
9
|
+
:state,
|
10
|
+
:preview_url,
|
11
|
+
:metadata
|
12
|
+
|
13
|
+
belongs_to :deployed_by
|
14
|
+
end
|
@@ -5,9 +5,8 @@ class UffizziCore::ComposeFile::Parsers::Services::ImageParserService
|
|
5
5
|
def parse(value)
|
6
6
|
return {} if value.blank?
|
7
7
|
|
8
|
-
|
9
|
-
|
10
|
-
raise parse_error if image_path.blank?
|
8
|
+
image_path, tag = get_image_path_and_tag(value)
|
9
|
+
raise_parse_error(value) if image_path.blank?
|
11
10
|
|
12
11
|
tag = Settings.compose.default_tag if tag.blank?
|
13
12
|
|
@@ -27,7 +26,11 @@ class UffizziCore::ComposeFile::Parsers::Services::ImageParserService
|
|
27
26
|
|
28
27
|
private
|
29
28
|
|
30
|
-
def
|
29
|
+
def raise_parse_error(value)
|
30
|
+
raise UffizziCore::ComposeFile::ParseError, I18n.t('compose.invalid_image_value', value: value)
|
31
|
+
end
|
32
|
+
|
33
|
+
def get_image_path_and_tag(value)
|
31
34
|
image_path_parts = value.downcase.split(':')
|
32
35
|
case image_path_parts.size
|
33
36
|
when 1
|
@@ -40,18 +43,18 @@ class UffizziCore::ComposeFile::Parsers::Services::ImageParserService
|
|
40
43
|
elsif tag_pattern.match?(value)
|
41
44
|
[image_path_parts[0], image_path_parts[1]]
|
42
45
|
else
|
43
|
-
|
46
|
+
raise_parse_error(value)
|
44
47
|
end
|
45
48
|
when 3
|
46
49
|
["#{image_path_parts[0]}:#{image_path_parts[1]}", image_path_parts[2]]
|
47
50
|
else
|
48
|
-
|
51
|
+
raise_parse_error(value)
|
49
52
|
end
|
50
53
|
end
|
51
54
|
|
52
55
|
def url?(image_path)
|
53
56
|
uri = URI(add_https_if_needed(image_path))
|
54
|
-
uri.host.present? && uri.host =~
|
57
|
+
uri.host.present? && uri.host =~ /(localhost(:\d+)?|\w+\.(\w+\.)*\w+)/ && uri.path.present?
|
55
58
|
rescue URI::InvalidURIError
|
56
59
|
false
|
57
60
|
end
|
@@ -20,7 +20,7 @@ class UffizziCore::ContainerService
|
|
20
20
|
end
|
21
21
|
|
22
22
|
def continuously_deploy_enabled?(container)
|
23
|
-
container.aasm(:continuously_deploy).current_state == UffizziCore::Container::
|
23
|
+
container.aasm(:continuously_deploy).current_state == UffizziCore::Container::STATE_CD_ENABLED
|
24
24
|
end
|
25
25
|
|
26
26
|
def valid_memory_limit?(container)
|
@@ -12,12 +12,13 @@ class UffizziCore::DeploymentService
|
|
12
12
|
}.freeze
|
13
13
|
|
14
14
|
class << self
|
15
|
-
def create_from_compose(compose_file, project, user)
|
15
|
+
def create_from_compose(compose_file, project, user, metadata)
|
16
16
|
deployment_attributes = ActionController::Parameters.new(compose_file.template.payload)
|
17
17
|
deployment_form = UffizziCore::Api::Cli::V1::Deployment::CreateForm.new(deployment_attributes)
|
18
18
|
deployment_form.assign_dependences!(project, user)
|
19
19
|
deployment_form.compose_file = compose_file
|
20
20
|
deployment_form.creation_source = UffizziCore::Deployment.creation_source.compose_file_manual
|
21
|
+
deployment_form.metadata = metadata || {}
|
21
22
|
|
22
23
|
if deployment_form.save
|
23
24
|
update_subdomain!(deployment_form)
|
@@ -28,22 +29,24 @@ class UffizziCore::DeploymentService
|
|
28
29
|
deployment_form
|
29
30
|
end
|
30
31
|
|
31
|
-
def update_from_compose(compose_file, project, user, deployment)
|
32
|
+
def update_from_compose(compose_file, project, user, deployment, metadata)
|
32
33
|
deployment_attributes = ActionController::Parameters.new(compose_file.template.payload)
|
33
34
|
|
34
35
|
deployment_form = UffizziCore::Api::Cli::V1::Deployment::UpdateForm.new(deployment_attributes)
|
35
36
|
deployment_form.assign_dependences!(project, user)
|
36
37
|
deployment_form.compose_file = compose_file
|
38
|
+
deployment_form.metadata = metadata || {}
|
37
39
|
|
38
40
|
ActiveRecord::Base.transaction do
|
39
41
|
deployment.containers.destroy_all
|
40
42
|
deployment.compose_file.destroy! if deployment.compose_file&.kind&.temporary?
|
41
|
-
|
42
|
-
deployment.update!(
|
43
|
+
params = {
|
43
44
|
containers: deployment_form.containers,
|
44
45
|
compose_file_id: compose_file.id,
|
45
46
|
creation_source: UffizziCore::Deployment.creation_source.compose_file_manual,
|
46
|
-
|
47
|
+
metadata: deployment_form.metadata,
|
48
|
+
}
|
49
|
+
deployment.update!(params)
|
47
50
|
end
|
48
51
|
|
49
52
|
deployment
|
data/lib/uffizzi_core/version.rb
CHANGED
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.
|
4
|
+
version: 0.7.1
|
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-08-
|
12
|
+
date: 2022-08-23 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: aasm
|
@@ -877,6 +877,8 @@ files:
|
|
877
877
|
- app/serializers/uffizzi_core/api/cli/v1/projects/deployments/container_serializer.rb
|
878
878
|
- app/serializers/uffizzi_core/api/cli/v1/projects/deployments/container_serializer/container_config_file_serializer.rb
|
879
879
|
- app/serializers/uffizzi_core/api/cli/v1/projects/deployments/container_serializer/container_config_file_serializer/config_file_serializer.rb
|
880
|
+
- app/serializers/uffizzi_core/api/cli/v1/projects/deployments_serializer.rb
|
881
|
+
- app/serializers/uffizzi_core/api/cli/v1/projects/deployments_serializer/user_serializer.rb
|
880
882
|
- app/serializers/uffizzi_core/api/cli/v1/projects/secret_serializer.rb
|
881
883
|
- app/serializers/uffizzi_core/api/cli/v1/short_project_serializer.rb
|
882
884
|
- app/serializers/uffizzi_core/api/cli/v1/user_serializer.rb
|
@@ -964,6 +966,7 @@ files:
|
|
964
966
|
- db/migrate/20220422151523_add_volumes_to_uffizzi_core_containers.rb
|
965
967
|
- db/migrate/20220525113412_rename_name_to_uffizzi_containers.rb
|
966
968
|
- db/migrate/20220704135629_add_disabled_at_to_deployments.rb
|
969
|
+
- db/migrate/20220805164628_add_metadata_to_deployment.rb
|
967
970
|
- db/seeds.rb
|
968
971
|
- lib/tasks/uffizzi_core_tasks.rake
|
969
972
|
- lib/uffizzi_core.rb
|