Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
chrmarti committed Nov 14, 2022
1 parent 6ebc652 commit a7f1799
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/spec-node/dockerfileUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ const findFromLines = new RegExp(/^(?<line>\s*FROM.*)/, 'gm');
const parseFromLine = /FROM\s+(?<platform>--platform=\S+\s+)?"?(?<image>[^\s"]+)"?(\s+[Aa][Ss]\s+(?<label>[^\s]+))?/;

const fromStatement = /^\s*FROM\s+(?<platform>--platform=\S+\s+)?"?(?<image>[^\s"]+)"?(\s+[Aa][Ss]\s+(?<label>[^\s]+))?/m;
const argEnvUserStatements = /^\s*(?<instruction>ARG|ENV|USER)\s+(?<name>[^\s=]+)(=("(?<value1>\S+)"|(?<value2>\S+)))?/gm;
const argEnvUserStatements = /^\s*(?<instruction>ARG|ENV|USER)\s+(?<name>[^\s=]+)([ =]+("(?<value1>\S+)"|(?<value2>\S+)))?/gm;
const directives = /^\s*#\s*(?<name>\S+)\s*=\s*(?<value>.+)/;
const variables = /\$\{?(?<variable>[a-zA-Z0-9_]+)\}?/g;

Expand Down
30 changes: 30 additions & 0 deletions src/test/dockerfileUtils.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -467,3 +467,33 @@ FROM debian`;
});
});
});

describe('extractDockerfile', () => {

it('handles ENV with equals', async () => {
const dockerfile = `FROM debian\nENV A=B`;
const extracted = extractDockerfile(dockerfile);
const env = extracted.stages[0].instructions[0];
assert.strictEqual(env.instruction, 'ENV');
assert.strictEqual(env.name, 'A');
assert.strictEqual(env.value, 'B');
});

it('handles ENV with equals and spaces', async () => {
const dockerfile = `FROM debian\nENV A = B`;
const extracted = extractDockerfile(dockerfile);
const env = extracted.stages[0].instructions[0];
assert.strictEqual(env.instruction, 'ENV');
assert.strictEqual(env.name, 'A');
assert.strictEqual(env.value, 'B');
});

it('handles ENV without equals', async () => {
const dockerfile = `FROM debian\nENV A B`;
const extracted = extractDockerfile(dockerfile);
const env = extracted.stages[0].instructions[0];
assert.strictEqual(env.instruction, 'ENV');
assert.strictEqual(env.name, 'A');
assert.strictEqual(env.value, 'B');
});
});

0 comments on commit a7f1799

Please sign in to comment.