Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(docker-compose): yaml parser option removeTemplates #31206

Merged
merged 8 commits into from
Sep 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
81 changes: 49 additions & 32 deletions lib/modules/manager/docker-compose/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 { extractPackageFile } from '.';

Expand Down Expand Up @@ -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
`,
Nemental marked this conversation as resolved.
Show resolved Hide resolved
'',
{
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: [
{
Expand All @@ -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: [
{
Expand All @@ -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: [
{
Expand All @@ -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',
},
],
});
});
});
});
1 change: 1 addition & 0 deletions lib/modules/manager/docker-compose/extract.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ export function extractPackageFile(
config = parseSingleYaml(content, {
json: true,
customSchema: DockerComposeFile,
removeTemplates: true,
});
} catch (err) {
logger.debug(
Expand Down