From 47dfc835b164d95c62d717d9439802a2d4e8889b Mon Sep 17 00:00:00 2001 From: Michael Kriese Date: Mon, 30 Aug 2021 18:37:46 +0200 Subject: [PATCH] fix(manager:dockerfile): wrong replace with trimmed images (#11485) --- .../__snapshots__/extract.spec.ts.snap | 16 ++++++++++++++++ lib/manager/dockerfile/extract.spec.ts | 14 ++++++++++++++ lib/manager/dockerfile/extract.ts | 4 ++++ .../droneci/__snapshots__/extract.spec.ts.snap | 2 +- 4 files changed, 35 insertions(+), 1 deletion(-) diff --git a/lib/manager/dockerfile/__snapshots__/extract.spec.ts.snap b/lib/manager/dockerfile/__snapshots__/extract.spec.ts.snap index 41e944805da20c..0abb636aec22c8 100644 --- a/lib/manager/dockerfile/__snapshots__/extract.spec.ts.snap +++ b/lib/manager/dockerfile/__snapshots__/extract.spec.ts.snap @@ -346,6 +346,22 @@ Array [ ] `; +exports[`manager/dockerfile/extract extractPackageFile() handles prefixes 1`] = ` +Array [ + Object { + "autoReplaceStringTemplate": "{{lookupName}}{{#if newValue}}:{{newValue}}{{/if}}{{#if newDigest}}@{{newDigest}}{{/if}}", + "currentDigest": undefined, + "currentValue": "18.04", + "datasource": "docker", + "depName": "ubuntu", + "depType": "final", + "lookupName": "amd64/ubuntu", + "replaceString": "amd64/ubuntu:18.04", + "versioning": "ubuntu", + }, +] +`; + exports[`manager/dockerfile/extract extractPackageFile() handles quay hosts with port 1`] = ` Object { "autoReplaceStringTemplate": "{{lookupName}}{{#if newValue}}:{{newValue}}{{/if}}{{#if newDigest}}@{{newDigest}}{{/if}}", diff --git a/lib/manager/dockerfile/extract.spec.ts b/lib/manager/dockerfile/extract.spec.ts index 896745048dfb3b..1e64e85dd7fc8a 100644 --- a/lib/manager/dockerfile/extract.spec.ts +++ b/lib/manager/dockerfile/extract.spec.ts @@ -265,6 +265,20 @@ describe('manager/dockerfile/extract', () => { }, ]); }); + + it('handles prefixes', () => { + const res = extractPackageFile('FROM amd64/ubuntu:18.04\n').deps; + expect(res).toMatchSnapshot([ + { + currentValue: '18.04', + depName: 'ubuntu', + lookupName: 'amd64/ubuntu', + versioning: 'ubuntu', + autoReplaceStringTemplate: + '{{lookupName}}{{#if newValue}}:{{newValue}}{{/if}}{{#if newDigest}}@{{newDigest}}{{/if}}', + }, + ]); + }); }); describe('getDep()', () => { it('rejects null', () => { diff --git a/lib/manager/dockerfile/extract.ts b/lib/manager/dockerfile/extract.ts index a21cf10f9d16a8..4a0b6f11ec3f75 100644 --- a/lib/manager/dockerfile/extract.ts +++ b/lib/manager/dockerfile/extract.ts @@ -58,6 +58,10 @@ export function getDep( if (dep.depName.startsWith(`${prefix}/`)) { dep.lookupName = dep.depName; dep.depName = dep.depName.replace(`${prefix}/`, ''); + if (specifyReplaceString) { + dep.autoReplaceStringTemplate = + '{{lookupName}}{{#if newValue}}:{{newValue}}{{/if}}{{#if newDigest}}@{{newDigest}}{{/if}}'; + } } } } diff --git a/lib/manager/droneci/__snapshots__/extract.spec.ts.snap b/lib/manager/droneci/__snapshots__/extract.spec.ts.snap index 0ed8a05d30d5d5..a7fe8577091daa 100644 --- a/lib/manager/droneci/__snapshots__/extract.spec.ts.snap +++ b/lib/manager/droneci/__snapshots__/extract.spec.ts.snap @@ -12,7 +12,7 @@ Array [ "replaceString": "elixir:1.8.1-alpine", }, Object { - "autoReplaceStringTemplate": "{{depName}}{{#if newValue}}:{{newValue}}{{/if}}{{#if newDigest}}@{{newDigest}}{{/if}}", + "autoReplaceStringTemplate": "{{lookupName}}{{#if newValue}}:{{newValue}}{{/if}}{{#if newDigest}}@{{newDigest}}{{/if}}", "currentDigest": "sha256:36adc17e9cceab32179d3314da9cb9c737ffb11f0de4e688f407ad6d9ca32201", "currentValue": "10.0.0", "datasource": "docker",