Skip to content

Commit

Permalink
fix(docker): Skip lookup of dependencies with variable in image name (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
rv2673 committed Feb 2, 2022
1 parent 8070f00 commit 356fdcb
Show file tree
Hide file tree
Showing 4 changed files with 126 additions and 1 deletion.
48 changes: 48 additions & 0 deletions lib/manager/dockerfile/extract.spec.ts
Expand Up @@ -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",
}
`);
});
});
});
9 changes: 8 additions & 1 deletion lib/manager/dockerfile/extract.ts
Expand Up @@ -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',
Expand Down
17 changes: 17 additions & 0 deletions lib/manager/gitlabci/__fixtures__/gitlab-ci.7.yaml
@@ -0,0 +1,17 @@
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
53 changes: 53 additions & 0 deletions lib/manager/gitlabci/extract.spec.ts
Expand Up @@ -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 comments on commit 356fdcb

Please sign in to comment.