Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
moklidia committed Aug 9, 2023
2 parents 73f576c + b256ef8 commit 554dddf
Show file tree
Hide file tree
Showing 17 changed files with 194 additions and 26 deletions.
16 changes: 13 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.9)
uffizzi_core (2.2.10)
aasm
actionpack (~> 6.1.0)
active_model_serializers
Expand Down Expand Up @@ -31,6 +31,7 @@ PATH
rswag-api
rswag-ui
sidekiq
sidekiq-unique-jobs
swagger_yard
virtus

Expand Down Expand Up @@ -110,8 +111,8 @@ GEM
ast (2.4.2)
awesome_print (1.9.2)
aws-eventstream (1.2.0)
aws-partitions (1.798.0)
aws-sdk-core (3.180.1)
aws-partitions (1.800.0)
aws-sdk-core (3.180.2)
aws-eventstream (~> 1, >= 1.0.2)
aws-partitions (~> 1, >= 1.651.0)
aws-sigv4 (~> 1.5)
Expand All @@ -134,6 +135,9 @@ GEM
bcrypt (3.1.16)
bootsnap (1.10.3)
msgpack (~> 1.2)
brpoplpush-redis_script (0.1.3)
concurrent-ruby (~> 1.0, >= 1.0.5)
redis (>= 1.0, < 6)
builder (3.2.4)
byebug (11.1.3)
case_transform (0.2)
Expand Down Expand Up @@ -343,6 +347,12 @@ GEM
connection_pool (>= 2.2.2)
rack (~> 2.0)
redis (>= 4.2.0)
sidekiq-unique-jobs (7.1.30)
brpoplpush-redis_script (> 0.1.1, <= 2.0.0)
concurrent-ruby (~> 1.0, >= 1.0.5)
redis (< 5.0)
sidekiq (>= 5.0, < 7.0)
thor (>= 0.20, < 3.0)
sprockets (4.0.3)
concurrent-ruby (~> 1.0)
rack (> 1, < 3)
Expand Down
18 changes: 18 additions & 0 deletions config/initializers/sidekiq.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,24 @@

Sidekiq.configure_client do |config|
config.redis = { url: ENV['REDIS_URL'], size: 2 }

config.client_middleware do |chain|
chain.add(SidekiqUniqueJobs::Middleware::Client)
end
end

Sidekiq.configure_server do |config|
config.redis = { url: ENV['REDIS_URL'], size: 20 }

config.client_middleware do |chain|
chain.add(SidekiqUniqueJobs::Middleware::Client)
end

config.server_middleware do |chain|
chain.add(SidekiqUniqueJobs::Middleware::Server)
end

SidekiqUniqueJobs::Server.configure(config)
end

if Settings.sidekiq.login.present?
Expand All @@ -23,3 +37,7 @@
valid_login & valid_password
end
end

SidekiqUniqueJobs.configure do |config|
config.enabled = !Rails.env.test?
end
2 changes: 2 additions & 0 deletions config/sidekiq.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,5 @@
- [accounts, 10]
- [containers, 10]
- [github, 10]
- [disable_deployments, 5]
- [clusters, 10]
18 changes: 14 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.9)
uffizzi_core (2.2.10)
aasm
actionpack (~> 6.1.0)
active_model_serializers
Expand Down Expand Up @@ -31,6 +31,7 @@ PATH
rswag-api
rswag-ui
sidekiq
sidekiq-unique-jobs
swagger_yard
virtus

Expand Down Expand Up @@ -109,8 +110,8 @@ GEM
activerecord (>= 5.2.6)
awesome_print (1.9.2)
aws-eventstream (1.2.0)
aws-partitions (1.798.0)
aws-sdk-core (3.180.1)
aws-partitions (1.800.0)
aws-sdk-core (3.180.2)
aws-eventstream (~> 1, >= 1.0.2)
aws-partitions (~> 1, >= 1.651.0)
aws-sigv4 (~> 1.5)
Expand All @@ -131,6 +132,9 @@ GEM
ice_nine (~> 0.11.0)
thread_safe (~> 0.3, >= 0.3.1)
bcrypt (3.1.16)
brpoplpush-redis_script (0.1.3)
concurrent-ruby (~> 1.0, >= 1.0.5)
redis (>= 1.0, < 6)
builder (3.2.4)
bump (0.10.0)
byebug (11.1.3)
Expand Down Expand Up @@ -258,7 +262,7 @@ GEM
net-smtp
marcel (1.0.2)
method_source (1.0.0)
mini_mime (1.1.2)
mini_mime (1.1.5)
minitest (5.15.0)
minitest-hooks (1.5.0)
minitest (> 5.3)
Expand Down Expand Up @@ -357,6 +361,12 @@ GEM
connection_pool (>= 2.2.5, < 3)
rack (~> 2.0)
redis (>= 4.5.0, < 5)
sidekiq-unique-jobs (7.1.30)
brpoplpush-redis_script (> 0.1.1, <= 2.0.0)
concurrent-ruby (~> 1.0, >= 1.0.5)
redis (< 5.0)
sidekiq (>= 5.0, < 7.0)
thor (>= 0.20, < 3.0)
sprockets (4.1.1)
concurrent-ruby (~> 1.0)
rack (> 1, < 3)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,12 @@ def controller_settings_service
module_class(:controller_settings)
end

def ci_module
return unless module_exists?(:ci_module)

module_class(:ci_module)
end

private

def module_exists?(module_name)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,9 @@ class UffizziCore::Api::Cli::V1::Projects::ClustersController < UffizziCore::Api

def index
clusters = resource_project.clusters.enabled
return respond_with clusters if request_by_admin? || valid_request_from_ci_workflow?

respond_with clusters
respond_with clusters.deployed_by_user(current_user)
end

def create
Expand All @@ -37,7 +38,20 @@ def destroy
private

def resource_cluster
@resource_cluster ||= resource_project.clusters.enabled.find_by!(name: params[:name])
active_project_clusters = resource_project.clusters.enabled
@resource_cluster ||= if request_by_admin? || valid_request_from_ci_workflow?
active_project_clusters.find_by!(name: params[:name])
else
active_project_clusters.deployed_by_user(current_user).find_by!(name: params[:name])
end
end

def request_by_admin?
current_user.admin_access_to_project?(resource_project)
end

def valid_request_from_ci_workflow?
ci_module.valid_request_from_ci_workflow?(params)
end

def cluster_params
Expand Down
4 changes: 3 additions & 1 deletion core/app/jobs/uffizzi_core/cluster/delete_job.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
# frozen_string_literal: true

class UffizziCore::Cluster::DeleteJob < UffizziCore::ApplicationJob
sidekiq_options queue: :deployments, retry: 5
sidekiq_options queue: :clusters,
lock: :until_executed,
retry: Settings.default_job_retry_count

def perform(id)
Rails.logger.info("DEPLOYMENT_PROCESS cluster_id=#{id} DeleteJob")
Expand Down
2 changes: 1 addition & 1 deletion core/app/jobs/uffizzi_core/cluster/deploy_job.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# frozen_string_literal: true

class UffizziCore::Cluster::DeployJob < UffizziCore::ApplicationJob
sidekiq_options queue: :deployments, retry: 5
sidekiq_options queue: :clusters, retry: Settings.default_job_retry_count

def perform(id)
cluster = UffizziCore::Cluster.find(id)
Expand Down
2 changes: 1 addition & 1 deletion core/app/jobs/uffizzi_core/cluster/manage_deploying_job.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# frozen_string_literal: true

class UffizziCore::Cluster::ManageDeployingJob < UffizziCore::ApplicationJob
sidekiq_options queue: :deployments, retry: 5
sidekiq_options queue: :clusters, retry: Settings.default_job_retry_count

def perform(id, try = 1)
cluster = UffizziCore::Cluster.find(id)
Expand Down
4 changes: 3 additions & 1 deletion core/app/jobs/uffizzi_core/deployment/delete_job.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
# frozen_string_literal: true

class UffizziCore::Deployment::DeleteJob < UffizziCore::ApplicationJob
sidekiq_options queue: :deployments, retry: 5
sidekiq_options queue: :disable_deployments,
lock: :until_executed,
retry: Settings.default_job_retry_count

def perform(id)
Rails.logger.info("DEPLOYMENT_PROCESS deployment_id=#{id} DeleteJob")
Expand Down
2 changes: 1 addition & 1 deletion core/app/lib/uffizzi_core/concerns/models/user.rb
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ def full_name
end

def admin_access_to_project?(project)
projects.by_ids(project).by_accounts(memberships.by_role_admin.select(:account_id)).exists?
project.user_projects.where(user_id: id, role: UffizziCore::UserProject.role.admin).exists?
end
end
end
1 change: 1 addition & 0 deletions core/app/repositories/uffizzi_core/cluster_repo.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,6 @@ module UffizziCore::ClusterRepo
included do
scope :deployed, -> { where(state: UffizziCore::Cluster::STATE_DEPLOYED) }
scope :enabled, -> { where.not(state: UffizziCore::Cluster::STATE_DISABLED) }
scope :deployed_by_user, ->(user) { where(deployed_by: user) }
end
end
9 changes: 9 additions & 0 deletions core/app/services/uffizzi_core/ci_service.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# frozen_string_literal: true

class UffizziCore::CiService
class << self
def valid_request_from_ci_workflow?(_params)
false
end
end
end
1 change: 1 addition & 0 deletions core/lib/uffizzi_core.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ module UffizziCore
deployment_memory_module: 'UffizziCore::Deployment::MemoryService',
template_memory_module: 'UffizziCore::Template::MemoryService',
controller_settings: 'UffizziCore::ControllerSettingsService',
ci_module: 'UffizziCore::CiService',
}
mattr_accessor :table_names, default: {
accounts: :uffizzi_core_accounts,
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.9'
VERSION = '2.2.10'
end
Loading

0 comments on commit 554dddf

Please sign in to comment.