From 83132a534eca83c2b4bf699d6b1386a4da9d6245 Mon Sep 17 00:00:00 2001 From: Mathieu Kniewallner Date: Thu, 12 Sep 2024 13:29:23 +0200 Subject: [PATCH] fix(manager/docker): accept key-only arguments in `COPY --from` (#31344) Co-authored-by: Michael Kriese --- .../manager/dockerfile/extract.spec.ts | 26 +++++++++++++++++++ lib/modules/manager/dockerfile/extract.ts | 2 +- 2 files changed, 27 insertions(+), 1 deletion(-) diff --git a/lib/modules/manager/dockerfile/extract.spec.ts b/lib/modules/manager/dockerfile/extract.spec.ts index b7934f840b663e..ce1faec854d533 100644 --- a/lib/modules/manager/dockerfile/extract.spec.ts +++ b/lib/modules/manager/dockerfile/extract.spec.ts @@ -1,3 +1,4 @@ +import { codeBlock } from 'common-tags'; import { Fixtures } from '../../../../test/fixtures'; import type { PackageDependency } from '../types'; import { extractVariables, getDep } from './extract'; @@ -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', diff --git a/lib/modules/manager/dockerfile/extract.ts b/lib/modules/manager/dockerfile/extract.ts index 53dd5550248558..1395dbcc1e57cb 100644 --- a/lib/modules/manager/dockerfile/extract.ts +++ b/lib/modules/manager/dockerfile/extract.ts @@ -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=(?\\S+)', + '[ \\t]*\\r?\\n| |\\t|#.*?\\r?\\n|--[a-z]+(?:=[a-zA-Z0-9_.:-]+?)?)+--from=(?\\S+)', 'im', ); // TODO #12875 complex for re2 has too many not supported groups const copyFromMatch = instruction.match(copyFromRegex);