Skip to content

Commit

Permalink
extend gitlabci parser to support services images (#71)
Browse files Browse the repository at this point in the history
Gitlab allows users to run multiple containers within a container with
the services feature: https://docs.gitlab.com/ee/ci/services/

This pull request extends the gitlabci parser to find all of the images
withing a services: definition.
  • Loading branch information
nschnarr authored Apr 8, 2024
1 parent 4c953fb commit f0773aa
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 1 deletion.
16 changes: 16 additions & 0 deletions parser/gitlabci.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,22 @@ func (c *GitLabCI) parseOne(refs *RefsList, m *yaml.Node) error {

ref := resolver.NormalizeContainerRef(imageRef.Value)
refs.Add(ref, imageRef)
} else if property.Value == "services" {
node := job.Content[k+1]
for _, service := range node.Content {
if service.Kind == yaml.MappingNode {
for j, nameRef := range service.Content {
if nameRef.Value == "name" {
imageRef = service.Content[j+1]
break
}
}
} else {
imageRef = service
}
ref := resolver.NormalizeContainerRef(imageRef.Value)
refs.Add(ref, imageRef)
}
}
}
}
Expand Down
42 changes: 41 additions & 1 deletion parser/gitlabci_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,8 +96,48 @@ job2:
"container://python",
},
},
}
{
name: "jobs_with_services",
in: `
.test:base:
stage: test
image: python
retry:
max: 1
variables:
VAR1: true
script:
- test command
job:
extends:
- .test:base
image: node:12
services:
- postgres:14.3
- docker:24.0.5-dind
- name: selenium/standalone-firefox:latest
alias: firefox
stage: test
script:
- test command
job2:
image: gcr.io/project/image:tag
stage: test
script:
- test command
`,
exp: []string{
"container://docker:24.0.5-dind",
"container://gcr.io/project/image:tag",
"container://node:12",
"container://postgres:14.3",
"container://python",
"container://selenium/standalone-firefox:latest",
},
},
}
for _, tc := range cases {
tc := tc

Expand Down

0 comments on commit f0773aa

Please sign in to comment.