uffizzi-core 0.1.12

Sign up to get free protection for your applications and to get access to all the features.
Files changed (257) hide show
  1. checksums.yaml +7 -0
  2. data/LICENSE +201 -0
  3. data/README.md +52 -0
  4. data/Rakefile +31 -0
  5. data/app/assets/config/uffizzi_core_manifest.js +1 -0
  6. data/app/assets/stylesheets/uffizzi_core/application.css +15 -0
  7. data/app/clients/uffizzi_core/amazon_registry_client.rb +18 -0
  8. data/app/clients/uffizzi_core/azure_registry_client/request_result.rb +5 -0
  9. data/app/clients/uffizzi_core/azure_registry_client.rb +42 -0
  10. data/app/clients/uffizzi_core/controller_client/request_result.rb +5 -0
  11. data/app/clients/uffizzi_core/controller_client.rb +106 -0
  12. data/app/clients/uffizzi_core/docker_hub_client/request_result.rb +7 -0
  13. data/app/clients/uffizzi_core/docker_hub_client.rb +141 -0
  14. data/app/clients/uffizzi_core/github_container_registry_client/request_result.rb +7 -0
  15. data/app/clients/uffizzi_core/github_container_registry_client.rb +52 -0
  16. data/app/clients/uffizzi_core/google_registry_client/request_result.rb +5 -0
  17. data/app/clients/uffizzi_core/google_registry_client.rb +42 -0
  18. data/app/contexts/uffizzi_core/base_context.rb +12 -0
  19. data/app/contexts/uffizzi_core/project_context.rb +13 -0
  20. data/app/contexts/uffizzi_core/webhooks_context.rb +9 -0
  21. data/app/controllers/concerns/uffizzi_core/auth_management.rb +23 -0
  22. data/app/controllers/concerns/uffizzi_core/authorization_concern.rb +38 -0
  23. data/app/controllers/concerns/uffizzi_core/dependency_injection_concern.rb +19 -0
  24. data/app/controllers/uffizzi_core/api/cli/v1/account/application_controller.rb +7 -0
  25. data/app/controllers/uffizzi_core/api/cli/v1/account/credentials_controller.rb +91 -0
  26. data/app/controllers/uffizzi_core/api/cli/v1/application_controller.rb +5 -0
  27. data/app/controllers/uffizzi_core/api/cli/v1/projects/application_controller.rb +11 -0
  28. data/app/controllers/uffizzi_core/api/cli/v1/projects/compose_files_controller.rb +93 -0
  29. data/app/controllers/uffizzi_core/api/cli/v1/projects/deployments/activity_items_controller.rb +36 -0
  30. data/app/controllers/uffizzi_core/api/cli/v1/projects/deployments/application_controller.rb +7 -0
  31. data/app/controllers/uffizzi_core/api/cli/v1/projects/deployments/containers/application_controller.rb +8 -0
  32. data/app/controllers/uffizzi_core/api/cli/v1/projects/deployments/containers/logs_controller.rb +27 -0
  33. data/app/controllers/uffizzi_core/api/cli/v1/projects/deployments/containers_controller.rb +24 -0
  34. data/app/controllers/uffizzi_core/api/cli/v1/projects/deployments/events_controller.rb +29 -0
  35. data/app/controllers/uffizzi_core/api/cli/v1/projects/deployments_controller.rb +179 -0
  36. data/app/controllers/uffizzi_core/api/cli/v1/projects/secrets_controller.rb +61 -0
  37. data/app/controllers/uffizzi_core/api/cli/v1/projects_controller.rb +85 -0
  38. data/app/controllers/uffizzi_core/api/cli/v1/sessions_controller.rb +43 -0
  39. data/app/controllers/uffizzi_core/application_controller.rb +57 -0
  40. data/app/errors/uffizzi_core/compose_file/build_error.rb +4 -0
  41. data/app/errors/uffizzi_core/compose_file/credential_error.rb +4 -0
  42. data/app/errors/uffizzi_core/compose_file/parse_error.rb +4 -0
  43. data/app/errors/uffizzi_core/compose_file/secrets_error.rb +4 -0
  44. data/app/errors/uffizzi_core/deployment/image_pull_error.rb +10 -0
  45. data/app/errors/uffizzi_core/deployment_not_found_error.rb +10 -0
  46. data/app/forms/uffizzi_core/api/cli/v1/account/credential/check_credential_form.rb +16 -0
  47. data/app/forms/uffizzi_core/api/cli/v1/account/credential/create_form.rb +26 -0
  48. data/app/forms/uffizzi_core/api/cli/v1/compose_file/check_credentials_form.rb +21 -0
  49. data/app/forms/uffizzi_core/api/cli/v1/compose_file/cli_form.rb +22 -0
  50. data/app/forms/uffizzi_core/api/cli/v1/compose_file/create_form.rb +13 -0
  51. data/app/forms/uffizzi_core/api/cli/v1/compose_file/template_form.rb +44 -0
  52. data/app/forms/uffizzi_core/api/cli/v1/compose_file/update_form.rb +9 -0
  53. data/app/forms/uffizzi_core/api/cli/v1/config_file/create_form.rb +11 -0
  54. data/app/forms/uffizzi_core/api/cli/v1/deployment/create_form.rb +92 -0
  55. data/app/forms/uffizzi_core/api/cli/v1/deployment/update_form.rb +90 -0
  56. data/app/forms/uffizzi_core/api/cli/v1/project/create_form.rb +7 -0
  57. data/app/forms/uffizzi_core/api/cli/v1/project/update_form.rb +10 -0
  58. data/app/forms/uffizzi_core/api/cli/v1/secret/bulk_assign_form.rb +39 -0
  59. data/app/forms/uffizzi_core/api/cli/v1/session_create_form.rb +29 -0
  60. data/app/forms/uffizzi_core/api/cli/v1/template/create_form.rb +65 -0
  61. data/app/forms/uffizzi_core/application_form.rb +11 -0
  62. data/app/forms/uffizzi_core/application_form_without_active_record.rb +17 -0
  63. data/app/forms/uffizzi_core/mass_assignment_control_concern.rb +22 -0
  64. data/app/helpers/uffizzi_core/application_helper.rb +6 -0
  65. data/app/jobs/uffizzi_core/account/create_credential_job.rb +10 -0
  66. data/app/jobs/uffizzi_core/activity_item/docker/update_digest_job.rb +11 -0
  67. data/app/jobs/uffizzi_core/application_job.rb +7 -0
  68. data/app/jobs/uffizzi_core/config_file/apply_job.rb +31 -0
  69. data/app/jobs/uffizzi_core/credential/docker_hub/create_webhook_job.rb +15 -0
  70. data/app/jobs/uffizzi_core/deployment/create_credential_job.rb +32 -0
  71. data/app/jobs/uffizzi_core/deployment/create_credentials_job.rb +17 -0
  72. data/app/jobs/uffizzi_core/deployment/create_job.rb +15 -0
  73. data/app/jobs/uffizzi_core/deployment/create_webhooks_job.rb +13 -0
  74. data/app/jobs/uffizzi_core/deployment/delete_credential_job.rb +13 -0
  75. data/app/jobs/uffizzi_core/deployment/delete_job.rb +11 -0
  76. data/app/jobs/uffizzi_core/deployment/deploy_containers_job.rb +27 -0
  77. data/app/jobs/uffizzi_core/deployment/manage_deploy_activity_item_job.rb +38 -0
  78. data/app/lib/uffizzi_core/concerns/models/activity_item.rb +39 -0
  79. data/app/lib/uffizzi_core/concerns/models/credential.rb +65 -0
  80. data/app/lib/uffizzi_core/concerns/models/repo.rb +33 -0
  81. data/app/lib/uffizzi_core/rbac/user_access_service.rb +45 -0
  82. data/app/mailers/uffizzi_core/application_mailer.rb +8 -0
  83. data/app/models/concerns/uffizzi_core/hashid_concern.rb +25 -0
  84. data/app/models/concerns/uffizzi_core/state_machine_concern.rb +16 -0
  85. data/app/models/uffizzi_core/account.rb +83 -0
  86. data/app/models/uffizzi_core/activity_item/docker.rb +4 -0
  87. data/app/models/uffizzi_core/activity_item/github.rb +4 -0
  88. data/app/models/uffizzi_core/activity_item/memory_limit.rb +4 -0
  89. data/app/models/uffizzi_core/activity_item.rb +53 -0
  90. data/app/models/uffizzi_core/application_record.rb +7 -0
  91. data/app/models/uffizzi_core/build.rb +39 -0
  92. data/app/models/uffizzi_core/comment.rb +16 -0
  93. data/app/models/uffizzi_core/compose_file.rb +57 -0
  94. data/app/models/uffizzi_core/config_file.rb +24 -0
  95. data/app/models/uffizzi_core/container.rb +100 -0
  96. data/app/models/uffizzi_core/container_config_file.rb +8 -0
  97. data/app/models/uffizzi_core/continuous_preview.rb +4 -0
  98. data/app/models/uffizzi_core/coupon.rb +5 -0
  99. data/app/models/uffizzi_core/credential/amazon.rb +4 -0
  100. data/app/models/uffizzi_core/credential/azure.rb +4 -0
  101. data/app/models/uffizzi_core/credential/docker_hub.rb +4 -0
  102. data/app/models/uffizzi_core/credential/github.rb +4 -0
  103. data/app/models/uffizzi_core/credential/github_container_registry.rb +4 -0
  104. data/app/models/uffizzi_core/credential/google.rb +4 -0
  105. data/app/models/uffizzi_core/credential.rb +61 -0
  106. data/app/models/uffizzi_core/database.rb +4 -0
  107. data/app/models/uffizzi_core/database_offering.rb +4 -0
  108. data/app/models/uffizzi_core/deployment.rb +86 -0
  109. data/app/models/uffizzi_core/event.rb +13 -0
  110. data/app/models/uffizzi_core/invitation.rb +27 -0
  111. data/app/models/uffizzi_core/membership.rb +16 -0
  112. data/app/models/uffizzi_core/payment.rb +11 -0
  113. data/app/models/uffizzi_core/price.rb +9 -0
  114. data/app/models/uffizzi_core/product.rb +11 -0
  115. data/app/models/uffizzi_core/project.rb +67 -0
  116. data/app/models/uffizzi_core/rating.rb +20 -0
  117. data/app/models/uffizzi_core/repo/amazon.rb +4 -0
  118. data/app/models/uffizzi_core/repo/azure.rb +4 -0
  119. data/app/models/uffizzi_core/repo/docker_hub.rb +4 -0
  120. data/app/models/uffizzi_core/repo/github.rb +4 -0
  121. data/app/models/uffizzi_core/repo/github_container_registry.rb +4 -0
  122. data/app/models/uffizzi_core/repo/google.rb +4 -0
  123. data/app/models/uffizzi_core/repo.rb +29 -0
  124. data/app/models/uffizzi_core/role.rb +17 -0
  125. data/app/models/uffizzi_core/secret.rb +9 -0
  126. data/app/models/uffizzi_core/template.rb +19 -0
  127. data/app/models/uffizzi_core/user.rb +62 -0
  128. data/app/models/uffizzi_core/user_project.rb +14 -0
  129. data/app/policies/uffizzi_core/api/cli/v1/account/credentials_policy.rb +19 -0
  130. data/app/policies/uffizzi_core/api/cli/v1/projects/compose_files_policy.rb +15 -0
  131. data/app/policies/uffizzi_core/api/cli/v1/projects/deployments/activity_items_policy.rb +7 -0
  132. data/app/policies/uffizzi_core/api/cli/v1/projects/deployments/containers_policy.rb +7 -0
  133. data/app/policies/uffizzi_core/api/cli/v1/projects/deployments/events_policy.rb +7 -0
  134. data/app/policies/uffizzi_core/api/cli/v1/projects/deployments_policy.rb +27 -0
  135. data/app/policies/uffizzi_core/api/cli/v1/projects/secrets_policy.rb +15 -0
  136. data/app/policies/uffizzi_core/api/cli/v1/projects_policy.rb +19 -0
  137. data/app/policies/uffizzi_core/application_policy.rb +12 -0
  138. data/app/repositories/uffizzi_core/activity_item_repo.rb +9 -0
  139. data/app/repositories/uffizzi_core/basic_order_repo.rb +11 -0
  140. data/app/repositories/uffizzi_core/build_repo.rb +23 -0
  141. data/app/repositories/uffizzi_core/comment_repo.rb +11 -0
  142. data/app/repositories/uffizzi_core/compose_file_repo.rb +11 -0
  143. data/app/repositories/uffizzi_core/config_file_repo.rb +40 -0
  144. data/app/repositories/uffizzi_core/container_repo.rb +25 -0
  145. data/app/repositories/uffizzi_core/credential_repo.rb +31 -0
  146. data/app/repositories/uffizzi_core/deployment_repo.rb +24 -0
  147. data/app/repositories/uffizzi_core/event_repo.rb +9 -0
  148. data/app/repositories/uffizzi_core/membership_repo.rb +10 -0
  149. data/app/repositories/uffizzi_core/price_repo.rb +11 -0
  150. data/app/repositories/uffizzi_core/product_repo.rb +11 -0
  151. data/app/repositories/uffizzi_core/project_repo.rb +10 -0
  152. data/app/repositories/uffizzi_core/repo_repo.rb +10 -0
  153. data/app/repositories/uffizzi_core/template_repo.rb +87 -0
  154. data/app/repositories/uffizzi_core/usage_repo.rb +9 -0
  155. data/app/repositories/uffizzi_core/user_repo.rb +11 -0
  156. data/app/responders/uffizzi_core/json_responder.rb +13 -0
  157. data/app/serializers/uffizzi_core/api/cli/v1/account/credential_serializer.rb +9 -0
  158. data/app/serializers/uffizzi_core/api/cli/v1/project_serializer/compose_file_serializer.rb +7 -0
  159. data/app/serializers/uffizzi_core/api/cli/v1/project_serializer/deployment_serializer.rb +13 -0
  160. data/app/serializers/uffizzi_core/api/cli/v1/project_serializer.rb +30 -0
  161. data/app/serializers/uffizzi_core/api/cli/v1/projects/compose_file_serializer.rb +7 -0
  162. data/app/serializers/uffizzi_core/api/cli/v1/projects/deployment_serializer/container_serializer.rb +32 -0
  163. data/app/serializers/uffizzi_core/api/cli/v1/projects/deployment_serializer/user_serializer.rb +11 -0
  164. data/app/serializers/uffizzi_core/api/cli/v1/projects/deployment_serializer.rb +74 -0
  165. data/app/serializers/uffizzi_core/api/cli/v1/projects/deployments/activity_item_serializer.rb +24 -0
  166. data/app/serializers/uffizzi_core/api/cli/v1/projects/deployments/container_serializer/container_config_file_serializer/config_file_serializer.rb +6 -0
  167. data/app/serializers/uffizzi_core/api/cli/v1/projects/deployments/container_serializer/container_config_file_serializer.rb +7 -0
  168. data/app/serializers/uffizzi_core/api/cli/v1/projects/deployments/container_serializer.rb +30 -0
  169. data/app/serializers/uffizzi_core/api/cli/v1/projects/secret_serializer.rb +5 -0
  170. data/app/serializers/uffizzi_core/api/cli/v1/short_project_serializer.rb +7 -0
  171. data/app/serializers/uffizzi_core/api/cli/v1/user_serializer/account_serializer.rb +5 -0
  172. data/app/serializers/uffizzi_core/api/cli/v1/user_serializer.rb +7 -0
  173. data/app/serializers/uffizzi_core/base_serializer.rb +7 -0
  174. data/app/serializers/uffizzi_core/controller/apply_config_file/config_file_serializer.rb +5 -0
  175. data/app/serializers/uffizzi_core/controller/create_credential/credential_serializer.rb +19 -0
  176. data/app/serializers/uffizzi_core/controller/create_deployment/deployment_serializer.rb +5 -0
  177. data/app/serializers/uffizzi_core/controller/deploy_containers/container_serializer/container_config_file_serializer/config_file_serializer.rb +8 -0
  178. data/app/serializers/uffizzi_core/controller/deploy_containers/container_serializer/container_config_file_serializer.rb +7 -0
  179. data/app/serializers/uffizzi_core/controller/deploy_containers/container_serializer.rb +70 -0
  180. data/app/serializers/uffizzi_core/controller/deploy_containers/credential_serializer.rb +5 -0
  181. data/app/services/uffizzi_core/account_service.rb +21 -0
  182. data/app/services/uffizzi_core/activity_item_service.rb +88 -0
  183. data/app/services/uffizzi_core/amazon/credential_service.rb +31 -0
  184. data/app/services/uffizzi_core/amazon_service.rb +45 -0
  185. data/app/services/uffizzi_core/azure/credential_service.rb +18 -0
  186. data/app/services/uffizzi_core/compose_file/builders/config_files_builder_service.rb +31 -0
  187. data/app/services/uffizzi_core/compose_file/builders/container_builder_service.rb +222 -0
  188. data/app/services/uffizzi_core/compose_file/builders/docker_repo_builder_service.rb +25 -0
  189. data/app/services/uffizzi_core/compose_file/builders/template_builder_service.rb +45 -0
  190. data/app/services/uffizzi_core/compose_file/builders/variables_builder_service.rb +58 -0
  191. data/app/services/uffizzi_core/compose_file/config_files_service.rb +52 -0
  192. data/app/services/uffizzi_core/compose_file/config_option_service.rb +41 -0
  193. data/app/services/uffizzi_core/compose_file/configs_options_service.rb +26 -0
  194. data/app/services/uffizzi_core/compose_file/container_service.rb +68 -0
  195. data/app/services/uffizzi_core/compose_file/continuous_preview_options_service.rb +57 -0
  196. data/app/services/uffizzi_core/compose_file/dependencies_service.rb +56 -0
  197. data/app/services/uffizzi_core/compose_file/errors_service.rb +46 -0
  198. data/app/services/uffizzi_core/compose_file/github_dependencies_service.rb +38 -0
  199. data/app/services/uffizzi_core/compose_file/ingress_options_service.rb +51 -0
  200. data/app/services/uffizzi_core/compose_file/parsers/services/healthcheck_parser_service.rb +73 -0
  201. data/app/services/uffizzi_core/compose_file/secrets_options_service.rb +28 -0
  202. data/app/services/uffizzi_core/compose_file/services_options/command_service.rb +18 -0
  203. data/app/services/uffizzi_core/compose_file/services_options/configs_service.rb +51 -0
  204. data/app/services/uffizzi_core/compose_file/services_options/deploy_service.rb +44 -0
  205. data/app/services/uffizzi_core/compose_file/services_options/entrypoint_service.rb +18 -0
  206. data/app/services/uffizzi_core/compose_file/services_options/env_file_service.rb +34 -0
  207. data/app/services/uffizzi_core/compose_file/services_options/environment_service.rb +20 -0
  208. data/app/services/uffizzi_core/compose_file/services_options/image_service.rb +89 -0
  209. data/app/services/uffizzi_core/compose_file/services_options/secrets_service.rb +35 -0
  210. data/app/services/uffizzi_core/compose_file/services_options_service.rb +57 -0
  211. data/app/services/uffizzi_core/compose_file/template_service.rb +55 -0
  212. data/app/services/uffizzi_core/compose_file/variables_service.rb +25 -0
  213. data/app/services/uffizzi_core/compose_file_service.rb +181 -0
  214. data/app/services/uffizzi_core/container_service.rb +42 -0
  215. data/app/services/uffizzi_core/controller_service.rb +86 -0
  216. data/app/services/uffizzi_core/credential_service.rb +44 -0
  217. data/app/services/uffizzi_core/deployment_service.rb +307 -0
  218. data/app/services/uffizzi_core/docker_hub/credential_service.rb +15 -0
  219. data/app/services/uffizzi_core/docker_hub_service.rb +77 -0
  220. data/app/services/uffizzi_core/github_container_registry/credential_service.rb +24 -0
  221. data/app/services/uffizzi_core/google/credential_service.rb +18 -0
  222. data/app/services/uffizzi_core/logs_service.rb +33 -0
  223. data/app/services/uffizzi_core/manage_activity_items_service.rb +159 -0
  224. data/app/services/uffizzi_core/project_service.rb +48 -0
  225. data/app/services/uffizzi_core/repo_service.rb +43 -0
  226. data/app/services/uffizzi_core/response_service.rb +13 -0
  227. data/app/services/uffizzi_core/starter_template_service.rb +200 -0
  228. data/app/services/uffizzi_core/template_service.rb +21 -0
  229. data/app/services/uffizzi_core/token_service.rb +19 -0
  230. data/app/services/uffizzi_core/user_access_service.rb +14 -0
  231. data/app/services/uffizzi_core/user_generator_service.rb +84 -0
  232. data/app/utils/uffizzi_core/converters.rb +33 -0
  233. data/app/validators/uffizzi_core/email_validator.rb +9 -0
  234. data/app/validators/uffizzi_core/environment_variable_list_validator.rb +15 -0
  235. data/app/validators/uffizzi_core/image_command_args_validator.rb +21 -0
  236. data/config/initializers/rswag_api.rb +15 -0
  237. data/config/initializers/rswag_ui.rb +15 -0
  238. data/config/initializers/swagger_yard.rb +17 -0
  239. data/config/locales/en.activerecord.yml +23 -0
  240. data/config/locales/en.yml +66 -0
  241. data/config/routes.rb +69 -0
  242. data/db/migrate/20220218121438_create_uffizzi_core_tables.rb +375 -0
  243. data/db/migrate/20220309110201_remove_secrets_from_projects.rb +7 -0
  244. data/db/migrate/20220310110150_create_project_secrets.rb +14 -0
  245. data/db/migrate/20220325113342_add_name_to_uffizzi_containers.rb +7 -0
  246. data/db/migrate/20220329123323_rename_project_secrets_to_secrets.rb +7 -0
  247. data/db/migrate/20220329124542_add_resource_to_secrets.rb +7 -0
  248. data/db/migrate/20220329143241_remove_project_ref_from_secrets.rb +7 -0
  249. data/db/migrate/20220419074956_add_health_check_to_containers.rb +7 -0
  250. data/db/migrate/20220525113412_rename_name_to_uffizzi_containers.rb +7 -0
  251. data/db/seeds.rb +16 -0
  252. data/lib/tasks/uffizzi_core_tasks.rake +19 -0
  253. data/lib/uffizzi_core/engine.rb +15 -0
  254. data/lib/uffizzi_core/version.rb +5 -0
  255. data/lib/uffizzi_core.rb +61 -0
  256. data/swagger/v1/swagger.json +1659 -0
  257. metadata +966 -0
@@ -0,0 +1,92 @@
1
+ # frozen_string_literal: true
2
+
3
+ class UffizziCore::Api::Cli::V1::Deployment::CreateForm < UffizziCore::Deployment
4
+ include UffizziCore::ApplicationForm
5
+
6
+ permit :creation_source,
7
+ containers_attributes: [
8
+ :image,
9
+ :service_name,
10
+ :tag,
11
+ :port,
12
+ :public,
13
+ :memory_limit,
14
+ :memory_request,
15
+ :entrypoint,
16
+ :command,
17
+ :receive_incoming_requests,
18
+ :continuously_deploy,
19
+ { healthcheck: {} },
20
+ { variables: [:name, :value],
21
+ secret_variables: [:name, :value],
22
+ repo_attributes: [
23
+ :namespace,
24
+ :name,
25
+ :slug,
26
+ :type,
27
+ :description,
28
+ :is_private,
29
+ :repository_id,
30
+ :branch,
31
+ :kind,
32
+ :dockerfile_path,
33
+ :dockerfile_context_path,
34
+ :deploy_preview_when_pull_request_is_opened,
35
+ :delete_preview_when_pull_request_is_closed,
36
+ :deploy_preview_when_image_tag_is_created,
37
+ :delete_preview_when_image_tag_is_updated,
38
+ :share_to_github,
39
+ :delete_preview_after,
40
+ { args: [:name, :value] },
41
+ ],
42
+ container_config_files_attributes: [
43
+ :config_file_id,
44
+ :mount_path,
45
+ ] },
46
+ ]
47
+
48
+ validate :check_all_containers_have_unique_ports
49
+ validate :check_exists_ingress_container
50
+ validate :check_max_memory_limit
51
+ validate :check_max_memory_request
52
+
53
+ def assign_dependences!(project, user)
54
+ self.project = project
55
+
56
+ self.containers = containers.map do |container|
57
+ container.repo.project = project if !container.repo.nil?
58
+
59
+ container
60
+ end
61
+
62
+ self.deployed_by = user
63
+
64
+ self
65
+ end
66
+
67
+ private
68
+
69
+ def check_all_containers_have_unique_ports
70
+ active_containers = containers.select(&:active?)
71
+
72
+ errors.add(:containers, :duplicate_ports) unless UffizziCore::DeploymentService.all_containers_have_unique_ports?(active_containers)
73
+ end
74
+
75
+ def check_exists_ingress_container
76
+ active_containers = containers.select(&:active?)
77
+
78
+ errors.add(:containers, :incorrect_ingress_container) unless UffizziCore::DeploymentService.ingress_container?(active_containers)
79
+ end
80
+
81
+ def check_max_memory_limit
82
+ return if UffizziCore::DeploymentService.valid_containers_memory_limit?(self)
83
+
84
+ errors.add(:containers, :max_memory_limit_error, max: project.account.container_memory_limit)
85
+ end
86
+
87
+ def check_max_memory_request
88
+ return if UffizziCore::DeploymentService.valid_containers_memory_request?(self)
89
+
90
+ errors.add(:containers, :max_memory_request_error, max: project.account.container_memory_limit)
91
+ end
92
+ end
@@ -0,0 +1,90 @@
1
+ # frozen_string_literal: true
2
+
3
+ class UffizziCore::Api::Cli::V1::Deployment::UpdateForm < UffizziCore::Deployment
4
+ include UffizziCore::ApplicationForm
5
+
6
+ permit containers_attributes: [
7
+ :image,
8
+ :name,
9
+ :tag,
10
+ :port,
11
+ :public,
12
+ :memory_limit,
13
+ :memory_request,
14
+ :entrypoint,
15
+ :command,
16
+ :receive_incoming_requests,
17
+ :continuously_deploy,
18
+ { variables: [:name, :value],
19
+ secret_variables: [:name, :value],
20
+ repo_attributes: [
21
+ :namespace,
22
+ :name,
23
+ :slug,
24
+ :type,
25
+ :description,
26
+ :is_private,
27
+ :repository_id,
28
+ :branch,
29
+ :kind,
30
+ :dockerfile_path,
31
+ :dockerfile_context_path,
32
+ :deploy_preview_when_pull_request_is_opened,
33
+ :delete_preview_when_pull_request_is_closed,
34
+ :deploy_preview_when_image_tag_is_created,
35
+ :delete_preview_when_image_tag_is_updated,
36
+ :share_to_github,
37
+ :delete_preview_after,
38
+ { args: [:name, :value] },
39
+ ],
40
+ container_config_files_attributes: [
41
+ :config_file_id,
42
+ :mount_path,
43
+ ] },
44
+ ]
45
+
46
+ validate :check_all_containers_have_unique_ports
47
+ validate :check_exists_ingress_container
48
+ validate :check_max_memory_limit
49
+ validate :check_max_memory_request
50
+
51
+ def assign_dependences!(project, user)
52
+ self.project = project
53
+
54
+ self.containers = containers.map do |container|
55
+ container.repo.project = project if !container.repo.nil?
56
+
57
+ container
58
+ end
59
+
60
+ self.deployed_by = user
61
+
62
+ self
63
+ end
64
+
65
+ private
66
+
67
+ def check_all_containers_have_unique_ports
68
+ active_containers = containers.select(&:active?)
69
+
70
+ errors.add(:containers, :duplicate_ports) unless UffizziCore::DeploymentService.all_containers_have_unique_ports?(active_containers)
71
+ end
72
+
73
+ def check_exists_ingress_container
74
+ active_containers = containers.select(&:active?)
75
+
76
+ errors.add(:containers, :incorrect_ingress_container) unless UffizziCore::DeploymentService.ingress_container?(active_containers)
77
+ end
78
+
79
+ def check_max_memory_limit
80
+ return if UffizziCore::DeploymentService.valid_containers_memory_limit?(self)
81
+
82
+ errors.add(:containers, :max_memory_limit_error, max: project.account.container_memory_limit)
83
+ end
84
+
85
+ def check_max_memory_request
86
+ return if UffizziCore::DeploymentService.valid_containers_memory_request?(self)
87
+
88
+ errors.add(:containers, :max_memory_request_error, max: project.account.container_memory_limit)
89
+ end
90
+ end
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ class UffizziCore::Api::Cli::V1::Project::CreateForm < UffizziCore::Project
4
+ include UffizziCore::ApplicationForm
5
+
6
+ permit :name, :slug, :description
7
+ end
@@ -0,0 +1,10 @@
1
+ # frozen_string_literal: true
2
+
3
+ class UffizziCore::Api::Cli::V1::Project::UpdateForm < UffizziCore::Project
4
+ include UffizziCore::ApplicationForm
5
+
6
+ permit :name, :slug, :description
7
+
8
+ validates :name, presence: true, uniqueness: { scope: :account }
9
+ validates :slug, presence: true, uniqueness: true
10
+ end
@@ -0,0 +1,39 @@
1
+ # frozen_string_literal: true
2
+
3
+ class UffizziCore::Api::Cli::V1::Secret::BulkAssignForm
4
+ include UffizziCore::ApplicationFormWithoutActiveRecord
5
+ MAX_SECRET_KEY_LENGTH = 256
6
+
7
+ attribute :secrets, Array
8
+ validate :check_duplicates
9
+ validate :check_length
10
+
11
+ def assign_secrets(new_secrets)
12
+ return if new_secrets.blank?
13
+
14
+ new_secrets.each do |new_secret|
15
+ secret = UffizziCore::Secret.new(name: new_secret['name'], value: new_secret['value'])
16
+ secrets.append(secret)
17
+ end
18
+ end
19
+
20
+ private
21
+
22
+ def check_duplicates
23
+ duplicates = []
24
+ groupped_secrets = secrets.group_by { |secret| secret['name'] }
25
+ groupped_secrets.each_pair do |key, value|
26
+ duplicates << key if value.size > 1
27
+ end
28
+
29
+ error_message = I18n.t('secrets.duplicates_exists', secrets: duplicates.join(', '))
30
+ errors.add(:secrets, error_message) if duplicates.present?
31
+ end
32
+
33
+ def check_length
34
+ secrets_with_invalid_key_length = secrets.select { |secret| secret['name'].length > MAX_SECRET_KEY_LENGTH }
35
+
36
+ error_message = I18n.t('secrets.invalid_key_length')
37
+ errors.add(:secrets, error_message) if secrets_with_invalid_key_length.present?
38
+ end
39
+ end
@@ -0,0 +1,29 @@
1
+ # frozen_string_literal: true
2
+
3
+ class UffizziCore::Api::Cli::V1::SessionCreateForm
4
+ include UffizziCore::ApplicationFormWithoutActiveRecord
5
+
6
+ attribute :email, String
7
+ attribute :password, String
8
+
9
+ validates :email, :password, presence: true
10
+ validate :check_authenticate, if: :email
11
+
12
+ def user
13
+ @user ||= UffizziCore::User.active.by_email(email).first
14
+ end
15
+
16
+ def check_authenticate
17
+ return unless wrong_email_or_password?
18
+
19
+ errors.add(:password, 'Email or password is incorrect.')
20
+ end
21
+
22
+ private
23
+
24
+ def wrong_email_or_password?
25
+ return true if user.nil?
26
+
27
+ !user.authenticate(password)
28
+ end
29
+ end
@@ -0,0 +1,65 @@
1
+ # frozen_string_literal: true
2
+
3
+ class UffizziCore::Api::Cli::V1::Template::CreateForm < UffizziCore::Template
4
+ include UffizziCore::ApplicationForm
5
+
6
+ permit :name,
7
+ payload: {
8
+ containers_attributes: [
9
+ :image,
10
+ :tag,
11
+ :port,
12
+ :public,
13
+ :memory_limit,
14
+ :memory_request,
15
+ :entrypoint,
16
+ :command,
17
+ :receive_incoming_requests,
18
+ :continuously_deploy,
19
+ :service_name,
20
+ { variables: [:name, :value],
21
+ secret_variables: [:name, :value],
22
+ repo_attributes: [
23
+ :namespace,
24
+ :name,
25
+ :slug,
26
+ :type,
27
+ :description,
28
+ :repository_id,
29
+ :is_private,
30
+ :branch,
31
+ :kind,
32
+ :dockerfile_path,
33
+ :dockerfile_context_path,
34
+ :deploy_preview_when_pull_request_is_opened,
35
+ :delete_preview_when_pull_request_is_closed,
36
+ :deploy_preview_when_image_tag_is_created,
37
+ :delete_preview_when_image_tag_is_updated,
38
+ :share_to_github,
39
+ :delete_preview_after,
40
+ { args: [:name, :value] },
41
+ ],
42
+ container_config_files_attributes: [
43
+ :config_file_id,
44
+ :mount_path,
45
+ ] },
46
+ ],
47
+ }
48
+
49
+ validate :check_max_memory_limit
50
+ validate :check_max_memory_request
51
+
52
+ private
53
+
54
+ def check_max_memory_limit
55
+ return if UffizziCore::TemplateService.valid_containers_memory_limit?(self)
56
+
57
+ errors.add(:payload, :max_memory_limit_error, max: project.account.container_memory_limit)
58
+ end
59
+
60
+ def check_max_memory_request
61
+ return if UffizziCore::TemplateService.valid_containers_memory_request?(self)
62
+
63
+ errors.add(:payload, :max_memory_request_error, max: project.account.container_memory_limit)
64
+ end
65
+ end
@@ -0,0 +1,11 @@
1
+ # frozen_string_literal: true
2
+
3
+ module UffizziCore::ApplicationForm
4
+ extend ActiveSupport::Concern
5
+
6
+ include UffizziCore::MassAssignmentControlConcern
7
+
8
+ class_methods do
9
+ delegate :model_name, :name, to: :superclass
10
+ end
11
+ end
@@ -0,0 +1,17 @@
1
+ # frozen_string_literal: true
2
+
3
+ module UffizziCore::ApplicationFormWithoutActiveRecord
4
+ extend ActiveSupport::Concern
5
+
6
+ included do
7
+ include ActiveModel::Validations
8
+ include ActiveModel::Conversion
9
+ include ActiveModel::Serialization
10
+ include ActiveModel::Validations::Callbacks
11
+ include ::Virtus.model
12
+ end
13
+
14
+ def persisted?
15
+ false
16
+ end
17
+ end
@@ -0,0 +1,22 @@
1
+ # frozen_string_literal: true
2
+
3
+ module UffizziCore::MassAssignmentControlConcern
4
+ extend ActiveSupport::Concern
5
+
6
+ class_methods do
7
+ def permit(*args)
8
+ @_args = args
9
+ end
10
+
11
+ def _args
12
+ @_args
13
+ end
14
+ end
15
+
16
+ def assign_attributes(attrs = ActionController::Parameters.new)
17
+ attrs = ActionController::Parameters.new if attrs.nil?
18
+
19
+ new_attrs = attrs.permit(*self.class._args)
20
+ super(new_attrs)
21
+ end
22
+ end
@@ -0,0 +1,6 @@
1
+ # frozen_string_literal: true
2
+
3
+ module UffizziCore
4
+ module ApplicationHelper
5
+ end
6
+ end
@@ -0,0 +1,10 @@
1
+ # frozen_string_literal: true
2
+
3
+ class UffizziCore::Account::CreateCredentialJob < UffizziCore::ApplicationJob
4
+ sidekiq_options queue: :accounts, retry: 5
5
+
6
+ def perform(id)
7
+ credential = UffizziCore::Credential.find(id)
8
+ UffizziCore::AccountService.create_credential(credential)
9
+ end
10
+ end
@@ -0,0 +1,11 @@
1
+ # frozen_string_literal: true
2
+
3
+ class UffizziCore::ActivityItem::Docker::UpdateDigestJob < UffizziCore::ApplicationJob
4
+ sidekiq_options queue: :deployments, retry: 5
5
+
6
+ def perform(id)
7
+ activity_item = UffizziCore::ActivityItem.find(id)
8
+
9
+ UffizziCore::ActivityItemService.update_docker_digest!(activity_item)
10
+ end
11
+ end
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ module UffizziCore
4
+ class ApplicationJob
5
+ include Sidekiq::Worker
6
+ end
7
+ end
@@ -0,0 +1,31 @@
1
+ # frozen_string_literal: true
2
+
3
+ class UffizziCore::ConfigFile::ApplyJob < UffizziCore::ApplicationJob
4
+ sidekiq_options queue: :config_files, retry: Settings.controller.resource_create_retry_count
5
+
6
+ sidekiq_retry_in do |count, exception|
7
+ case exception
8
+ when UffizziCore::ControllerService::DeploymentNotFoundError
9
+ Rails.logger.info("DEPLOYMENT_PROCESS ApplyJob retry deployment_id=#{exception.deployment_id} count=#{count}")
10
+ Settings.controller.resource_create_retry_time
11
+ end
12
+ end
13
+
14
+ def perform(deployment_id, config_file_id)
15
+ Rails.logger.info("DEPLOYMENT_PROCESS deployment_id=#{deployment_id} Apply ConfigFile(config_file_id:#{config_file_id})")
16
+
17
+ deployment = UffizziCore::Deployment.find(deployment_id)
18
+ config_file = UffizziCore::ConfigFile.find(config_file_id)
19
+ if deployment.disabled?
20
+ Rails.logger.info("DEPLOYMENT_PROCESS deployment_id=#{deployment.id} deployment was disabled stop config file applying")
21
+ return
22
+ end
23
+
24
+ unless UffizziCore::ControllerService.deployment_exists?(deployment)
25
+ raise UffizziCore::ControllerService::DeploymentNotFoundError,
26
+ deployment_id
27
+ end
28
+
29
+ UffizziCore::ControllerService.apply_config_file(deployment, config_file)
30
+ end
31
+ end
@@ -0,0 +1,15 @@
1
+ # frozen_string_literal: true
2
+
3
+ class UffizziCore::Credential::DockerHub::CreateWebhookJob < UffizziCore::ApplicationJob
4
+ sidekiq_options queue: :accounts, retry: 5
5
+
6
+ def perform(credential_id, image, deployment_id = nil)
7
+ if deployment_id.present?
8
+ Rails.logger.info("DEPLOYMENT_PROCESS deployment_id=#{deployment_id} DockerHub CreateWebhooksJob")
9
+ end
10
+
11
+ credential = UffizziCore::Credential.find(credential_id)
12
+
13
+ UffizziCore::DockerHubService.create_webhook(credential, image)
14
+ end
15
+ end
@@ -0,0 +1,32 @@
1
+ # frozen_string_literal: true
2
+
3
+ class UffizziCore::Deployment::CreateCredentialJob < UffizziCore::ApplicationJob
4
+ sidekiq_options queue: :deployments, retry: Settings.controller.resource_create_retry_count
5
+
6
+ sidekiq_retry_in do |count, exception|
7
+ case exception
8
+ when UffizziCore::DeploymentNotFoundError
9
+ Rails.logger.info("DEPLOYMENT_PROCESS CreateCredentialJob retry deployment_id=#{exception.deployment_id} count=#{count}")
10
+ Settings.controller.resource_create_retry_time
11
+ end
12
+ end
13
+
14
+ def perform(deployment_id, credential_id)
15
+ Rails.logger.info("DEPLOYMENT_PROCESS deployment_id=#{deployment_id} CreateCredentialJob(cred_id:#{credential_id})")
16
+
17
+ deployment = UffizziCore::Deployment.find(deployment_id)
18
+ credential = UffizziCore::Credential.find(credential_id)
19
+
20
+ if deployment.disabled?
21
+ Rails.logger.info("DEPLOYMENT_PROCESS deployment_id=#{deployment.id} deployment was disabled stop creating credential")
22
+ return
23
+ end
24
+
25
+ unless UffizziCore::ControllerService.deployment_exists?(deployment)
26
+ raise UffizziCore::DeploymentNotFoundError,
27
+ deployment_id
28
+ end
29
+
30
+ UffizziCore::ControllerService.apply_credential(deployment, credential)
31
+ end
32
+ end
@@ -0,0 +1,17 @@
1
+ # frozen_string_literal: true
2
+
3
+ class UffizziCore::Deployment::CreateCredentialsJob < UffizziCore::ApplicationJob
4
+ sidekiq_options queue: :deployments, retry: 5
5
+
6
+ def perform(deployment_id)
7
+ Rails.logger.info("DEPLOYMENT_PROCESS deployment_id=#{deployment_id} CreateCredentialsJob")
8
+
9
+ deployment = UffizziCore::Deployment.find(deployment_id)
10
+
11
+ credentials = deployment.project.account.credentials.deployable
12
+
13
+ credentials.each do |credential|
14
+ UffizziCore::Deployment::CreateCredentialJob.perform_async(deployment.id, credential.id)
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,15 @@
1
+ # frozen_string_literal: true
2
+
3
+ class UffizziCore::Deployment::CreateJob < UffizziCore::ApplicationJob
4
+ sidekiq_options queue: :deployments, retry: 5
5
+
6
+ def perform(id)
7
+ Rails.logger.info("DEPLOYMENT_PROCESS deployment_id=#{id} CreateJob")
8
+
9
+ deployment = UffizziCore::Deployment.find(id)
10
+
11
+ UffizziCore::ControllerService.create_deployment(deployment)
12
+
13
+ UffizziCore::Deployment::CreateCredentialsJob.perform_async(deployment.id)
14
+ end
15
+ end
@@ -0,0 +1,13 @@
1
+ # frozen_string_literal: true
2
+
3
+ class UffizziCore::Deployment::CreateWebhooksJob < UffizziCore::ApplicationJob
4
+ sidekiq_options queue: :deployments, retry: 5
5
+
6
+ def perform(id)
7
+ Rails.logger.info("DEPLOYMENT_PROCESS deployment_id=#{id} CreateWebhooksJob")
8
+
9
+ deployment = UffizziCore::Deployment.find(id)
10
+
11
+ UffizziCore::DeploymentService.create_webhooks(deployment)
12
+ end
13
+ end
@@ -0,0 +1,13 @@
1
+ # frozen_string_literal: true
2
+
3
+ class UffizziCore::Deployment::DeleteCredentialJob < UffizziCore::ApplicationJob
4
+ sidekiq_options queue: :deployments, retry: 5
5
+
6
+ def perform(deployment_id, credential_id)
7
+ Rails.logger.info("DEPLOYMENT_PROCESS deployment_id=#{deployment_id} DeleteCredentialJob(cred_id:#{credential_id})")
8
+
9
+ deployment = UffizziCore::Deployment.find(deployment_id)
10
+ credential = UffizziCore::Credential.find(credential_id)
11
+ UffizziCore::ControllerService.delete_credential(deployment, credential)
12
+ end
13
+ end
@@ -0,0 +1,11 @@
1
+ # frozen_string_literal: true
2
+
3
+ class UffizziCore::Deployment::DeleteJob < UffizziCore::ApplicationJob
4
+ sidekiq_options queue: :deployments, retry: 5
5
+
6
+ def perform(id)
7
+ Rails.logger.info("DEPLOYMENT_PROCESS deployment_id=#{id} DeleteJob")
8
+
9
+ UffizziCore::ControllerService.delete_deployment(id)
10
+ end
11
+ end
@@ -0,0 +1,27 @@
1
+ # frozen_string_literal: true
2
+
3
+ class UffizziCore::Deployment::DeployContainersJob < UffizziCore::ApplicationJob
4
+ sidekiq_options queue: :deployments, retry: Settings.controller.resource_create_retry_count
5
+
6
+ sidekiq_retry_in do |count, exception|
7
+ case exception
8
+ when UffizziCore::DeploymentNotFoundError
9
+ Rails.logger.info("DEPLOYMENT_PROCESS DeployContainersJob retry deployment_id=#{exception.deployment_id} count=#{count}")
10
+ Settings.controller.resource_create_retry_time
11
+ end
12
+ end
13
+
14
+ def perform(id, repeated = false)
15
+ Rails.logger.info("DEPLOYMENT_PROCESS deployment_id=#{id} DeployContainersJob")
16
+
17
+ deployment = UffizziCore::Deployment.find(id)
18
+ if deployment.disabled?
19
+ Rails.logger.info("DEPLOYMENT_PROCESS deployment_id=#{deployment.id} deployment was disabled stop deploying")
20
+ return
21
+ end
22
+
23
+ raise UffizziCore::DeploymentNotFoundError, id unless UffizziCore::ControllerService.deployment_exists?(deployment)
24
+
25
+ UffizziCore::DeploymentService.deploy_containers(deployment, repeated)
26
+ end
27
+ end
@@ -0,0 +1,38 @@
1
+ # frozen_string_literal: true
2
+
3
+ class UffizziCore::Deployment::ManageDeployActivityItemJob < UffizziCore::ApplicationJob
4
+ sidekiq_options queue: :deployments, retry: 3
5
+
6
+ sidekiq_retry_in do |count, exception|
7
+ case exception
8
+ when UffizziCore::Deployment::ImagePullError
9
+ Rails.logger.info("DEPLOYMENT_PROCESS ManageDeployActivityItemJob retry deployment_id=#{exception.deployment_id} count=#{count}")
10
+ 15.seconds
11
+ end
12
+ end
13
+
14
+ sidekiq_retries_exhausted do |msg, exception|
15
+ case exception
16
+ when UffizziCore::Deployment::ImagePullError
17
+ Rails.logger.info("DEPLOYMENT_PROCESS ManageDeployActivityItemJob exhausted #{msg.inspect} #{exception.inspect}")
18
+
19
+ activity_item_id = msg['args'].first
20
+ activity_item = UffizziCore::ActivityItem.find(activity_item_id)
21
+ UffizziCore::ActivityItemService.fail_deployment!(activity_item)
22
+ end
23
+ end
24
+
25
+ def perform(activity_item_id)
26
+ activity_item = UffizziCore::ActivityItem.find(activity_item_id)
27
+ container = activity_item.container
28
+
29
+ if container.disabled?
30
+ logger_message = "DEPLOYMENT_PROCESS deployment_id=#{container.deployment_id} activity_item_id=#{activity_item.id}
31
+ deployment was disabled stop monitoring"
32
+ Rails.logger.info(logger_message)
33
+ return
34
+ end
35
+
36
+ UffizziCore::ActivityItemService.manage_deploy_activity_item(activity_item)
37
+ end
38
+ end