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,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ class UffizziCore::Api::Cli::V1::Projects::SecretSerializer < UffizziCore::BaseSerializer
4
+ attributes :name, :created_at, :updated_at
5
+ end
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ class UffizziCore::Api::Cli::V1::ShortProjectSerializer < UffizziCore::BaseSerializer
4
+ type :project
5
+
6
+ attributes :name, :slug
7
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ class UffizziCore::Api::Cli::V1::UserSerializer::AccountSerializer < UffizziCore::BaseSerializer
4
+ attributes :id, :state
5
+ end
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ class UffizziCore::Api::Cli::V1::UserSerializer < UffizziCore::BaseSerializer
4
+ type :user
5
+
6
+ has_many :accounts
7
+ end
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ class UffizziCore::BaseSerializer < ActiveModel::Serializer
4
+ def anonymize(field)
5
+ '*' * field.length
6
+ end
7
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ class UffizziCore::Controller::ApplyConfigFile::ConfigFileSerializer < UffizziCore::BaseSerializer
4
+ attributes :id, :filename, :kind, :payload
5
+ end
@@ -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,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ class UffizziCore::Controller::CreateDeployment::DeploymentSerializer < UffizziCore::BaseSerializer
4
+ attributes :kind
5
+ 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,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ class UffizziCore::Controller::DeployContainers::ContainerSerializer::ContainerConfigFileSerializer < UffizziCore::BaseSerializer
4
+ attributes :mount_path
5
+
6
+ belongs_to :config_file
7
+ 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,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ class UffizziCore::Controller::DeployContainers::CredentialSerializer < UffizziCore::BaseSerializer
4
+ attributes :id
5
+ 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