containerbuildsystem/dockerfile-parse

ARGs are not handled in FROM instruction

Closed this issue · 6 comments

I have the following Dockerfile (https://docs.docker.com/v17.09/engine/reference/builder/#understand-how-arg-and-from-interact):

ARG PYTHON_VERSION
FROM python:${PYTHON_VERSION}

When trying to parse it with this library:

>>> parser = dockerfile_parse.DockerfileParser('Dockerfile')
>>> parser.parent_images
['python:${PYTHON_VERSION}']

What I expected:

  • build_args constructor argument (similar to parent_env)
  • args to be expanded in parent_images

I think there are two causes:

  • we only handle ENV variables, not ARG variables
  • we only perform variable expansion for ENV and LABEL instructions

Would you be able to have a go at contributing support for this?

👋 I don't think this is solvable before build time. Per the Dockerfile reference ARG is evaluated at build time based on what you pass to docker build --build-args. In this case ${PYTHON_VERSION} is only known at build time. Maybe if you gave the tool both the Dockerfile and the build command, it can do the appropriate substitution.

@nishakm
I'd substitute only defined ARG in dockerfile, eventually we can add extra param build_args to related methods.

@MartinBasti sounds good. Is anyone working on this? I can submit a PR if that's OK.

Feel free to submit PR :)