Skip to content

Validates and scans Catalog Resource for components

Laura Montemayor requested to merge create-service-scan-catalog-resources into master

What does this MR do and why?

A summary of the changes, since this is a lengthy MR:

  • The service names were updated to follow convention
  • Extracts duplicate knowledge from InstancePath into the new Ci::ComponentsProject, which is responsible for retrieving content and paths. This will serve as our SSOT for the constants as well.
  • Adds a check in Ci::Catalog::Resource::ValidateService to scan the project marked as a catalog resource for valid components.
  • Creates Ci::Catalog::Resources::Version::CreateService
  • Creates the Ci::Catalog::Resources::ReleaseService , which is used in the Releases::CreateService . This service simply calls the Ci::Catalog::Resources::ValidateService and Ci::Catalog::Resources::Version::CreateService when a release is valid.

How to set up and validate locally

1. Mark a project as a catalog resource:

Settings -> General -> Visibility, project features, permissions -> CI/CD Catalog resource

2. Create a templates directory and two components:

  1. a simple component: templates/name-of-component.yml
  2. a complex component: templates/directory-name/template.yml

3. Create a release

4.Check for the records in the console:

> Ci::Catalog::Resources::Version.last

You should have a record for the version:
=> #<Ci::Catalog::Resources::Version:0x000000016d727f90 id: 3, release_id: 32, catalog_resource_id: 13, project_id: 21, created_at: Tue, 12 Sep 2023 14:33:35.417982000 UTC +00:00>

> Ci::Catalog::Resources::Comopnents.all

And two records for the components:

=> [#<Ci::Catalog::Resources::Component:0x000000016f8cea68 id: 1, catalog_resource_id: 13, version_id: 3, project_id: 21, created_at: Tue, 12 Sep 2023 14:33:35.516879000 UTC +00:00, resource_type: "template", inputs: {}, name: "secret-detection">, #<Ci::Catalog::Resources::Component:0x000000016f92c078 id: 2, catalog_resource_id: 13, version_id: 3, project_id: 21, created_at: Tue, 12 Sep 2023 14:33:35.539745000 UTC +00:00, resource_type: "template", inputs: {}, name: "dast">]

5.Verify that the catalog resources state is published:

=> #<Ci::Catalog::Resource:0x00000002804f43e0 id: 13, project_id: 21, created_at: Thu, 24 Aug 2023 11:52:39.353194000 UTC +00:00, state: "published">

Database query

explain UPDATE FROM "catalog_resource_versions" WHERE "catalog_resource_versions"."id" = 1

Looks good

Time: 17.556 ms  
  - planning: 0.519 ms  
  - execution: 17.037 ms  
    - I/O read: 16.600 ms  
    - I/O write: 0.000 ms  
  
Shared buffers:  
  - hits: 15 (~120.00 KiB) from the buffer pool  
  - reads: 6 (~48.00 KiB) from the OS file cache, including disk I/O  
  - dirtied: 1 (~8.00 KiB)  
  - writes: 0  

Details and visualizations

MR acceptance checklist

This checklist encourages us to confirm any changes have been analyzed to reduce risks in quality, performance, reliability, security, and maintainability.

#415413 (closed)

Edited by Laura Montemayor

Merge request reports