Add function to resolve variables in image references
This release adds a new function to resolve variable substitutions in image references.
For example, given this Dockerfile:
ARG IMAGE=alpine
ARG TAG=3.12
FROM ${IMAGE}:${TAG}
... previously the image would be parsed as:
ImageRef { registry: None, image: "${IMAGE}", tag: Some("${TAG}"), hash: None }
...which is obviously unhelpful. This default behavior remains unchanged, however the new function ImageRef::resolve_vars(&self, &Dockerfile)
can be called to resolve these variable references when possible:
let d = Dockerfile::parse(indoc!(r#"
ARG image=alpine
ARG unnecessarily_nested=${image}
ARG tag=3.12
FROM ${unnecessarily_nested}:${tag}
"#)).unwrap();
let from: &FromInstruction = d.instructions
.get(3).unwrap()
.try_into().unwrap();
assert_eq!(
from.image_parsed.resolve_vars(&d),
Some(ImageRef::parse("alpine:3.12"))
);
Note that this adds dependencies on regex
and lazy_static
.