Skip to content

Commit

Permalink
Merge pull request #403 from UffizziCloud/feature/402_support_custom_…
Browse files Browse the repository at this point in the history
…creation_sources_for_self_hosted_versions

[402] removed validation on create_source inclusion
  • Loading branch information
moklidia authored Apr 10, 2023
2 parents a4b1356 + d2757ac commit 73c3c8a
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 14 deletions.
4 changes: 0 additions & 4 deletions core/app/lib/uffizzi_core/concerns/models/deployment.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,8 @@ module UffizziCore::Concerns::Models::Deployment
has_many :activity_items, dependent: :destroy

has_one :ingress_container, -> { where(receive_incoming_requests: true) }, class_name: UffizziCore::Container.name

validates :kind, presence: true

enumerize :creation_source, in: [:manual, :demo, :continuous_preview, :compose_file_manual, :compose_file_continuous_preview],
predicates: true, scope: true, default: :manual

accepts_nested_attributes_for :containers, allow_destroy: true

after_destroy_commit :clean
Expand Down
3 changes: 3 additions & 0 deletions core/app/models/uffizzi_core/deployment.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,7 @@

class UffizziCore::Deployment < UffizziCore::ApplicationRecord
include UffizziCore::Concerns::Models::Deployment

const_set(:COMPOSE_FILE_MANUAL, :compose_file_manual)
validates :creation_source, presence: true
end
2 changes: 1 addition & 1 deletion core/app/services/uffizzi_core/deployment_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ def create_from_compose(compose_file, project, user, params)
deployment_form = UffizziCore::Api::Cli::V1::Deployment::CreateForm.new(deployment_attributes)
deployment_form.assign_dependences!(project, user)
deployment_form.compose_file = compose_file
deployment_form.creation_source = params[:creation_source] || UffizziCore::Deployment.creation_source.compose_file_manual
deployment_form.creation_source = params[:creation_source] || UffizziCore::Deployment::COMPOSE_FILE_MANUAL
deployment_form.metadata = params[:metadata] || {}

run_deployment_creation_tasks(deployment_form) if deployment_form.save
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -142,13 +142,13 @@ class UffizziCore::Api::Cli::V1::Projects::DeploymentsControllerTest < ActionCon
deployment = compose_file.deployments.first
assert_equal(@metadata, deployment.metadata)
assert_equal(deployment.subdomain.downcase, deployment.subdomain)
assert_equal(deployment.creation_source, UffizziCore::Deployment.creation_source.compose_file_manual)
assert_equal(deployment.creation_source, UffizziCore::Deployment::COMPOSE_FILE_MANUAL.to_s)

Sidekiq::Worker.clear_all
Sidekiq::Testing.inline!
end

test '#create - from the existing compose file with creation_source' do
test '#create - from the existing compose file with custom creation source' do
Sidekiq::Worker.clear_all
Sidekiq::Testing.fake!

Expand Down Expand Up @@ -177,7 +177,7 @@ class UffizziCore::Api::Cli::V1::Projects::DeploymentsControllerTest < ActionCon
}
create(:template, :compose_file_source, compose_file: compose_file, project: @project, added_by: @admin, payload: template_payload)
stub_dockerhub_repository('library', 'redis')
creation_source = UffizziCore::Deployment.creation_source.manual
creation_source = 'custom_source'

params = { project_slug: @project.slug, compose_file: {}, dependencies: [], creation_source: creation_source }

Expand All @@ -186,7 +186,7 @@ class UffizziCore::Api::Cli::V1::Projects::DeploymentsControllerTest < ActionCon
assert_response :success
deployment = compose_file.deployments.first

assert_equal(deployment.creation_source, creation_source)
assert_equal(creation_source, deployment.creation_source)

Sidekiq::Worker.clear_all
Sidekiq::Testing.inline!
Expand Down
6 changes: 1 addition & 5 deletions core/test/factories/deployment.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
created_at { DateTime.current }
memory_limit { 1 }
continuous_preview_payload { nil }
creation_source { nil }
creation_source { UffizziCore::Deployment::COMPOSE_FILE_MANUAL }
metadata { {} }

trait :active do
Expand All @@ -17,9 +17,5 @@
trait :disabled do
state { :disabled }
end

trait :compose_file_source do
creation_source { UffizziCore::Deployment.creation_source.compose_file_manual }
end
end
end

0 comments on commit 73c3c8a

Please sign in to comment.