Top level ARG support
Closed this issue · 6 comments
The ARG
parameter comes in two shapes. Either it is declared after a FROM statement, and has its scope limited to that stage, or it is declared before any FROM statement, and then it will be global. Because dockerfile-x can interleave the content of several files, some ARG
may migrate from top level to stage scope. The answer here is to move every ARG which is local in a single file to the top of the resulting Dockerfile.
I think I understand (tell me if it's not), you can handle this by putting ARG on top on root Dockerfile before any include, so this will let the possibility to globalize an ARG or not
I cannot move the ARG to the top root Dockerfile because that root Dockerfile may be used as the root for different projects, and the ARG would make sense only in one of those projects. In other words, that breaks the include mechanism goal of serving as a way to model common dependencies.
OK, understood, thanks for your feedback
I think the problem is what if there are default ARG in one local stage and another default for same named ARG in another stage, what should be the global default, eg:
FROM debian AS builder
ARG FOO=BAR
FROM debian AS server
ARG FOO=BAZ
but I see nothing that is opposed to redeclare the ARG key globally, eg
ARG FOO
FROM debian AS builder
ARG FOO=BAR
FROM debian AS server
ARG FOO=BAZ
I will implement this
I think this fix is causing #16
the approach was not good and caused a regression: #16
the new approach is to only get ARG on top if the ARG is on top of the included Dockerfile (before FROM) and when the Dockerfile is included using FROM
or --from
, not INCLUDE
(to let it agnostic of this).
Example:
# syntax = devthefuture/dockerfile-x
FROM ubuntu.dockerfile
ubuntu.dockerfile
ARG UBUNTU_VERSION=22.04
FROM ubuntu:$UBUNTU_VERSION