Skip to content
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
5 changes: 5 additions & 0 deletions .changeset/fix-from-copy-option-parsing.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@docker-doctor/cli": patch
---

Fix `FROM` and `COPY`/`ADD` instruction parsing in rules to correctly skip option flags (e.g. `--platform`, `--chown`), preventing false-positive diagnostics or layer ordering check failures.
5 changes: 3 additions & 2 deletions packages/core/src/rules/image-size.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,9 @@ export const preferSlimBase: DockerfileRule = {

for (const inst of instructions) {
if (inst.instruction === "FROM") {
const [imagePart] = inst.args.split(/\s+/u);
if (imagePart === "scratch") {
const parts = inst.args.split(/\s+/u);
const imagePart = parts.find((p) => !p.startsWith("--"));
if (!imagePart || imagePart === "scratch") {
continue;
}

Expand Down
7 changes: 5 additions & 2 deletions packages/core/src/rules/performance.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,11 @@ export const orderLayers: DockerfileRule = {
for (const inst of instructions) {
if (inst.instruction === "COPY" || inst.instruction === "ADD") {
const parts = inst.args.split(/\s+/u);
// If copying the current directory (e.g., COPY . .)
const [src] = parts;
const src = parts.find((p) => !p.startsWith("--"));

if (!src) {
continue;
}

if (
(src === "." || src === "./" || src === "*" || src.includes("src")) &&
Expand Down
4 changes: 2 additions & 2 deletions packages/core/src/rules/security.ts
Original file line number Diff line number Diff line change
Expand Up @@ -113,9 +113,9 @@ export const pinImageVersion: DockerfileRule = {
// FROM image or FROM image:tag or FROM image@sha256:hash
// Also respect multi-stage builds (AS stageName)
const parts = inst.args.split(/\s+/u);
const [imagePart] = parts;
const imagePart = parts.find((p) => !p.startsWith("--"));

if (imagePart === "scratch") {
if (!imagePart || imagePart === "scratch") {
continue;
}

Expand Down
Loading