fix(pkg/dockerfile): fix FROM in Dockerfile parsing issues#930
Merged
xunleii merged 1 commit intoradiofrance:mainfrom Mar 30, 2026
Merged
fix(pkg/dockerfile): fix FROM in Dockerfile parsing issues#930xunleii merged 1 commit intoradiofrance:mainfrom
xunleii merged 1 commit intoradiofrance:mainfrom
Conversation
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>
Codecov Report✅ All modified and coverable lines are covered by tests. 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. 🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
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.goto better handle whitespace and trailing content (e.g.,ASaliases, comments). - Added new Dockerfile fixtures covering
FROM ... AS ...andFROM ... # comment. - Expanded
TestParseDockerfilewith 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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This pull request improves the robustness of Dockerfile parsing in the
pkg/dockerfilepackage 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 inFROM,LABEL, andARGinstructions.Parsing improvements:
dockerfile.goto allow for optional whitespace and to better capture image references, tags, and digests inFROMinstructions, as well as to handleLABELandARGinstructions with more flexible spacing.Test coverage enhancements:
dockerfile_test.goto cover Dockerfiles with build stage aliases (ASkeyword, including uppercase), inline comments inFROMinstructions, and other edge cases.simple-AS.dockerfilefor testingASbuild stage parsing [1] andsimple-comment.dockerfilefor testing parsing ofFROMinstructions with comments. [2]