Skip to content

Commit

Permalink
fix(manager/docker): accept key-only arguments in COPY --from (#31344)
Browse files Browse the repository at this point in the history
Co-authored-by: Michael Kriese <michael.kriese@visualon.de>
  • Loading branch information
mkniewallner and viceice committed Sep 12, 2024
1 parent 49faa29 commit 83132a5
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 1 deletion.
26 changes: 26 additions & 0 deletions lib/modules/manager/dockerfile/extract.spec.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { codeBlock } from 'common-tags';
import { Fixtures } from '../../../../test/fixtures';
import type { PackageDependency } from '../types';
import { extractVariables, getDep } from './extract';
Expand Down Expand Up @@ -395,6 +396,31 @@ describe('modules/manager/dockerfile/extract', () => {
]);
});

it('handles COPY --link --from', () => {
const res = extractPackageFile(
codeBlock`
FROM scratch
COPY --link --from=gcr.io/k8s-skaffold/skaffold:v0.11.0 /usr/bin/skaffold /usr/bin/skaffold
`,
'',
{},
);
expect(res).toEqual({
deps: [
{
autoReplaceStringTemplate:
'{{depName}}{{#if newValue}}:{{newValue}}{{/if}}{{#if newDigest}}@{{newDigest}}{{/if}}',
currentDigest: undefined,
currentValue: 'v0.11.0',
datasource: 'docker',
depName: 'gcr.io/k8s-skaffold/skaffold',
depType: 'final',
replaceString: 'gcr.io/k8s-skaffold/skaffold:v0.11.0',
},
],
});
});

it('skips named multistage COPY --from tags', () => {
const res = extractPackageFile(
'FROM node:6.12.3 as frontend\n\n# comment\nENV foo=bar\nCOPY --from=frontend /usr/bin/node /usr/bin/node\n',
Expand Down
2 changes: 1 addition & 1 deletion lib/modules/manager/dockerfile/extract.ts
Original file line number Diff line number Diff line change
Expand Up @@ -385,7 +385,7 @@ export function extractPackageFile(
const copyFromRegex = new RegExp(
'^[ \\t]*COPY(?:' +
escapeChar +
'[ \\t]*\\r?\\n| |\\t|#.*?\\r?\\n|--[a-z]+=[a-zA-Z0-9_.:-]+?)+--from=(?<image>\\S+)',
'[ \\t]*\\r?\\n| |\\t|#.*?\\r?\\n|--[a-z]+(?:=[a-zA-Z0-9_.:-]+?)?)+--from=(?<image>\\S+)',
'im',
); // TODO #12875 complex for re2 has too many not supported groups
const copyFromMatch = instruction.match(copyFromRegex);
Expand Down

0 comments on commit 83132a5

Please # to comment.