diff --git a/lib/modules/manager/docker-compose/extract.spec.ts b/lib/modules/manager/docker-compose/extract.spec.ts index 01a4caf31c9d80..b9436050d88ae1 100644 --- a/lib/modules/manager/docker-compose/extract.spec.ts +++ b/lib/modules/manager/docker-compose/extract.spec.ts @@ -1,3 +1,4 @@ +import { codeBlock } from 'common-tags'; import { Fixtures } from '../../../../test/fixtures'; import { extractPackageFile } from '.'; @@ -56,20 +57,17 @@ describe('modules/manager/docker-compose/extract', () => { }); it('extracts image and replaces registry', () => { - const res = extractPackageFile( - ` - version: "3" - services: - nginx: - image: quay.io/nginx:0.0.1 - `, - '', - { - registryAliases: { - 'quay.io': 'my-quay-mirror.registry.com', - }, + const compose = codeBlock` + version: "3" + services: + nginx: + image: quay.io/nginx:0.0.1 + `; + const res = extractPackageFile(compose, '', { + registryAliases: { + 'quay.io': 'my-quay-mirror.registry.com', }, - ); + }); expect(res).toEqual({ deps: [ { @@ -86,20 +84,17 @@ describe('modules/manager/docker-compose/extract', () => { }); it('extracts image but no replacement', () => { - const res = extractPackageFile( - ` + const compose = codeBlock` version: "3" services: nginx: image: quay.io/nginx:0.0.1 - `, - '', - { - registryAliases: { - 'index.docker.io': 'my-docker-mirror.registry.com', - }, + `; + const res = extractPackageFile(compose, '', { + registryAliases: { + 'index.docker.io': 'my-docker-mirror.registry.com', }, - ); + }); expect(res).toEqual({ deps: [ { @@ -116,21 +111,18 @@ describe('modules/manager/docker-compose/extract', () => { }); it('extracts image and no double replacement', () => { - const res = extractPackageFile( - ` + const compose = codeBlock` version: "3" services: nginx: image: quay.io/nginx:0.0.1 - `, - '', - { - registryAliases: { - 'quay.io': 'my-quay-mirror.registry.com', - 'my-quay-mirror.registry.com': 'quay.io', - }, + `; + const res = extractPackageFile(compose, '', { + registryAliases: { + 'quay.io': 'my-quay-mirror.registry.com', + 'my-quay-mirror.registry.com': 'quay.io', }, - ); + }); expect(res).toEqual({ deps: [ { @@ -145,5 +137,30 @@ describe('modules/manager/docker-compose/extract', () => { ], }); }); + + it('extracts image of templated compose file', () => { + const compose = codeBlock` + version: "3" + services: + nginx: + image: quay.io/nginx:0.0.1 + envrionment: + {{ services['nginx']['env'] }} + `; + const res = extractPackageFile(compose, '', {}); + expect(res).toEqual({ + deps: [ + { + autoReplaceStringTemplate: + '{{depName}}{{#if newValue}}:{{newValue}}{{/if}}{{#if newDigest}}@{{newDigest}}{{/if}}', + currentDigest: undefined, + currentValue: '0.0.1', + datasource: 'docker', + depName: 'quay.io/nginx', + replaceString: 'quay.io/nginx:0.0.1', + }, + ], + }); + }); }); }); diff --git a/lib/modules/manager/docker-compose/extract.ts b/lib/modules/manager/docker-compose/extract.ts index 255d47ae7d35a9..f685323a959086 100644 --- a/lib/modules/manager/docker-compose/extract.ts +++ b/lib/modules/manager/docker-compose/extract.ts @@ -39,6 +39,7 @@ export function extractPackageFile( config = parseSingleYaml(content, { json: true, customSchema: DockerComposeFile, + removeTemplates: true, }); } catch (err) { logger.debug(