renovate icon indicating copy to clipboard operation
renovate copied to clipboard

Support GitLab CI/CD components

Open secustor opened this issue 1 year ago • 12 comments

Discussed in https://github.com/renovatebot/renovate/discussions/23424

Originally posted by fgreinacher July 18, 2023

Tell us more.

CI/CD components are a new way to reuse CI logic within GitLab, see upstream documentation.

They look very similar to other includes and can probably be implemented in the existing gitlabci-include datasource.

include:
  - component: gitlab.com/gitlab-org/[email protected]

secustor avatar Jul 18 '23 15:07 secustor

this should be added to the gitlabci manager, as the gitlab-include manager will be merged to it

viceice avatar Jul 18 '23 17:07 viceice

I started having a look at this. I think with the current syntax it might be challenging to implement: https://gitlab.com/groups/gitlab-org/-/epics/9897#note_1494759770.

fgreinacher avatar Aug 01 '23 06:08 fgreinacher

Does the directory structure update in 16.3 make the project/component distinction firm enough to move forward? Reference Merge Request.

thompson-shaun avatar Aug 31 '23 13:08 thompson-shaun

Does someone maybe already have a working (read: tested) custom manager for this which could be used in the meantime?

mbrodala avatar Nov 20 '23 09:11 mbrodala

I'm researching about GitLab CI/CD components. I'm curious about why the include syntax is challenging. My understanding about:

include:
   - component: $CI_SERVER_HOST/$CI_PROJECT_PATH/$EXAMPLE@$REF

where:

  • $CI_SERVER_HOST points to GitLab instance, i.e. gitlab.com
  • $CI_PROJECT_PATH points to namespace within domain, i.e. iaigz/gitlab-ci
  • $EXAMPLE references to component name - i.e. lint-yaml-files
  • $REF references to repository history - tag, branch, or commit sha

Within the component definitions themselves, the YAML syntax is the usual Gitlab CI syntax, preceded with more YAML front-matter. any other gitlabci-include can contain that spec: syntax too, up from GitLab 16.x, as it's usable from include:local

---
spec:
  inputs:
    job-stage:
      default: test
    search-path:
      default: .
    search-name:
      default: Dockerfile
---
lint-dockerfiles:
  image: hadolint/hadolint:v2.12.0-alpine
  stage: $[[ inputs.job-stage ]]
  script:
    - hadolint --version
    - find $[[ inputs.search-path ]] -type f -name $[[ inputs.search-name ]]
      -exec hadolint
      '{}'
      \+

The key part seems matching for the - component: <host><repo><depName>@<version> pattern. Note that version can't be specific to one component within the repository, but the same to every component for any given git reference

lorenzogrv avatar Dec 02 '23 04:12 lorenzogrv

I'm curious about why the include syntax is challenging.

@lorenzogrv In previous iterations this syntax supported components in a any subdirectory, making it impossible to extract the project path from the reference.

Your understanding is correct and it should be doable now.

fgreinacher avatar Dec 05 '23 22:12 fgreinacher

@lorenzogrv @mbrodala Here is my custom manager for cicd components:

{
  "customType": "regex",
  "fileMatch": [
      "\\.gitlab-ci\\.ya?ml$",
      "templates/.+\\.ya?ml$"
  ],
  "versioningTemplate": "semver",
  "datasourceTemplate": "gitlab-releases",
  "registryUrlTemplate": "https://{{{registryUrl}}}",
  "depTypeTemplate": "repository",
  "matchStrings": [
    "component: (?<registryUrl>[^\\s\\/]+)\\/(?<depName>\\S+)\\/[^\\s\\/]+@(?<currentValue>\\S+)"
  ]
}

benedikt-bartscher avatar Dec 08 '23 02:12 benedikt-bartscher

@benedikt-bartscher Thanks, seems to work just fine! :+1:

I only noticed that gitlab-releases are slow to pick up updates, so one may consider using gitlab-tags as datasourceTemplate instead.

mbrodala avatar Dec 11 '23 08:12 mbrodala

@mbrodala you are welcome. That's interesting, i will investigate why gitlab-releases is slower later this evening. Do you still get release notes in your renovate MRs with gitlab-tags as datasource?

benedikt-bartscher avatar Dec 11 '23 15:12 benedikt-bartscher

Yes, this works just fine. Renovate retrieves release notes separately from the specific data source AFAIK.

mbrodala avatar Dec 12 '23 07:12 mbrodala

@benedikt-bartscher Works like a charm, thanks for sharing. I used gitlab-tags as suggested by @mbrodala and release notes are actually included within MRs.

lorenzogrv avatar Dec 13 '23 02:12 lorenzogrv

Finally, thanks @fgreinacher !

mbrodala avatar Jan 24 '24 07:01 mbrodala