Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
zipofar committed Jul 11, 2023
2 parents 24365ad + 90f7158 commit 8ab1c60
Show file tree
Hide file tree
Showing 17 changed files with 106 additions and 17 deletions.
8 changes: 4 additions & 4 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.2)
uffizzi_core (2.2.3)
aasm
actionpack (~> 6.1.0)
active_model_serializers
Expand Down Expand Up @@ -110,7 +110,7 @@ GEM
ast (2.4.2)
awesome_print (1.9.2)
aws-eventstream (1.2.0)
aws-partitions (1.784.0)
aws-partitions (1.785.0)
aws-sdk-core (3.177.0)
aws-eventstream (~> 1, >= 1.0.2)
aws-partitions (~> 1, >= 1.651.0)
Expand Down Expand Up @@ -185,7 +185,7 @@ GEM
dry-core (~> 0.5, >= 0.5)
dry-initializer (~> 3.0)
dry-schema (~> 1.9, >= 1.9.1)
enumerize (2.6.1)
enumerize (2.7.0)
activesupport (>= 3.2)
erubi (1.10.0)
faraday (1.10.3)
Expand Down Expand Up @@ -264,7 +264,7 @@ GEM
ast (~> 2.4.1)
parslet (2.0.0)
pg (1.3.4)
public_suffix (5.0.1)
public_suffix (5.0.3)
puma (4.3.11)
nio4r (~> 2.0)
pundit (2.3.0)
Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,4 @@ test:
docker-compose run --rm core bash -c "bundle exec rails test"

lint:
docker-compose run --rm web bash -c "bundle exec rubocop --auto-correct"
docker-compose run --rm web bash -c "bundle exec rubocop -A"
6 changes: 3 additions & 3 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.2)
uffizzi_core (2.2.3)
aasm
actionpack (~> 6.1.0)
active_model_serializers
Expand Down Expand Up @@ -109,7 +109,7 @@ GEM
activerecord (>= 5.2.6)
awesome_print (1.9.2)
aws-eventstream (1.2.0)
aws-partitions (1.784.0)
aws-partitions (1.785.0)
aws-sdk-core (3.177.0)
aws-eventstream (~> 1, >= 1.0.2)
aws-partitions (~> 1, >= 1.651.0)
Expand Down Expand Up @@ -188,7 +188,7 @@ GEM
dry-core (~> 0.5, >= 0.5)
dry-initializer (~> 3.0)
dry-schema (~> 1.9, >= 1.9.1)
enumerize (2.6.1)
enumerize (2.7.0)
activesupport (>= 3.2)
erubi (1.12.0)
factory_bot (6.2.0)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ module UffizziCore::DependencyInjectionConcern
def include_module_if_exists(module_name)
include(Object.const_get(module_name)) if Object.const_defined?(module_name)
end

def prepend_module_if_exists(module_name)
prepend(Object.const_get(module_name)) if Object.const_defined?(module_name)
end
end

def user_access_module
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,7 @@ def deploy_containers
# @response 401 Not authorized
def destroy
UffizziCore::DeploymentService.disable!(deployment)
deployment.deployment_events.create!(deployment_state: deployment.state, message: 'Destroyed by CLI')

head :no_content
end
Expand Down
1 change: 1 addition & 0 deletions core/app/lib/uffizzi_core/concerns/models/deployment.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ module UffizziCore::Concerns::Models::Deployment
has_many :credentials, through: :project
has_many :containers, dependent: :destroy, index_errors: true
has_many :activity_items, dependent: :destroy
has_many :deployment_events, dependent: :destroy

has_one :ingress_container, -> { where(receive_incoming_requests: true) }, class_name: UffizziCore::Container.name
validates :kind, presence: true
Expand Down
11 changes: 11 additions & 0 deletions core/app/lib/uffizzi_core/concerns/models/deployment_event.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# frozen_string_literal: true

module UffizziCore::Concerns::Models::DeploymentEvent
extend ActiveSupport::Concern

included do
self.table_name = UffizziCore.table_names[:deployment_events]

belongs_to :deployment
end
end
1 change: 1 addition & 0 deletions core/app/lib/uffizzi_core/concerns/models/project.rb
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ def active_deployments
def disable_deployments
active_deployments.each do |deployment|
UffizziCore::DeploymentService.disable!(deployment)
deployment.deployment_events.create!(deployment_state: deployment.state, message: 'Disabled after project was disabled')
end
end

Expand Down
5 changes: 5 additions & 0 deletions core/app/models/uffizzi_core/deployment_event.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# frozen_string_literal: true

class UffizziCore::DeploymentEvent < UffizziCore::ApplicationRecord
include UffizziCore::Concerns::Models::DeploymentEvent
end
5 changes: 4 additions & 1 deletion core/app/services/uffizzi_core/activity_item_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,10 @@ def manage_deploy_activity_item(activity_item)
return handle_failed_status(activity_item, deployment) if failed?(status)

if deployed?(status) && UffizziCore::ContainerService.ingress_container?(container)
return deployment.update(last_deploy_at: last_event.created_at)
deployment.update!(last_deploy_at: last_event.created_at)
deployment.deployment_events.create!(deployment_state: status)

return
end

return unless [UffizziCore::Event.state.building, UffizziCore::Event.state.deploying].include?(status)
Expand Down
28 changes: 21 additions & 7 deletions core/app/services/uffizzi_core/deployment_service.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
# frozen_string_literal: true

class UffizziCore::DeploymentService
include UffizziCore::DependencyInjectionConcern
prepend_module_if_exists('UffizziCore::DeploymentServiceModule')

MIN_TARGET_PORT_RANGE = 37_000
MAX_TARGET_PORT_RANGE = 39_999

Expand Down Expand Up @@ -39,12 +42,8 @@ def update_from_compose(compose_file, project, user, deployment, metadata)
deployment.containers.destroy_all
deployment.compose_file.destroy! if deployment.compose_file&.kind&.temporary?
deployment.activate unless deployment.active?
params = {
containers: deployment_form.containers,
compose_file_id: compose_file.id,
metadata: deployment_form.metadata,
}
deployment.update!(params)
new_params = params_for_update_deployment(deployment_form, compose_file)
deployment.update!(new_params)
end

deployment
Expand All @@ -56,17 +55,23 @@ def deploy_containers(deployment, repeated = false)
update_controller_container_names(deployment)
end

case deployment_process_status(deployment)
status = deployment_process_status(deployment)

case status
when DEPLOYMENT_PROCESS_STATUSES[:building]
Rails.logger.info("DEPLOYMENT_PROCESS deployment_id=#{deployment.id} repeat deploy_containers")
UffizziCore::Deployment::DeployContainersJob.perform_in(1.minute, deployment.id, true)
unless repeated
deployment.deployment_events.create!(deployment_state: status)
end
when DEPLOYMENT_PROCESS_STATUSES[:deploying]
Rails.logger.info("DEPLOYMENT_PROCESS deployment_id=#{deployment.id} start deploying into controller")

containers = deployment.active_containers
containers_with_variables = add_default_deployment_variables!(containers, deployment)

UffizziCore::ControllerService.deploy_containers(deployment, containers_with_variables)
deployment.deployment_events.create!(deployment_state: status)
else
Rails.logger.info("DEPLOYMENT_PROCESS deployment_id=#{deployment.id} deployment has builds errors, stopping")
end
Expand All @@ -84,6 +89,7 @@ def fail!(deployment)
return if deployment.failed?

deployment.fail!
deployment.deployment_events.create!(deployment_state: deployment.state)
compose_file = deployment.compose_file || deployment.template&.compose_file
return unless compose_file&.kind&.temporary?

Expand Down Expand Up @@ -230,5 +236,13 @@ def add_default_deployment_variables!(containers, deployment)
container.variables.push(*envs)
end
end

def params_for_update_deployment(deployment_form, compose_file)
{
containers: deployment_form.containers,
compose_file_id: compose_file.id,
metadata: deployment_form.metadata,
}
end
end
end
14 changes: 14 additions & 0 deletions core/db/migrate/20230531135739_create_deployment_events.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# frozen_string_literal: true

class CreateDeploymentEvents < ActiveRecord::Migration[6.1]
def change
create_table :uffizzi_core_deployment_events do |t|
t.string :deployment_state
t.string :message
t.timestamps
t.references :deployment, null: false,
index: { name: :uf_core_dep_events_on_dep },
foreign_key: { to_table: :uffizzi_core_deployments }
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 @@ -61,6 +61,7 @@ module UffizziCore
users_roles: :uffizzi_core_users_roles,
host_volume_files: :uffizzi_core_host_volume_files,
container_host_volume_files: :uffizzi_core_container_host_volume_files,
deployment_events: :uffizzi_core_deployment_events,
}
mattr_accessor :user_creation_sources, default: [:system, :online_registration, :google, :sso]
mattr_accessor :user_project_roles, default: [:admin, :developer, :viewer]
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.2'
VERSION = '2.2.3'
end
10 changes: 10 additions & 0 deletions core/test/dummy/db/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,15 @@
t.index ["provider_ref"], name: "index_credentials_on_provider_ref"
end

create_table "uffizzi_core_deployment_events", force: :cascade do |t|
t.string "deployment_state"
t.string "message"
t.datetime "created_at", precision: 6, null: false
t.datetime "updated_at", precision: 6, null: false
t.bigint "deployment_id", null: false
t.index ["deployment_id"], name: "uf_core_dep_events_on_dep"
end

create_table "uffizzi_core_deployments", force: :cascade do |t|
t.bigint "project_id", null: false
t.text "kind", null: false
Expand Down Expand Up @@ -442,6 +451,7 @@
add_foreign_key "uffizzi_core_clusters", "uffizzi_core_projects", column: "project_id"
add_foreign_key "uffizzi_core_container_host_volume_files", "uffizzi_core_containers", column: "container_id"
add_foreign_key "uffizzi_core_container_host_volume_files", "uffizzi_core_host_volume_files", column: "host_volume_file_id"
add_foreign_key "uffizzi_core_deployment_events", "uffizzi_core_deployments", column: "deployment_id"
add_foreign_key "uffizzi_core_host_volume_files", "uffizzi_core_compose_files", column: "compose_file_id"
add_foreign_key "uffizzi_core_host_volume_files", "uffizzi_core_projects", column: "project_id"
end
14 changes: 14 additions & 0 deletions db/migrate/20230531135739_create_deployment_events.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# frozen_string_literal: true

class CreateDeploymentEvents < ActiveRecord::Migration[6.1]
def change
create_table :uffizzi_core_deployment_events do |t|
t.string :deployment_state
t.string :message
t.timestamps
t.references :deployment, null: false,
index: { name: :uf_core_dep_events_on_dep },
foreign_key: { to_table: :uffizzi_core_deployments }
end
end
end
10 changes: 10 additions & 0 deletions db/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,15 @@
t.index ["provider_ref"], name: "index_credentials_on_provider_ref"
end

create_table "uffizzi_core_deployment_events", force: :cascade do |t|
t.string "deployment_state"
t.string "message"
t.datetime "created_at", precision: 6, null: false
t.datetime "updated_at", precision: 6, null: false
t.bigint "deployment_id", null: false
t.index ["deployment_id"], name: "uf_core_dep_events_on_dep"
end

create_table "uffizzi_core_deployments", force: :cascade do |t|
t.bigint "project_id", null: false
t.text "kind", null: false
Expand Down Expand Up @@ -442,6 +451,7 @@
add_foreign_key "uffizzi_core_clusters", "uffizzi_core_projects", column: "project_id"
add_foreign_key "uffizzi_core_container_host_volume_files", "uffizzi_core_containers", column: "container_id"
add_foreign_key "uffizzi_core_container_host_volume_files", "uffizzi_core_host_volume_files", column: "host_volume_file_id"
add_foreign_key "uffizzi_core_deployment_events", "uffizzi_core_deployments", column: "deployment_id"
add_foreign_key "uffizzi_core_host_volume_files", "uffizzi_core_compose_files", column: "compose_file_id"
add_foreign_key "uffizzi_core_host_volume_files", "uffizzi_core_projects", column: "project_id"
end

0 comments on commit 8ab1c60

Please sign in to comment.