Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
zipofar committed Aug 14, 2023
2 parents 554dddf + a3b6bf7 commit a24ad13
Show file tree
Hide file tree
Showing 8 changed files with 36 additions and 19 deletions.
6 changes: 3 additions & 3 deletions Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
PATH
remote: core
specs:
uffizzi_core (2.2.10)
uffizzi_core (2.2.11)
aasm
actionpack (~> 6.1.0)
active_model_serializers
Expand Down Expand Up @@ -111,8 +111,8 @@ GEM
ast (2.4.2)
awesome_print (1.9.2)
aws-eventstream (1.2.0)
aws-partitions (1.800.0)
aws-sdk-core (3.180.2)
aws-partitions (1.803.0)
aws-sdk-core (3.180.3)
aws-eventstream (~> 1, >= 1.0.2)
aws-partitions (~> 1, >= 1.651.0)
aws-sigv4 (~> 1.5)
Expand Down
8 changes: 4 additions & 4 deletions core/Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
PATH
remote: .
specs:
uffizzi_core (2.2.10)
uffizzi_core (2.2.11)
aasm
actionpack (~> 6.1.0)
active_model_serializers
Expand Down Expand Up @@ -110,8 +110,8 @@ GEM
activerecord (>= 5.2.6)
awesome_print (1.9.2)
aws-eventstream (1.2.0)
aws-partitions (1.800.0)
aws-sdk-core (3.180.2)
aws-partitions (1.803.0)
aws-sdk-core (3.180.3)
aws-eventstream (~> 1, >= 1.0.2)
aws-partitions (~> 1, >= 1.651.0)
aws-sigv4 (~> 1.5)
Expand Down Expand Up @@ -281,7 +281,7 @@ GEM
net-smtp (0.3.3)
net-protocol
nio4r (2.5.8)
nokogiri (1.15.3-x86_64-linux)
nokogiri (1.15.4-x86_64-linux)
racc (~> 1.4)
octokit (7.0.0)
faraday (>= 1, < 3)
Expand Down
6 changes: 1 addition & 5 deletions core/app/lib/uffizzi_core/concerns/models/container.rb
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ module UffizziCore::Concerns::Models::Container
transitions from: [:disabled], to: :active
end

event :disable, after: :clean do
event :disable do
transitions from: [:active], to: :disabled
end
end
Expand All @@ -76,10 +76,6 @@ def should_check_port
public && active?
end

def clean
update(public: false, port: nil)
end

def set_defaults
update_target_port_value
end
Expand Down
21 changes: 21 additions & 0 deletions core/app/services/uffizzi_core/controller_service.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,14 @@
# frozen_string_literal: true

class UffizziCore::ControllerService
class InvalidPublicPort < StandardError
def initialize(containers)
msg = "Deployment with ID #{containers.first.deployment.id} does not have any public port"

super(msg)
end
end

class << self
include UffizziCore::DependencyInjectionConcern

Expand Down Expand Up @@ -28,6 +36,10 @@ def delete_credential(deployment, credential)
end

def deploy_containers(deployment, containers)
check_any_container_has_public_port(containers) do |exists|
UffizziCore::DeploymentService.disable!(deployment) unless exists
end

containers = containers.map do |container|
UffizziCore::Controller::DeployContainers::ContainerSerializer.new(container).as_json(include: '**')
end
Expand Down Expand Up @@ -100,6 +112,15 @@ def delete_cluster(cluster)

private

def check_any_container_has_public_port(containers)
exists = containers.any? { |c| c.port.present? && c.public }
yield(exists) if block_given?

return if exists

raise InvalidPublicPort.new(containers)
end

def request_events(deployment)
controller_client(deployment).deployment_containers_events(deployment_id: deployment.id)
end
Expand Down
2 changes: 1 addition & 1 deletion core/lib/uffizzi_core/version.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# frozen_string_literal: true

module UffizziCore
VERSION = '2.2.10'
VERSION = '2.2.11'
end
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ class UffizziCore::Api::Cli::V1::Projects::DeploymentsControllerTest < ActionCon

container = create(
:container,
:with_public_port,
:continuously_deploy_enabled,
deployment: @deployment,
repo: repo,
Expand Down Expand Up @@ -114,6 +115,7 @@ class UffizziCore::Api::Cli::V1::Projects::DeploymentsControllerTest < ActionCon

container = create(
:container,
:with_public_port,
:continuously_deploy_enabled,
deployment: @deployment,
repo: repo,
Expand Down Expand Up @@ -172,6 +174,7 @@ class UffizziCore::Api::Cli::V1::Projects::DeploymentsControllerTest < ActionCon

container = create(
:container,
:with_public_port,
:continuously_deploy_enabled,
deployment: @deployment,
repo: repo,
Expand Down Expand Up @@ -230,6 +233,7 @@ class UffizziCore::Api::Cli::V1::Projects::DeploymentsControllerTest < ActionCon
container = create(
:container,
:continuously_deploy_enabled,
:with_public_port,
:with_named_volume,
deployment: @deployment,
repo: repo,
Expand Down Expand Up @@ -391,7 +395,7 @@ class UffizziCore::Api::Cli::V1::Projects::DeploymentsControllerTest < ActionCon
host_volume_file_app_file = create(:host_volume_file, **host_volume_file_app_file_params)
app_container = create(:container, :continuously_deploy_enabled,
**{ deployment: @deployment, repo: app_repo }.merge(container_app_attrs))
nginx_container = create(:container, :continuously_deploy_enabled,
nginx_container = create(:container, :with_public_port, :continuously_deploy_enabled,
**{ deployment: @deployment, repo: nginx_repo }.merge(container_nginx_attrs))

container_host_volume_files_app_dir = create(:container_host_volume_file, container: app_container,
Expand Down
4 changes: 0 additions & 4 deletions core/test/factories/containers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,6 @@
memory_limit { Settings.compose.default_memory }
memory_request { Settings.compose.default_memory }

trait :continuously_deploy_enabled do
continuously_deploy { UffizziCore::Container::STATE_CD_ENABLED }
end

trait :with_public_port do
public { true }

Expand Down
2 changes: 1 addition & 1 deletion core/test/services/deployment_service_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class UffizziCore::DeploymentServiceTest < ActiveSupport::TestCase

test '#deploy_containers - start to deploy dockerhub container' do
repo = create(:repo, :docker_hub, project: @project)
create(:container, :active, deployment: @deployment, repo: repo)
create(:container, :with_public_port, :active, deployment: @deployment, repo: repo)

stubbed_deploy_containers_request = stub_request(:post, "#{Settings.controller.url}/deployments/#{@deployment.id}/containers")

Expand Down

0 comments on commit a24ad13

Please sign in to comment.