uffizzi-core 0.1.12
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/LICENSE +201 -0
- data/README.md +52 -0
- data/Rakefile +31 -0
- data/app/assets/config/uffizzi_core_manifest.js +1 -0
- data/app/assets/stylesheets/uffizzi_core/application.css +15 -0
- data/app/clients/uffizzi_core/amazon_registry_client.rb +18 -0
- data/app/clients/uffizzi_core/azure_registry_client/request_result.rb +5 -0
- data/app/clients/uffizzi_core/azure_registry_client.rb +42 -0
- data/app/clients/uffizzi_core/controller_client/request_result.rb +5 -0
- data/app/clients/uffizzi_core/controller_client.rb +106 -0
- data/app/clients/uffizzi_core/docker_hub_client/request_result.rb +7 -0
- data/app/clients/uffizzi_core/docker_hub_client.rb +141 -0
- data/app/clients/uffizzi_core/github_container_registry_client/request_result.rb +7 -0
- data/app/clients/uffizzi_core/github_container_registry_client.rb +52 -0
- data/app/clients/uffizzi_core/google_registry_client/request_result.rb +5 -0
- data/app/clients/uffizzi_core/google_registry_client.rb +42 -0
- data/app/contexts/uffizzi_core/base_context.rb +12 -0
- data/app/contexts/uffizzi_core/project_context.rb +13 -0
- data/app/contexts/uffizzi_core/webhooks_context.rb +9 -0
- data/app/controllers/concerns/uffizzi_core/auth_management.rb +23 -0
- data/app/controllers/concerns/uffizzi_core/authorization_concern.rb +38 -0
- data/app/controllers/concerns/uffizzi_core/dependency_injection_concern.rb +19 -0
- data/app/controllers/uffizzi_core/api/cli/v1/account/application_controller.rb +7 -0
- data/app/controllers/uffizzi_core/api/cli/v1/account/credentials_controller.rb +91 -0
- data/app/controllers/uffizzi_core/api/cli/v1/application_controller.rb +5 -0
- data/app/controllers/uffizzi_core/api/cli/v1/projects/application_controller.rb +11 -0
- data/app/controllers/uffizzi_core/api/cli/v1/projects/compose_files_controller.rb +93 -0
- data/app/controllers/uffizzi_core/api/cli/v1/projects/deployments/activity_items_controller.rb +36 -0
- data/app/controllers/uffizzi_core/api/cli/v1/projects/deployments/application_controller.rb +7 -0
- data/app/controllers/uffizzi_core/api/cli/v1/projects/deployments/containers/application_controller.rb +8 -0
- data/app/controllers/uffizzi_core/api/cli/v1/projects/deployments/containers/logs_controller.rb +27 -0
- data/app/controllers/uffizzi_core/api/cli/v1/projects/deployments/containers_controller.rb +24 -0
- data/app/controllers/uffizzi_core/api/cli/v1/projects/deployments/events_controller.rb +29 -0
- data/app/controllers/uffizzi_core/api/cli/v1/projects/deployments_controller.rb +179 -0
- data/app/controllers/uffizzi_core/api/cli/v1/projects/secrets_controller.rb +61 -0
- data/app/controllers/uffizzi_core/api/cli/v1/projects_controller.rb +85 -0
- data/app/controllers/uffizzi_core/api/cli/v1/sessions_controller.rb +43 -0
- data/app/controllers/uffizzi_core/application_controller.rb +57 -0
- data/app/errors/uffizzi_core/compose_file/build_error.rb +4 -0
- data/app/errors/uffizzi_core/compose_file/credential_error.rb +4 -0
- data/app/errors/uffizzi_core/compose_file/parse_error.rb +4 -0
- data/app/errors/uffizzi_core/compose_file/secrets_error.rb +4 -0
- data/app/errors/uffizzi_core/deployment/image_pull_error.rb +10 -0
- data/app/errors/uffizzi_core/deployment_not_found_error.rb +10 -0
- data/app/forms/uffizzi_core/api/cli/v1/account/credential/check_credential_form.rb +16 -0
- data/app/forms/uffizzi_core/api/cli/v1/account/credential/create_form.rb +26 -0
- data/app/forms/uffizzi_core/api/cli/v1/compose_file/check_credentials_form.rb +21 -0
- data/app/forms/uffizzi_core/api/cli/v1/compose_file/cli_form.rb +22 -0
- data/app/forms/uffizzi_core/api/cli/v1/compose_file/create_form.rb +13 -0
- data/app/forms/uffizzi_core/api/cli/v1/compose_file/template_form.rb +44 -0
- data/app/forms/uffizzi_core/api/cli/v1/compose_file/update_form.rb +9 -0
- data/app/forms/uffizzi_core/api/cli/v1/config_file/create_form.rb +11 -0
- data/app/forms/uffizzi_core/api/cli/v1/deployment/create_form.rb +92 -0
- data/app/forms/uffizzi_core/api/cli/v1/deployment/update_form.rb +90 -0
- data/app/forms/uffizzi_core/api/cli/v1/project/create_form.rb +7 -0
- data/app/forms/uffizzi_core/api/cli/v1/project/update_form.rb +10 -0
- data/app/forms/uffizzi_core/api/cli/v1/secret/bulk_assign_form.rb +39 -0
- data/app/forms/uffizzi_core/api/cli/v1/session_create_form.rb +29 -0
- data/app/forms/uffizzi_core/api/cli/v1/template/create_form.rb +65 -0
- data/app/forms/uffizzi_core/application_form.rb +11 -0
- data/app/forms/uffizzi_core/application_form_without_active_record.rb +17 -0
- data/app/forms/uffizzi_core/mass_assignment_control_concern.rb +22 -0
- data/app/helpers/uffizzi_core/application_helper.rb +6 -0
- data/app/jobs/uffizzi_core/account/create_credential_job.rb +10 -0
- data/app/jobs/uffizzi_core/activity_item/docker/update_digest_job.rb +11 -0
- data/app/jobs/uffizzi_core/application_job.rb +7 -0
- data/app/jobs/uffizzi_core/config_file/apply_job.rb +31 -0
- data/app/jobs/uffizzi_core/credential/docker_hub/create_webhook_job.rb +15 -0
- data/app/jobs/uffizzi_core/deployment/create_credential_job.rb +32 -0
- data/app/jobs/uffizzi_core/deployment/create_credentials_job.rb +17 -0
- data/app/jobs/uffizzi_core/deployment/create_job.rb +15 -0
- data/app/jobs/uffizzi_core/deployment/create_webhooks_job.rb +13 -0
- data/app/jobs/uffizzi_core/deployment/delete_credential_job.rb +13 -0
- data/app/jobs/uffizzi_core/deployment/delete_job.rb +11 -0
- data/app/jobs/uffizzi_core/deployment/deploy_containers_job.rb +27 -0
- data/app/jobs/uffizzi_core/deployment/manage_deploy_activity_item_job.rb +38 -0
- data/app/lib/uffizzi_core/concerns/models/activity_item.rb +39 -0
- data/app/lib/uffizzi_core/concerns/models/credential.rb +65 -0
- data/app/lib/uffizzi_core/concerns/models/repo.rb +33 -0
- data/app/lib/uffizzi_core/rbac/user_access_service.rb +45 -0
- data/app/mailers/uffizzi_core/application_mailer.rb +8 -0
- data/app/models/concerns/uffizzi_core/hashid_concern.rb +25 -0
- data/app/models/concerns/uffizzi_core/state_machine_concern.rb +16 -0
- data/app/models/uffizzi_core/account.rb +83 -0
- data/app/models/uffizzi_core/activity_item/docker.rb +4 -0
- data/app/models/uffizzi_core/activity_item/github.rb +4 -0
- data/app/models/uffizzi_core/activity_item/memory_limit.rb +4 -0
- data/app/models/uffizzi_core/activity_item.rb +53 -0
- data/app/models/uffizzi_core/application_record.rb +7 -0
- data/app/models/uffizzi_core/build.rb +39 -0
- data/app/models/uffizzi_core/comment.rb +16 -0
- data/app/models/uffizzi_core/compose_file.rb +57 -0
- data/app/models/uffizzi_core/config_file.rb +24 -0
- data/app/models/uffizzi_core/container.rb +100 -0
- data/app/models/uffizzi_core/container_config_file.rb +8 -0
- data/app/models/uffizzi_core/continuous_preview.rb +4 -0
- data/app/models/uffizzi_core/coupon.rb +5 -0
- data/app/models/uffizzi_core/credential/amazon.rb +4 -0
- data/app/models/uffizzi_core/credential/azure.rb +4 -0
- data/app/models/uffizzi_core/credential/docker_hub.rb +4 -0
- data/app/models/uffizzi_core/credential/github.rb +4 -0
- data/app/models/uffizzi_core/credential/github_container_registry.rb +4 -0
- data/app/models/uffizzi_core/credential/google.rb +4 -0
- data/app/models/uffizzi_core/credential.rb +61 -0
- data/app/models/uffizzi_core/database.rb +4 -0
- data/app/models/uffizzi_core/database_offering.rb +4 -0
- data/app/models/uffizzi_core/deployment.rb +86 -0
- data/app/models/uffizzi_core/event.rb +13 -0
- data/app/models/uffizzi_core/invitation.rb +27 -0
- data/app/models/uffizzi_core/membership.rb +16 -0
- data/app/models/uffizzi_core/payment.rb +11 -0
- data/app/models/uffizzi_core/price.rb +9 -0
- data/app/models/uffizzi_core/product.rb +11 -0
- data/app/models/uffizzi_core/project.rb +67 -0
- data/app/models/uffizzi_core/rating.rb +20 -0
- data/app/models/uffizzi_core/repo/amazon.rb +4 -0
- data/app/models/uffizzi_core/repo/azure.rb +4 -0
- data/app/models/uffizzi_core/repo/docker_hub.rb +4 -0
- data/app/models/uffizzi_core/repo/github.rb +4 -0
- data/app/models/uffizzi_core/repo/github_container_registry.rb +4 -0
- data/app/models/uffizzi_core/repo/google.rb +4 -0
- data/app/models/uffizzi_core/repo.rb +29 -0
- data/app/models/uffizzi_core/role.rb +17 -0
- data/app/models/uffizzi_core/secret.rb +9 -0
- data/app/models/uffizzi_core/template.rb +19 -0
- data/app/models/uffizzi_core/user.rb +62 -0
- data/app/models/uffizzi_core/user_project.rb +14 -0
- data/app/policies/uffizzi_core/api/cli/v1/account/credentials_policy.rb +19 -0
- data/app/policies/uffizzi_core/api/cli/v1/projects/compose_files_policy.rb +15 -0
- data/app/policies/uffizzi_core/api/cli/v1/projects/deployments/activity_items_policy.rb +7 -0
- data/app/policies/uffizzi_core/api/cli/v1/projects/deployments/containers_policy.rb +7 -0
- data/app/policies/uffizzi_core/api/cli/v1/projects/deployments/events_policy.rb +7 -0
- data/app/policies/uffizzi_core/api/cli/v1/projects/deployments_policy.rb +27 -0
- data/app/policies/uffizzi_core/api/cli/v1/projects/secrets_policy.rb +15 -0
- data/app/policies/uffizzi_core/api/cli/v1/projects_policy.rb +19 -0
- data/app/policies/uffizzi_core/application_policy.rb +12 -0
- data/app/repositories/uffizzi_core/activity_item_repo.rb +9 -0
- data/app/repositories/uffizzi_core/basic_order_repo.rb +11 -0
- data/app/repositories/uffizzi_core/build_repo.rb +23 -0
- data/app/repositories/uffizzi_core/comment_repo.rb +11 -0
- data/app/repositories/uffizzi_core/compose_file_repo.rb +11 -0
- data/app/repositories/uffizzi_core/config_file_repo.rb +40 -0
- data/app/repositories/uffizzi_core/container_repo.rb +25 -0
- data/app/repositories/uffizzi_core/credential_repo.rb +31 -0
- data/app/repositories/uffizzi_core/deployment_repo.rb +24 -0
- data/app/repositories/uffizzi_core/event_repo.rb +9 -0
- data/app/repositories/uffizzi_core/membership_repo.rb +10 -0
- data/app/repositories/uffizzi_core/price_repo.rb +11 -0
- data/app/repositories/uffizzi_core/product_repo.rb +11 -0
- data/app/repositories/uffizzi_core/project_repo.rb +10 -0
- data/app/repositories/uffizzi_core/repo_repo.rb +10 -0
- data/app/repositories/uffizzi_core/template_repo.rb +87 -0
- data/app/repositories/uffizzi_core/usage_repo.rb +9 -0
- data/app/repositories/uffizzi_core/user_repo.rb +11 -0
- data/app/responders/uffizzi_core/json_responder.rb +13 -0
- data/app/serializers/uffizzi_core/api/cli/v1/account/credential_serializer.rb +9 -0
- data/app/serializers/uffizzi_core/api/cli/v1/project_serializer/compose_file_serializer.rb +7 -0
- data/app/serializers/uffizzi_core/api/cli/v1/project_serializer/deployment_serializer.rb +13 -0
- data/app/serializers/uffizzi_core/api/cli/v1/project_serializer.rb +30 -0
- data/app/serializers/uffizzi_core/api/cli/v1/projects/compose_file_serializer.rb +7 -0
- data/app/serializers/uffizzi_core/api/cli/v1/projects/deployment_serializer/container_serializer.rb +32 -0
- data/app/serializers/uffizzi_core/api/cli/v1/projects/deployment_serializer/user_serializer.rb +11 -0
- data/app/serializers/uffizzi_core/api/cli/v1/projects/deployment_serializer.rb +74 -0
- data/app/serializers/uffizzi_core/api/cli/v1/projects/deployments/activity_item_serializer.rb +24 -0
- data/app/serializers/uffizzi_core/api/cli/v1/projects/deployments/container_serializer/container_config_file_serializer/config_file_serializer.rb +6 -0
- data/app/serializers/uffizzi_core/api/cli/v1/projects/deployments/container_serializer/container_config_file_serializer.rb +7 -0
- data/app/serializers/uffizzi_core/api/cli/v1/projects/deployments/container_serializer.rb +30 -0
- data/app/serializers/uffizzi_core/api/cli/v1/projects/secret_serializer.rb +5 -0
- data/app/serializers/uffizzi_core/api/cli/v1/short_project_serializer.rb +7 -0
- data/app/serializers/uffizzi_core/api/cli/v1/user_serializer/account_serializer.rb +5 -0
- data/app/serializers/uffizzi_core/api/cli/v1/user_serializer.rb +7 -0
- data/app/serializers/uffizzi_core/base_serializer.rb +7 -0
- data/app/serializers/uffizzi_core/controller/apply_config_file/config_file_serializer.rb +5 -0
- data/app/serializers/uffizzi_core/controller/create_credential/credential_serializer.rb +19 -0
- data/app/serializers/uffizzi_core/controller/create_deployment/deployment_serializer.rb +5 -0
- data/app/serializers/uffizzi_core/controller/deploy_containers/container_serializer/container_config_file_serializer/config_file_serializer.rb +8 -0
- data/app/serializers/uffizzi_core/controller/deploy_containers/container_serializer/container_config_file_serializer.rb +7 -0
- data/app/serializers/uffizzi_core/controller/deploy_containers/container_serializer.rb +70 -0
- data/app/serializers/uffizzi_core/controller/deploy_containers/credential_serializer.rb +5 -0
- data/app/services/uffizzi_core/account_service.rb +21 -0
- data/app/services/uffizzi_core/activity_item_service.rb +88 -0
- data/app/services/uffizzi_core/amazon/credential_service.rb +31 -0
- data/app/services/uffizzi_core/amazon_service.rb +45 -0
- data/app/services/uffizzi_core/azure/credential_service.rb +18 -0
- data/app/services/uffizzi_core/compose_file/builders/config_files_builder_service.rb +31 -0
- data/app/services/uffizzi_core/compose_file/builders/container_builder_service.rb +222 -0
- data/app/services/uffizzi_core/compose_file/builders/docker_repo_builder_service.rb +25 -0
- data/app/services/uffizzi_core/compose_file/builders/template_builder_service.rb +45 -0
- data/app/services/uffizzi_core/compose_file/builders/variables_builder_service.rb +58 -0
- data/app/services/uffizzi_core/compose_file/config_files_service.rb +52 -0
- data/app/services/uffizzi_core/compose_file/config_option_service.rb +41 -0
- data/app/services/uffizzi_core/compose_file/configs_options_service.rb +26 -0
- data/app/services/uffizzi_core/compose_file/container_service.rb +68 -0
- data/app/services/uffizzi_core/compose_file/continuous_preview_options_service.rb +57 -0
- data/app/services/uffizzi_core/compose_file/dependencies_service.rb +56 -0
- data/app/services/uffizzi_core/compose_file/errors_service.rb +46 -0
- data/app/services/uffizzi_core/compose_file/github_dependencies_service.rb +38 -0
- data/app/services/uffizzi_core/compose_file/ingress_options_service.rb +51 -0
- data/app/services/uffizzi_core/compose_file/parsers/services/healthcheck_parser_service.rb +73 -0
- data/app/services/uffizzi_core/compose_file/secrets_options_service.rb +28 -0
- data/app/services/uffizzi_core/compose_file/services_options/command_service.rb +18 -0
- data/app/services/uffizzi_core/compose_file/services_options/configs_service.rb +51 -0
- data/app/services/uffizzi_core/compose_file/services_options/deploy_service.rb +44 -0
- data/app/services/uffizzi_core/compose_file/services_options/entrypoint_service.rb +18 -0
- data/app/services/uffizzi_core/compose_file/services_options/env_file_service.rb +34 -0
- data/app/services/uffizzi_core/compose_file/services_options/environment_service.rb +20 -0
- data/app/services/uffizzi_core/compose_file/services_options/image_service.rb +89 -0
- data/app/services/uffizzi_core/compose_file/services_options/secrets_service.rb +35 -0
- data/app/services/uffizzi_core/compose_file/services_options_service.rb +57 -0
- data/app/services/uffizzi_core/compose_file/template_service.rb +55 -0
- data/app/services/uffizzi_core/compose_file/variables_service.rb +25 -0
- data/app/services/uffizzi_core/compose_file_service.rb +181 -0
- data/app/services/uffizzi_core/container_service.rb +42 -0
- data/app/services/uffizzi_core/controller_service.rb +86 -0
- data/app/services/uffizzi_core/credential_service.rb +44 -0
- data/app/services/uffizzi_core/deployment_service.rb +307 -0
- data/app/services/uffizzi_core/docker_hub/credential_service.rb +15 -0
- data/app/services/uffizzi_core/docker_hub_service.rb +77 -0
- data/app/services/uffizzi_core/github_container_registry/credential_service.rb +24 -0
- data/app/services/uffizzi_core/google/credential_service.rb +18 -0
- data/app/services/uffizzi_core/logs_service.rb +33 -0
- data/app/services/uffizzi_core/manage_activity_items_service.rb +159 -0
- data/app/services/uffizzi_core/project_service.rb +48 -0
- data/app/services/uffizzi_core/repo_service.rb +43 -0
- data/app/services/uffizzi_core/response_service.rb +13 -0
- data/app/services/uffizzi_core/starter_template_service.rb +200 -0
- data/app/services/uffizzi_core/template_service.rb +21 -0
- data/app/services/uffizzi_core/token_service.rb +19 -0
- data/app/services/uffizzi_core/user_access_service.rb +14 -0
- data/app/services/uffizzi_core/user_generator_service.rb +84 -0
- data/app/utils/uffizzi_core/converters.rb +33 -0
- data/app/validators/uffizzi_core/email_validator.rb +9 -0
- data/app/validators/uffizzi_core/environment_variable_list_validator.rb +15 -0
- data/app/validators/uffizzi_core/image_command_args_validator.rb +21 -0
- data/config/initializers/rswag_api.rb +15 -0
- data/config/initializers/rswag_ui.rb +15 -0
- data/config/initializers/swagger_yard.rb +17 -0
- data/config/locales/en.activerecord.yml +23 -0
- data/config/locales/en.yml +66 -0
- data/config/routes.rb +69 -0
- data/db/migrate/20220218121438_create_uffizzi_core_tables.rb +375 -0
- data/db/migrate/20220309110201_remove_secrets_from_projects.rb +7 -0
- data/db/migrate/20220310110150_create_project_secrets.rb +14 -0
- data/db/migrate/20220325113342_add_name_to_uffizzi_containers.rb +7 -0
- data/db/migrate/20220329123323_rename_project_secrets_to_secrets.rb +7 -0
- data/db/migrate/20220329124542_add_resource_to_secrets.rb +7 -0
- data/db/migrate/20220329143241_remove_project_ref_from_secrets.rb +7 -0
- data/db/migrate/20220419074956_add_health_check_to_containers.rb +7 -0
- data/db/migrate/20220525113412_rename_name_to_uffizzi_containers.rb +7 -0
- data/db/seeds.rb +16 -0
- data/lib/tasks/uffizzi_core_tasks.rake +19 -0
- data/lib/uffizzi_core/engine.rb +15 -0
- data/lib/uffizzi_core/version.rb +5 -0
- data/lib/uffizzi_core.rb +61 -0
- data/swagger/v1/swagger.json +1659 -0
- metadata +966 -0
@@ -0,0 +1,19 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
class UffizziCore::Controller::CreateCredential::CredentialSerializer < UffizziCore::BaseSerializer
|
4
|
+
attributes :id, :registry_url, :username, :password
|
5
|
+
|
6
|
+
def username
|
7
|
+
return 'AWS' if object.amazon?
|
8
|
+
|
9
|
+
object.username
|
10
|
+
end
|
11
|
+
|
12
|
+
def password
|
13
|
+
if object.amazon?
|
14
|
+
UffizziCore::Amazon::CredentialService.access_token(object)
|
15
|
+
else
|
16
|
+
object.password
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,8 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# rubocop:disable Metrics/LineLength
|
4
|
+
class UffizziCore::Controller::DeployContainers::ContainerSerializer::ContainerConfigFileSerializer::ConfigFileSerializer < UffizziCore::BaseSerializer
|
5
|
+
# rubocop:enable Metrics/LineLength
|
6
|
+
|
7
|
+
attributes :id, :filename, :kind, :payload
|
8
|
+
end
|
@@ -0,0 +1,70 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
class UffizziCore::Controller::DeployContainers::ContainerSerializer < UffizziCore::BaseSerializer
|
4
|
+
attributes :id,
|
5
|
+
:kind,
|
6
|
+
:image,
|
7
|
+
:tag,
|
8
|
+
:variables,
|
9
|
+
:secret_variables,
|
10
|
+
:memory_limit,
|
11
|
+
:memory_request,
|
12
|
+
:entrypoint,
|
13
|
+
:command,
|
14
|
+
:port,
|
15
|
+
:target_port,
|
16
|
+
:public,
|
17
|
+
:controller_name,
|
18
|
+
:receive_incoming_requests,
|
19
|
+
:healthcheck
|
20
|
+
|
21
|
+
has_many :container_config_files
|
22
|
+
|
23
|
+
def image
|
24
|
+
repo = object.repo
|
25
|
+
credential = UffizziCore::RepoService.credential(repo)
|
26
|
+
|
27
|
+
case repo.type
|
28
|
+
when UffizziCore::Repo::Google.name, UffizziCore::Repo::Amazon.name, UffizziCore::Repo::Azure.name
|
29
|
+
registry_host = URI.parse(credential.registry_url).host
|
30
|
+
|
31
|
+
"#{registry_host}/#{object.image}"
|
32
|
+
when UffizziCore::Repo::GithubContainerRegistry.name
|
33
|
+
registry_host = URI.parse(credential.registry_url).host
|
34
|
+
"#{registry_host}/#{repo.namespace}/#{object.image}"
|
35
|
+
else
|
36
|
+
object.image
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
def tag
|
41
|
+
case object.repo.type
|
42
|
+
when UffizziCore::Repo::Github.name
|
43
|
+
UffizziCore::RepoService.tag(object.repo)
|
44
|
+
else
|
45
|
+
object.tag
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
def entrypoint
|
50
|
+
object.entrypoint.blank? ? nil : JSON.parse(object.entrypoint)
|
51
|
+
end
|
52
|
+
|
53
|
+
def command
|
54
|
+
object.command.blank? ? nil : JSON.parse(object.command)
|
55
|
+
end
|
56
|
+
|
57
|
+
def healthcheck
|
58
|
+
return {} if object.healthcheck.nil?
|
59
|
+
|
60
|
+
command = object.healthcheck['test']
|
61
|
+
new_command = if command.is_a?(Array)
|
62
|
+
items_to_remove = ['CMD', 'CMD-SHELL']
|
63
|
+
command.select { |item| items_to_remove.exclude?(item) }
|
64
|
+
elsif object.healthcheck['test'].is_a?(String)
|
65
|
+
command.split
|
66
|
+
end
|
67
|
+
|
68
|
+
object.healthcheck.merge(test: new_command)
|
69
|
+
end
|
70
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
class UffizziCore::AccountService
|
4
|
+
class << self
|
5
|
+
def create_credential(credential)
|
6
|
+
credential.account.projects.active.each do |project|
|
7
|
+
project.deployments.active.each do |deployment|
|
8
|
+
UffizziCore::Deployment::CreateCredentialJob.perform_async(deployment.id, credential.id)
|
9
|
+
end
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
def delete_credential(credential)
|
14
|
+
credential.account.projects.active.each do |project|
|
15
|
+
project.deployments.active.each do |deployment|
|
16
|
+
UffizziCore::Deployment::DeleteCredentialJob.perform_async(deployment.id, credential.id)
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,88 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
class UffizziCore::ActivityItemService
|
4
|
+
COMPLETED_STATES = ['deployed', 'failed', 'cancelled'].freeze
|
5
|
+
|
6
|
+
class << self
|
7
|
+
def create_docker_item!(repo, container)
|
8
|
+
activity_item_attributes = {
|
9
|
+
namespace: repo.namespace,
|
10
|
+
name: repo.name,
|
11
|
+
container: container,
|
12
|
+
deployment_id: container.deployment_id,
|
13
|
+
type: UffizziCore::ActivityItem::Docker.name,
|
14
|
+
tag: container.tag,
|
15
|
+
}
|
16
|
+
|
17
|
+
create_item!(activity_item_attributes)
|
18
|
+
end
|
19
|
+
|
20
|
+
def disable_deployment!(activity_item)
|
21
|
+
deployment = activity_item.container.deployment
|
22
|
+
|
23
|
+
activity_item.events.create(state: UffizziCore::Event.state.failed)
|
24
|
+
|
25
|
+
UffizziCore::DeploymentService.disable!(deployment)
|
26
|
+
end
|
27
|
+
|
28
|
+
def fail_deployment!(activity_item)
|
29
|
+
deployment = activity_item.container.deployment
|
30
|
+
|
31
|
+
activity_item.events.create(state: UffizziCore::Event.state.failed)
|
32
|
+
|
33
|
+
UffizziCore::DeploymentService.fail!(deployment)
|
34
|
+
end
|
35
|
+
|
36
|
+
def update_docker_digest!(activity_item)
|
37
|
+
container = activity_item.container
|
38
|
+
repo = container.repo
|
39
|
+
credential = UffizziCore::RepoService.credential(repo)
|
40
|
+
|
41
|
+
digest = case repo.type
|
42
|
+
when UffizziCore::Repo::DockerHub.name
|
43
|
+
UffizziCore::DockerHubService.digest(credential, activity_item.image, activity_item.tag)
|
44
|
+
when UffizziCore::Repo::Azure.name
|
45
|
+
UffizziCore::AzureService.digest(credential, activity_item.image, activity_item.tag)
|
46
|
+
when UffizziCore::Repo::Google.name
|
47
|
+
UffizziCore::GoogleService.digest(credential, activity_item.image, activity_item.tag)
|
48
|
+
when UffizziCore::Repo::Amazon.name
|
49
|
+
UffizziCore::AmazonService.digest(credential, activity_item.image, activity_item.tag)
|
50
|
+
end
|
51
|
+
|
52
|
+
activity_item.update!(digest: digest)
|
53
|
+
|
54
|
+
activity_item
|
55
|
+
end
|
56
|
+
|
57
|
+
def manage_deploy_activity_item(activity_item)
|
58
|
+
container = activity_item.container
|
59
|
+
deployment = container.deployment
|
60
|
+
service = UffizziCore::ManageActivityItemsService.new(deployment)
|
61
|
+
container_status_item = service.container_status_item(container)
|
62
|
+
status = container_status_item[:status]
|
63
|
+
last_event = activity_item.events.order_by_id.last
|
64
|
+
|
65
|
+
activity_item.events.create(state: status) if last_event&.state != status
|
66
|
+
|
67
|
+
return unless [UffizziCore::Event.state.building, UffizziCore::Event.state.deploying].include?(status)
|
68
|
+
|
69
|
+
UffizziCore::Deployment::ManageDeployActivityItemJob.perform_in(5.seconds, activity_item.id)
|
70
|
+
end
|
71
|
+
|
72
|
+
private
|
73
|
+
|
74
|
+
def create_item!(activity_item_attributes)
|
75
|
+
activity_item = UffizziCore::ActivityItem.find_by(activity_item_attributes)
|
76
|
+
return activity_item unless completed?(activity_item)
|
77
|
+
|
78
|
+
UffizziCore::ActivityItem.create!(activity_item_attributes)
|
79
|
+
end
|
80
|
+
|
81
|
+
def completed?(activity_item)
|
82
|
+
return true if activity_item.nil?
|
83
|
+
|
84
|
+
last_event = activity_item.events.last
|
85
|
+
COMPLETED_STATES.include?(last_event.state)
|
86
|
+
end
|
87
|
+
end
|
88
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
class UffizziCore::Amazon::CredentialService
|
4
|
+
class << self
|
5
|
+
def credential_correct?(credential)
|
6
|
+
access_token(credential).present?
|
7
|
+
end
|
8
|
+
|
9
|
+
def access_token(credential)
|
10
|
+
response = client(credential).authorization_token
|
11
|
+
base64_data = response.authorization_data[0].authorization_token
|
12
|
+
token_string = Base64.decode64(base64_data)
|
13
|
+
token_items = token_string.split(':')
|
14
|
+
token_items.pop
|
15
|
+
rescue Aws::ECR::Errors::UnrecognizedClientException, Aws::ECR::Errors::InvalidSignatureException
|
16
|
+
''
|
17
|
+
end
|
18
|
+
|
19
|
+
private
|
20
|
+
|
21
|
+
def client(credential)
|
22
|
+
region = UffizziCore::AmazonService.get_region_from_registry_url(credential.registry_url)
|
23
|
+
|
24
|
+
UffizziCore::AmazonRegistryClient.new(
|
25
|
+
region: region,
|
26
|
+
access_key_id: credential.username,
|
27
|
+
secret_access_key: credential.password,
|
28
|
+
)
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
@@ -0,0 +1,45 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
class UffizziCore::AmazonService
|
4
|
+
class << self
|
5
|
+
def digest(credential, image, tag)
|
6
|
+
response = client(credential).batch_get_image(image: image, tag: tag)
|
7
|
+
response.images[0].image_id.image_digest
|
8
|
+
rescue StandardError
|
9
|
+
nil
|
10
|
+
end
|
11
|
+
|
12
|
+
def get_region_from_registry_url(url)
|
13
|
+
parsed_url = URI.parse(url)
|
14
|
+
host = parsed_url.host
|
15
|
+
parsed_host = host.split('.')
|
16
|
+
parsed_host[3]
|
17
|
+
end
|
18
|
+
|
19
|
+
def process_webhook(event, event_data)
|
20
|
+
case event
|
21
|
+
when 'PUSH'
|
22
|
+
source = UffizziCore::Repo::Amazon.name
|
23
|
+
image = event_data['repository-name']
|
24
|
+
tag = event_data['image-tag']
|
25
|
+
|
26
|
+
UffizziCore::ContinuouslyDeployService.run_docker_registry_process(source, image, tag)
|
27
|
+
UffizziCore::ContinuousPreviewService.run_docker_registry_process(source, image, tag)
|
28
|
+
else
|
29
|
+
Rails.logger.warn("Amazon #{event} event doesn't support")
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
private
|
34
|
+
|
35
|
+
def client(credential)
|
36
|
+
region = get_region_from_registry_url(credential.registry_url)
|
37
|
+
|
38
|
+
UffizziCore::AmazonRegistryClient.new(
|
39
|
+
region: region,
|
40
|
+
access_key_id: credential.username,
|
41
|
+
secret_access_key: credential.password,
|
42
|
+
)
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
class UffizziCore::Azure::CredentialService
|
4
|
+
class << self
|
5
|
+
def credential_correct?(credential)
|
6
|
+
client(credential).authentificated?
|
7
|
+
rescue URI::InvalidURIError, Faraday::ConnectionFailed
|
8
|
+
false
|
9
|
+
end
|
10
|
+
|
11
|
+
private
|
12
|
+
|
13
|
+
def client(credential)
|
14
|
+
UffizziCore::AzureRegistryClient.new(registry_url: credential.registry_url, username: credential.username,
|
15
|
+
password: credential.password)
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
class UffizziCore::ComposeFile::Builders::ConfigFilesBuilderService
|
4
|
+
attr_accessor :project
|
5
|
+
|
6
|
+
def initialize(project)
|
7
|
+
@project = project
|
8
|
+
end
|
9
|
+
|
10
|
+
def build_attributes(config_files_data, dependencies)
|
11
|
+
return [] if config_files_data.empty?
|
12
|
+
|
13
|
+
config_file_sources = dependencies.pluck(:source)
|
14
|
+
config_files = project.config_files.with_creation_source(UffizziCore::ConfigFile.creation_source.compose_file)
|
15
|
+
.by_source(config_file_sources)
|
16
|
+
|
17
|
+
config_files_data.map do |config_file_data|
|
18
|
+
detected_dependency = dependencies.detect { |dependency| dependency[:path] == config_file_data[:source] }
|
19
|
+
detected_config_file = config_files.detect { |config_file| config_file.source == detected_dependency[:source] }
|
20
|
+
|
21
|
+
if detected_config_file.nil?
|
22
|
+
raise UffizziCore::ComposeFile::BuildError, I18n.t('compose.config_file_not_found', name: config_file_data[:source])
|
23
|
+
end
|
24
|
+
|
25
|
+
{
|
26
|
+
mount_path: config_file_data[:target],
|
27
|
+
config_file_id: detected_config_file.id,
|
28
|
+
}
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
@@ -0,0 +1,222 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
class UffizziCore::ComposeFile::Builders::ContainerBuilderService
|
4
|
+
attr_accessor :credentials, :project, :repositories
|
5
|
+
|
6
|
+
def initialize(credentials, project, repositories = [])
|
7
|
+
@credentials = credentials
|
8
|
+
@project = project
|
9
|
+
@repositories = repositories
|
10
|
+
end
|
11
|
+
|
12
|
+
def build_attributes(container_data, ingress_data, continuous_preview_global_data, compose_dependencies)
|
13
|
+
image_data = container_data[:image] || {}
|
14
|
+
build_data = container_data[:build] || {}
|
15
|
+
environment = container_data[:environment] || []
|
16
|
+
deploy_data = container_data[:deploy] || {}
|
17
|
+
configs_data = container_data[:configs] || []
|
18
|
+
secrets = container_data[:secrets] || []
|
19
|
+
container_name = container_data[:container_name]
|
20
|
+
healthcheck_data = container_data[:healthcheck] || {}
|
21
|
+
|
22
|
+
env_file_dependencies = UffizziCore::ComposeFile::GithubDependenciesService.env_file_dependencies_for_container(compose_dependencies,
|
23
|
+
container_name)
|
24
|
+
configs_dependencies = UffizziCore::ComposeFile::GithubDependenciesService.configs_dependencies_for_container(compose_dependencies,
|
25
|
+
container_name)
|
26
|
+
is_ingress = ingress_container?(container_name, ingress_data)
|
27
|
+
repo_attributes = repo_attributes(container_data, continuous_preview_global_data)
|
28
|
+
|
29
|
+
{
|
30
|
+
tag: tag(image_data, repo_attributes),
|
31
|
+
port: port(container_name, ingress_data),
|
32
|
+
image: image(container_data, image_data, build_data),
|
33
|
+
public: is_ingress,
|
34
|
+
entrypoint: entrypoint(container_data),
|
35
|
+
command: command(container_data),
|
36
|
+
variables: variables(environment, env_file_dependencies),
|
37
|
+
secret_variables: secret_variables(secrets),
|
38
|
+
memory_limit: memory(deploy_data),
|
39
|
+
memory_request: memory(deploy_data),
|
40
|
+
repo_attributes: repo_attributes,
|
41
|
+
continuously_deploy: continuously_deploy(deploy_data),
|
42
|
+
receive_incoming_requests: is_ingress,
|
43
|
+
container_config_files_attributes: config_files(configs_data, configs_dependencies),
|
44
|
+
service_name: container_name,
|
45
|
+
}
|
46
|
+
end
|
47
|
+
|
48
|
+
private
|
49
|
+
|
50
|
+
def repo_attributes(container_data, continuous_preview_global_data)
|
51
|
+
repo_attributes = build_repo_attributes(container_data)
|
52
|
+
continuous_preview_container_data = container_data[:'x-uffizzi-continuous-preview'] || container_data[:'x-uffizzi-continuous-previews']
|
53
|
+
|
54
|
+
set_continuous_preview_attributes_to_repo(repo_attributes, continuous_preview_global_data.to_h, continuous_preview_container_data.to_h)
|
55
|
+
end
|
56
|
+
|
57
|
+
def set_continuous_preview_attributes_to_repo(repo_attributes, global_data, container_data)
|
58
|
+
condition_attributes = [
|
59
|
+
:deploy_preview_when_pull_request_is_opened,
|
60
|
+
:delete_preview_when_pull_request_is_closed,
|
61
|
+
:deploy_preview_when_image_tag_is_created,
|
62
|
+
:delete_preview_when_image_tag_is_updated,
|
63
|
+
:share_to_github,
|
64
|
+
]
|
65
|
+
|
66
|
+
condition_attributes.each do |attribute|
|
67
|
+
repo_attributes[attribute] = select_continuous_preview_attribute(global_data[attribute], container_data[attribute], false)
|
68
|
+
end
|
69
|
+
repo_attributes[:delete_preview_after] =
|
70
|
+
select_continuous_preview_attribute(global_data.dig(:delete_preview_after, :value),
|
71
|
+
container_data.dig(:delete_preview_after, :value), nil)
|
72
|
+
|
73
|
+
repo_attributes
|
74
|
+
end
|
75
|
+
|
76
|
+
def select_continuous_preview_attribute(global_attribute, local_attribute, default_attribute)
|
77
|
+
return local_attribute if !local_attribute.nil?
|
78
|
+
return global_attribute if !global_attribute.nil?
|
79
|
+
|
80
|
+
default_attribute
|
81
|
+
end
|
82
|
+
|
83
|
+
def tag(image_data, repo_attributes)
|
84
|
+
image_data[:tag] || repo_attributes[:branch]
|
85
|
+
end
|
86
|
+
|
87
|
+
def port(container_name, ingress)
|
88
|
+
return nil unless ingress_container?(container_name, ingress)
|
89
|
+
|
90
|
+
ingress[:port]
|
91
|
+
end
|
92
|
+
|
93
|
+
def image(container_data, image_data, build_data)
|
94
|
+
if image_data.present?
|
95
|
+
image_name(container_data, image_data)
|
96
|
+
else
|
97
|
+
"#{build_data[:account_name]}/#{build_data[:repository_name]}"
|
98
|
+
end
|
99
|
+
end
|
100
|
+
|
101
|
+
def image_name(container_data, image_data)
|
102
|
+
if image_data[:registry_url].present? && !UffizziCore::ComposeFile::ContainerService.google?(container_data)
|
103
|
+
image_data[:name]
|
104
|
+
else
|
105
|
+
"#{image_data[:namespace]}/#{image_data[:name]}"
|
106
|
+
end
|
107
|
+
end
|
108
|
+
|
109
|
+
def ingress_container?(container_name, ingress)
|
110
|
+
ingress[:container_name] == container_name
|
111
|
+
end
|
112
|
+
|
113
|
+
def entrypoint(container_data)
|
114
|
+
entrypoint = container_data[:entrypoint]
|
115
|
+
|
116
|
+
entrypoint.present? ? entrypoint.to_s : nil
|
117
|
+
end
|
118
|
+
|
119
|
+
def command(container_data)
|
120
|
+
command = container_data[:command]
|
121
|
+
|
122
|
+
command.present? ? command.to_s : nil
|
123
|
+
end
|
124
|
+
|
125
|
+
def command_args(command_data)
|
126
|
+
return nil if command_data[:command_args].blank?
|
127
|
+
|
128
|
+
command_data[:command_args].to_s
|
129
|
+
end
|
130
|
+
|
131
|
+
def memory(deploy_data)
|
132
|
+
memory = deploy_data[:memory]
|
133
|
+
return Settings.compose.default_memory if memory.nil?
|
134
|
+
|
135
|
+
memory_value = case memory[:postfix]
|
136
|
+
when 'b'
|
137
|
+
memory[:value] / 1_000_000
|
138
|
+
when 'k'
|
139
|
+
memory[:value] / 1000
|
140
|
+
when 'm'
|
141
|
+
memory[:value]
|
142
|
+
when 'g'
|
143
|
+
memory[:value] * 1000
|
144
|
+
end
|
145
|
+
|
146
|
+
unless Settings.compose.memory_values.include?(memory_value)
|
147
|
+
raise UffizziCore::ComposeFile::BuildError,
|
148
|
+
I18n.t('compose.invalid_memory')
|
149
|
+
end
|
150
|
+
|
151
|
+
memory_value
|
152
|
+
end
|
153
|
+
|
154
|
+
def build_repo_attributes(container_data)
|
155
|
+
repo_type = repo_type(container_data)
|
156
|
+
image_data = container_data[:image]
|
157
|
+
|
158
|
+
case repo_type
|
159
|
+
when UffizziCore::Repo::DockerHub.name
|
160
|
+
build_docker_repo_attributes(image_data, credentials, :docker_hub, UffizziCore::Repo::DockerHub.name)
|
161
|
+
when UffizziCore::Repo::Azure.name
|
162
|
+
build_docker_repo_attributes(image_data, credentials, :azure, UffizziCore::Repo::Azure.name)
|
163
|
+
when UffizziCore::Repo::Google.name
|
164
|
+
build_docker_repo_attributes(image_data, credentials, :google, UffizziCore::Repo::Google.name)
|
165
|
+
when UffizziCore::Repo::GithubContainerRegistry.name
|
166
|
+
build_docker_repo_attributes(image_data, credentials, :github_container_registry, UffizziCore::Repo::GithubContainerRegistry.name)
|
167
|
+
when UffizziCore::Repo::Amazon.name
|
168
|
+
build_docker_repo_attributes(image_data, credentials, :amazon, UffizziCore::Repo::Amazon.name)
|
169
|
+
else
|
170
|
+
raise UffizziCore::ComposeFile::BuildError, I18n.t('compose.invalid_repo_type')
|
171
|
+
end
|
172
|
+
end
|
173
|
+
|
174
|
+
def repo_type(container_data)
|
175
|
+
if UffizziCore::ComposeFile::ContainerService.azure?(container_data)
|
176
|
+
UffizziCore::Repo::Azure.name
|
177
|
+
elsif UffizziCore::ComposeFile::ContainerService.docker_hub?(container_data)
|
178
|
+
UffizziCore::Repo::DockerHub.name
|
179
|
+
elsif UffizziCore::ComposeFile::ContainerService.google?(container_data)
|
180
|
+
UffizziCore::Repo::Google.name
|
181
|
+
elsif UffizziCore::ComposeFile::ContainerService.github_container_registry?(container_data)
|
182
|
+
UffizziCore::Repo::GithubContainerRegistry.name
|
183
|
+
elsif UffizziCore::ComposeFile::ContainerService.amazon?(container_data)
|
184
|
+
UffizziCore::Repo::Amazon.name
|
185
|
+
end
|
186
|
+
end
|
187
|
+
|
188
|
+
def continuously_deploy(deploy_data)
|
189
|
+
return :disabled if deploy_data[:auto] == false
|
190
|
+
|
191
|
+
:enabled
|
192
|
+
end
|
193
|
+
|
194
|
+
def build_docker_repo_attributes(image_data, credentials, scope, repo_type)
|
195
|
+
credential = credentials.send(scope).first
|
196
|
+
raise UffizziCore::ComposeFile::BuildError, I18n.t('compose.invalid_credential', value: scope) if credential.nil?
|
197
|
+
|
198
|
+
docker_builder(repo_type).build_attributes(image_data)
|
199
|
+
end
|
200
|
+
|
201
|
+
def variables(variables_data, dependencies)
|
202
|
+
variables_builder.build_attributes(variables_data, dependencies)
|
203
|
+
end
|
204
|
+
|
205
|
+
def secret_variables(secrets)
|
206
|
+
variables_builder.build_secret_attributes(secrets)
|
207
|
+
end
|
208
|
+
|
209
|
+
def config_files(config_files_data, dependencies)
|
210
|
+
builder = UffizziCore::ComposeFile::Builders::ConfigFilesBuilderService.new(project)
|
211
|
+
|
212
|
+
builder.build_attributes(config_files_data, dependencies)
|
213
|
+
end
|
214
|
+
|
215
|
+
def docker_builder(type)
|
216
|
+
@docker_builder ||= UffizziCore::ComposeFile::Builders::DockerRepoBuilderService.new(type)
|
217
|
+
end
|
218
|
+
|
219
|
+
def variables_builder
|
220
|
+
@variables_builder ||= UffizziCore::ComposeFile::Builders::VariablesBuilderService.new(project)
|
221
|
+
end
|
222
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
class UffizziCore::ComposeFile::Builders::DockerRepoBuilderService
|
4
|
+
attr_accessor :type
|
5
|
+
|
6
|
+
def initialize(type)
|
7
|
+
@type = type
|
8
|
+
end
|
9
|
+
|
10
|
+
def build_attributes(image_data)
|
11
|
+
{
|
12
|
+
kind: nil,
|
13
|
+
name: image_data[:name],
|
14
|
+
slug: image_data[:name],
|
15
|
+
type: type,
|
16
|
+
branch: nil,
|
17
|
+
namespace: image_data[:namespace],
|
18
|
+
is_private: nil, # TODO: detect
|
19
|
+
description: '',
|
20
|
+
repository_id: nil,
|
21
|
+
dockerfile_path: '',
|
22
|
+
dockerfile_context_path: nil,
|
23
|
+
}
|
24
|
+
end
|
25
|
+
end
|