Skip to content

fix(pkg/dockerfile): fix FROM in Dockerfile parsing issues#930

Merged
xunleii merged 1 commit intoradiofrance:mainfrom
xunleii:fix-dib-interpolation
Mar 30, 2026
Merged

fix(pkg/dockerfile): fix FROM in Dockerfile parsing issues#930
xunleii merged 1 commit intoradiofrance:mainfrom
xunleii:fix-dib-interpolation

Conversation

@xunleii
Copy link
Copy Markdown
Member

@xunleii xunleii commented Mar 27, 2026

This pull request improves the robustness of Dockerfile parsing in the pkg/dockerfile package by updating regular expressions to handle more Dockerfile syntax variations and adding new test cases to ensure correct parsing. The changes focus on better handling of whitespace, comments, and build stage aliases in FROM, LABEL, and ARG instructions.

Parsing improvements:

  • Updated the regular expressions in dockerfile.go to allow for optional whitespace and to better capture image references, tags, and digests in FROM instructions, as well as to handle LABEL and ARG instructions with more flexible spacing.

Test coverage enhancements:

  • Added new test cases in dockerfile_test.go to cover Dockerfiles with build stage aliases (AS keyword, including uppercase), inline comments in FROM instructions, and other edge cases.
  • Added fixture Dockerfiles: simple-AS.dockerfile for testing AS build stage parsing [1] and simple-comment.dockerfile for testing parsing of FROM instructions with comments. [2]

The previous regex used '$' to mark the end of the line, which made parsing too fragile.
Specifically, it failed when using 'AS' (uppercase) for multistage builds or when a comment was present at the end of the line.
Removing the '$' anchor and the explicit 'as' alias check allows for more robust parsing of the image reference.
New tests have been added to cover these cases (comments and different 'AS' casing).

Signed-off-by: Alexandre NICOLAIE <alexandre.nicolaie@radiofrance.com>
@xunleii xunleii requested a review from Copilot March 27, 2026 18:21
@xunleii xunleii marked this pull request as ready for review March 27, 2026 18:22
@xunleii xunleii requested a review from a team as a code owner March 27, 2026 18:22
@codecov
Copy link
Copy Markdown

codecov bot commented Mar 27, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 55.40%. Comparing base (8b82fe4) to head (7782653).
⚠️ Report is 2 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main     #930   +/-   ##
=======================================
  Coverage   55.40%   55.40%           
=======================================
  Files          55       55           
  Lines        3485     3485           
=======================================
  Hits         1931     1931           
  Misses       1430     1430           
  Partials      124      124           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Improves pkg/dockerfile parsing robustness for Dockerfile instructions (primarily FROM) by relaxing regex matching to support more real-world syntax like build stage aliases and inline comments, and adds fixtures/tests to validate these cases.

Changes:

  • Updated regexes in pkg/dockerfile/dockerfile.go to better handle whitespace and trailing content (e.g., AS aliases, comments).
  • Added new Dockerfile fixtures covering FROM ... AS ... and FROM ... # comment.
  • Expanded TestParseDockerfile with new cases for aliases and comments.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 3 comments.

File Description
pkg/dockerfile/dockerfile.go Updates regexes used to parse FROM, LABEL, and ARG lines.
pkg/dockerfile/dockerfile_test.go Adds test cases for AS (uppercase) and inline FROM comments; adds a multistage alias case.
test/fixtures/dockerfile/simple-AS.dockerfile New fixture for FROM ... AS builder.
test/fixtures/dockerfile/simple-comment.dockerfile New fixture for FROM ... # comment.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Copy link
Copy Markdown
Contributor

@antoinegelloz antoinegelloz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM 👌

@xunleii xunleii merged commit c172812 into radiofrance:main Mar 30, 2026
13 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants