Skip to content

Add `resolve_vars_with_context` to find variable names in an image

Compare
Choose a tag to compare
@timothyb89 timothyb89 released this 19 Oct 20:05
· 31 commits to master since this release
87f2970

Building on v0.6.0's ImageRef::resolve_vars(&self, &dockerfile), this adds an additional function, ImageRef::resolve_vars_with_context(&self &dockerfile), to additionally return a HashSet of all variables referenced (both directly and indirectly) in the image string.

Additionally, Stage::arg_index(&self, &str) was added to determine if a given stage references a particular ARG, and if so, after which instruction index it becomes available to other instructions within that stage. As the Dockerfile's scoping rules require build stages to redefine all ARGs, the presence of a duplicate ARG instruction should reliably indicate whether or not a build stage actually used a given ARG outside of its FROM.

These two functions can be used together to help determine if a particular ARG is actually used within a given Dockerfile or if a parameterized image string can be automatically replaced with its variable-free equivalent.