Skip to content

Commit

Permalink
Fix #123 Support the new --parents flag in COPY
Browse files Browse the repository at this point in the history
Support has been added for the new boolean --parents flag for COPY
instructions. This flag will now be recognized and will no longer be
identified as an error by the validator.

Signed-off-by: Remy Suen <remy.suen@gmail.com>
  • Loading branch information
rcjsuen committed Mar 25, 2024
1 parent 69280a6 commit c3e6693
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 3 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Expand Up @@ -4,6 +4,7 @@ All notable changes to this project will be documented in this file.
## [Unreleased]
### Added
- support parsing the new `--exclude` flag for ADD and COPY instructions ([#124](https://github.com/rcjsuen/dockerfile-utils/issues/124))
- support parsing the new `--parents` flag for COPY instructions ([#123](https://github.com/rcjsuen/dockerfile-utils/issues/123))

## [0.15.0] - 2023-09-10
### Added
Expand Down
6 changes: 3 additions & 3 deletions src/dockerValidator.ts
Expand Up @@ -723,12 +723,12 @@ export class Validator {
const flagRange = flag.getRange();
if (name === "") {
problems.push(Validator.createUnknownCopyFlag(copyInstructionRange.start.line, flagRange.start, flagRange.end, name));
} else if (name === "link") {
} else if (name === "link" || name === "parents") {
const problem = this.checkFlagBoolean(copyInstructionRange.start.line, flag);
if (problem !== null) {
problems.push(problem);
}
} else if (name !== "chmod" && name !== "chown" && name !== "from" && name !== "exclude") {
} else if (name !== "chmod" && name !== "chown" && name !== "from" && name !== "exclude" && name !== "parents") {
let range = flag.getNameRange();
problems.push(Validator.createUnknownCopyFlag(copyInstructionRange.start.line, flagRange.start, range.end, name));
}
Expand All @@ -751,7 +751,7 @@ export class Validator {
problems.push(copyDestinationDiagnostic);
}
this.checkFlagValue(copyInstructionRange.start.line, flags, ["chmod", "chown", "from", "exclude"], problems);
this.checkDuplicateFlags(copyInstructionRange.start.line, flags, ["chmod", "chown", "from", "link"], problems);
this.checkDuplicateFlags(copyInstructionRange.start.line, flags, ["chmod", "chown", "from", "link", "parents"], problems);
this.checkJSONQuotes(instruction, problems);
break;
case "WORKDIR":
Expand Down
40 changes: 40 additions & 0 deletions test/dockerValidator.test.ts
Expand Up @@ -2877,6 +2877,46 @@ describe("Docker Validator Tests", function() {
});
});

describe("parents", () => {
it("ok", () => {
let diagnostics = validateDockerfile("FROM alpine\nCOPY --parents=true . .");
assert.strictEqual(diagnostics.length, 0);

diagnostics = validateDockerfile("FROM alpine\nCOPY --parents=false . .");
assert.strictEqual(diagnostics.length, 0);

diagnostics = validateDockerfile("FROM alpine\nCOPY --parents=TrUE . .");
assert.strictEqual(diagnostics.length, 0);

diagnostics = validateDockerfile("FROM alpine\nCOPY --parents=fALSe . .");
assert.strictEqual(diagnostics.length, 0);
});

it("no value", () => {
const diagnostics = validateDockerfile("FROM alpine\nCOPY --parents . .");
assert.strictEqual(diagnostics.length, 0);
});

it("empty value", () => {
const diagnostics = validateDockerfile("FROM alpine\nCOPY --parents= . .");
assert.strictEqual(diagnostics.length, 1);
assertFlagMissingValue(diagnostics[0], 1, "parents", 1, 7, 1, 14);
});

it("invalid value", () => {
const diagnostics = validateDockerfile("FROM alpine\nCOPY --parents=abc . .");
assert.strictEqual(diagnostics.length, 1);
assertFlagExpectedBooleanValue(diagnostics[0], 1, "parents", "abc", 1, 15, 1, 18);
});

it("duplicate flag", () => {
const diagnostics = validateDockerfile("FROM alpine\nCOPY --parents=true --parents=false . .");
assert.strictEqual(diagnostics.length, 2);
assertFlagDuplicate(diagnostics[0], 1, "parents", 1, 7, 1, 14);
assertFlagDuplicate(diagnostics[1], 1, "parents", 1, 22, 1, 29);
});
});

it("all flags", function() {
let diagnostics = validateDockerfile("FROM node AS bb\nFROM alpine\nCOPY --from=bb --chown=node:node . .");
assert.equal(diagnostics.length, 0);
Expand Down

0 comments on commit c3e6693

Please sign in to comment.