Skip to content
Snippets Groups Projects
Unverified Commit 356fdcb3 authored by Richard Versteeg's avatar Richard Versteeg Committed by GitHub
Browse files

fix(docker): Skip lookup of dependencies with variable in image name (#13951)

parent 8070f007
No related branches found
No related tags found
No related merge requests found
......@@ -665,5 +665,53 @@ Object {
}
`);
});
it('skips depName containing a non default variable at start', () => {
const res = getDep('$CI_REGISTRY/alpine:3.15');
expect(res).toMatchInlineSnapshot(`
Object {
"autoReplaceStringTemplate": "{{depName}}{{#if newValue}}:{{newValue}}{{/if}}{{#if newDigest}}@{{newDigest}}{{/if}}",
"datasource": "docker",
"replaceString": "$CI_REGISTRY/alpine:3.15",
"skipReason": "contains-variable",
}
`);
});
it('skips depName containing a non default variable with brackets at start', () => {
const res = getDep('${CI_REGISTRY}/alpine:3.15');
expect(res).toMatchInlineSnapshot(`
Object {
"autoReplaceStringTemplate": "{{depName}}{{#if newValue}}:{{newValue}}{{/if}}{{#if newDigest}}@{{newDigest}}{{/if}}",
"datasource": "docker",
"replaceString": "\${CI_REGISTRY}/alpine:3.15",
"skipReason": "contains-variable",
}
`);
});
it('skips depName containing a non default variable', () => {
const res = getDep('docker.io/$PREFIX/alpine:3.15');
expect(res).toMatchInlineSnapshot(`
Object {
"autoReplaceStringTemplate": "{{depName}}{{#if newValue}}:{{newValue}}{{/if}}{{#if newDigest}}@{{newDigest}}{{/if}}",
"datasource": "docker",
"replaceString": "docker.io/$PREFIX/alpine:3.15",
"skipReason": "contains-variable",
}
`);
});
it('skips depName containing a non default variable with brackets', () => {
const res = getDep('docker.io/${PREFIX}/alpine:3.15');
expect(res).toMatchInlineSnapshot(`
Object {
"autoReplaceStringTemplate": "{{depName}}{{#if newValue}}:{{newValue}}{{/if}}{{#if newDigest}}@{{newDigest}}{{/if}}",
"datasource": "docker",
"replaceString": "docker.io/\${PREFIX}/alpine:3.15",
"skipReason": "contains-variable",
}
`);
});
});
});
......@@ -56,7 +56,14 @@ export function splitImageParts(currentFrom: string): PackageDependency {
depName = depTagSplit.join(':');
}
if (currentValue && currentValue.indexOf(variableMarker) !== -1) {
if (depName?.includes(variableMarker)) {
// If depName contains a variable, after cleaning, e.g. "$REGISTRY/alpine", we currently not support this.
return {
skipReason: 'contains-variable',
};
}
if (currentValue?.includes(variableMarker)) {
// If tag contains a variable, e.g. "5.0${VERSION_SUFFIX}", we do not support this.
return {
skipReason: 'contains-variable',
......
image:
# comment
name: $VARIABLE/renovate/renovate:31.65.1-slim
services:
# comment
- name: $VARIABLE/other/image1:1.0.0
alias: imagealias1
# comment
- name: ${VARIABLE}/other/image1:2.0.0
alias: imagealias2
# comment
- name: docker.io/$VARIABLE/image1:3.0.0
alias: imagealias1
# comment
- name: docker.io/${VARIABLE}/image1:4.0.0
alias: imagealias2
......@@ -101,5 +101,58 @@ describe('manager/gitlabci/extract', () => {
expect(res).toBeNull();
expect(logger.logger.warn).toHaveBeenCalled();
});
it('skips images with variables', async () => {
const res = await extractAllPackageFiles(config, [
'lib/manager/gitlabci/__fixtures__/gitlab-ci.7.yaml',
]);
expect(res).toEqual([
{
deps: [
{
autoReplaceStringTemplate:
'{{depName}}{{#if newValue}}:{{newValue}}{{/if}}{{#if newDigest}}@{{newDigest}}{{/if}}',
datasource: 'docker',
depType: 'image-name',
replaceString: '$VARIABLE/renovate/renovate:31.65.1-slim',
skipReason: 'contains-variable',
},
{
autoReplaceStringTemplate:
'{{depName}}{{#if newValue}}:{{newValue}}{{/if}}{{#if newDigest}}@{{newDigest}}{{/if}}',
datasource: 'docker',
depType: 'service-image',
replaceString: '$VARIABLE/other/image1:1.0.0',
skipReason: 'contains-variable',
},
{
autoReplaceStringTemplate:
'{{depName}}{{#if newValue}}:{{newValue}}{{/if}}{{#if newDigest}}@{{newDigest}}{{/if}}',
datasource: 'docker',
depType: 'service-image',
replaceString: '${VARIABLE}/other/image1:2.0.0',
skipReason: 'contains-variable',
},
{
autoReplaceStringTemplate:
'{{depName}}{{#if newValue}}:{{newValue}}{{/if}}{{#if newDigest}}@{{newDigest}}{{/if}}',
datasource: 'docker',
depType: 'service-image',
replaceString: 'docker.io/$VARIABLE/image1:3.0.0',
skipReason: 'contains-variable',
},
{
autoReplaceStringTemplate:
'{{depName}}{{#if newValue}}:{{newValue}}{{/if}}{{#if newDigest}}@{{newDigest}}{{/if}}',
datasource: 'docker',
depType: 'service-image',
replaceString: 'docker.io/${VARIABLE}/image1:4.0.0',
skipReason: 'contains-variable',
},
],
packageFile: 'lib/manager/gitlabci/__fixtures__/gitlab-ci.7.yaml',
},
]);
});
});
});
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment