`RUN` is formatted as POSIX shell after `SHELL` switches to PowerShell or cmd

Đang mở
#72 0 bình luận 0 reaction 0 người được giao Xem trên GitHub

Chưa có ai nhận issue này.

Đánh giá

Độ khó
3/5
Thời gian dự kiến
1-2 ngày
Mức phù hợp với người mới
72/100
Loại issue
Lỗi
Độ rõ ràng
Đặc tả rõ ràng
Mức độ hoạt động
Sôi nổi
Công nghệ
docker, go
Lĩnh vực
tooling

Hướng nghiên cứu

Start by tracing how dockerfmt parses and formats shell-form RUN, CMD, and ENTRYPOINT instructions, then follow how the Dockerfile SHELL instruction is represented and used. Reproduce with the PowerShell example in the issue and inspect existing formatter tests. Done means shell-form bodies remain unchanged after a non-POSIX SHELL instruction, with tests covering the reported panic and unwanted rewriting.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

RUN commands are always parsed and formatted as POSIX shell, even after a SHELL instruction switches to PowerShell or cmd. Depending on the command, dockerfmt either panics or silently rewrites it using shell quoting rules.

Reproduce
FROM mcr.microsoft.com/powershell
SHELL ["pwsh", "-Command"]
RUN if ($true) { Write-Host hi }
dockerfmt Dockerfile
Actual

Exit code 2:

Error parsing: if ($true) { Write-Host hi }
panic: 1:12: statements must be separated by &, ; or a newline

A command that happens to parse as shell gets rewritten instead:

SHELL ["pwsh", "-Command"]
RUN Get-ChildItem -Path C:\ | Select-Object Name

becomes

RUN Get-ChildItem -Path C:\  | Select-Object Name

because shell reads \ as an escaped space.

Expected

After a SHELL instruction that selects a non-POSIX shell, leave the shell-form RUN, CMD and ENTRYPOINT bodies untouched. That is the usual setup for Windows images.

Reproduced with v0.5.4 and with main at a5868c2.

Ngôn ngữ chính
Go
Star
626
Fork
23
Merge trung bình
6 ngày 23 giờ
Pull request đã merge (30 ngày)
3

Chuẩn bị môi trường

Dự án này không cung cấp dev container, Dockerfile hay hướng dẫn đóng góp, nên bạn cần tự thiết lập môi trường: hãy bắt đầu từ README và xem hướng dẫn đóng góp lần đầu của chúng tôi để biết các bước chung.

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của reteps/dockerfmt

Tất cả issue của reteps/dockerfmt

Issue tương tự

Thêm issue về Go

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.