Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support GitLab CI/CD components #23431

Closed
secustor opened this issue Jul 18, 2023 Discussed in #23424 · 13 comments · Fixed by #26660
Closed

Support GitLab CI/CD components #23431

secustor opened this issue Jul 18, 2023 Discussed in #23424 · 13 comments · Fixed by #26660
Labels
manager:gitlabci GitLab CI config files priority-3-medium Default priority, "should be done" but isn't prioritised ahead of others type:feature Feature (new functionality)

Comments

@secustor
Copy link
Collaborator

Discussed in #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/ruby-test@1.0
@secustor secustor added type:feature Feature (new functionality) priority-3-medium Default priority, "should be done" but isn't prioritised ahead of others manager:gitlabci GitLab CI config files status:ready labels Jul 18, 2023
@viceice
Copy link
Member

viceice commented Jul 18, 2023

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

@fgreinacher
Copy link
Contributor

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.

@thompson-shaun
Copy link

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

@mbrodala
Copy link
Contributor

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

@lorenzogrv
Copy link

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
Copy link

@fgreinacher
Copy link
Contributor

fgreinacher commented Dec 5, 2023

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.

@benedikt-bartscher
Copy link

benedikt-bartscher commented Dec 8, 2023

@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+)"
  ]
}

@mbrodala
Copy link
Contributor

mbrodala commented Dec 11, 2023

@benedikt-bartscher Thanks, seems to work just fine! 👍

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

@benedikt-bartscher
Copy link

@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?

@mbrodala
Copy link
Contributor

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

@lorenzogrv
Copy link

@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.

@mbrodala
Copy link
Contributor

Finally, thanks @fgreinacher !

mbrodala added a commit to pagemachine/renovate-config that referenced this issue Jan 24, 2024
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Feb 24, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
manager:gitlabci GitLab CI config files priority-3-medium Default priority, "should be done" but isn't prioritised ahead of others type:feature Feature (new functionality)
Projects
None yet
Development

Successfully merging a pull request may close this issue.

8 participants