Skip to content

Commit

Permalink
fix: include docker ARG format without curly brackets
Browse files Browse the repository at this point in the history
Signed-off-by: Ilona Shishov <[email protected]>
  • Loading branch information
IlonaShishov committed Apr 16, 2024
1 parent 7fe2333 commit dafed0b
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
3 changes: 2 additions & 1 deletion src/providers/docker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,8 @@ export class ImageProvider implements IImageProvider {
* @private
*/
private replaceArgsInString(imageData: string): string {
return imageData.replace(/\${([^{}]+)}/g, (match, key) => {
return imageData.replace(/(\$\{([^{}]+)\}|\$([^{}]+))/g, (match, fullMatch, key1, key2) => {
const key = key1 || key2;
const value = this.args.get(key) || '';
return value;
});
Expand Down
9 changes: 7 additions & 2 deletions test/providers/docker.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -190,13 +190,18 @@ FROM --platform=linux/amd64 alpine@sha256:c5b1261d6d3e43071626931fc004f70149baeb
const deps = await dependencyProvider.collect(`
ARG ARG_IMAGE=python
ARG ARG_TAG=3.9.5
FROM --platform=linux/amd64 \${ARG_IMAGE}:\${ARG_TAG} as stage1\${ARG_FAKE}
FROM --platform=linux/amd64 \${ARG_IMAGE}:\${ARG_TAG} as stage1\$ARG_FAKE
FROM \$ARG_IMAGE
`);
expect(deps).is.eql([
{
name: {value: 'python:3.9.5', position: {line: 4, column: 0}},
line: 'FROM --platform=linux/amd64 ${ARG_IMAGE}:${ARG_TAG} as stage1${ARG_FAKE}',
line: 'FROM --platform=linux/amd64 ${ARG_IMAGE}:${ARG_TAG} as stage1$ARG_FAKE',
platform: 'linux/amd64'
},
{
name: {value: 'python', position: {line: 5, column: 0}},
line: 'FROM $ARG_IMAGE',
}
]);
});
Expand Down

0 comments on commit dafed0b

Please sign in to comment.