moby / buildkit

concurrent, cache-efficient, and Dockerfile-agnostic builder toolkit
https://github.com/moby/moby/issues/34227
Apache License 2.0
8.26k stars 1.17k forks source link

Support copying from an image defined with an ARG in the local scope #2412

Open umarcor opened 3 years ago

umarcor commented 3 years ago

It would be desirable to support copying content from an image using a variable/argument for specifying the image name. For instance:

ARG REGISTRY='docker.io/hdlc'

FROM $REGISTRY/build:build AS build

COPY --from=$REGISTRY/pkg:icestorm /icestorm/usr/local/share/icebox /usr/local/share/icebox

or

# syntax=docker/dockerfile:1.2

ARG REGISTRY='docker.io/hdlc'

FROM $REGISTRY/build:build AS build

RUN --mount=type=cache,from=$REGISTRY/pkg:icestorm,src=/icestorm/usr/local/share/icebox,target=/usr/local/share/icebox \
...

Refs:

tonistiigi commented 3 years ago

https://github.com/moby/buildkit/issues/2034#issuecomment-805445957 is the recommended method for achieving this.

--from supports ARG but only the ones in the global scope.

umarcor commented 3 years ago

#2034 (comment) is the recommended method for achieving this.

That is a workaround for an unsupported feature, not a solution to the feature request; hence, the creation of this issue.

--from supports ARG but only the ones in the global scope.

Can you please provide an example? I tried four variants (lowercase and uppercase) but all of them are failing:

failed to solve with frontend dockerfile.v0: failed to create LLB definition: failed to parse stage name "$REGISTRY/pkg/icestorm": invalid reference format: repository name must be lowercase
failed to solve with frontend dockerfile.v0: failed to create LLB definition: failed to parse stage name "$registry/pkg/icestorm": invalid reference format
failed to solve with frontend dockerfile.v0: failed to solve with frontend gateway.v0: rpc error: code = Unknown desc = failed to create LLB definition: failed to parse stage name "$REGISTRY/pkg:icestorm": invalid reference format: repository name must be lowercase
failed to solve with frontend dockerfile.v0: failed to solve with frontend gateway.v0: rpc error: code = Unknown desc = failed to create LLB definition: failed to parse stage name "$registry/pkg:icestorm": invalid reference format
tonistiigi commented 3 years ago

Can you please provide an example?

The example on the link is what I meant. You can't write the $ARG directly in the flag because then the arg would be in local (stage) scope that isn't supported. Therefore you need to get it through an extra FROM command that gives you access to the args in the global scope.

tonistiigi commented 3 years ago

PSA: If anyone wants to take this on then please confirm the design here first as there are some tricky cases to consider.

umarcor commented 3 years ago

You can't write the $ARG directly in the flag because then the arg would be in local (stage) scope that isn't supported.

I updated the title of issue to specify that the feature request is supporting the usage of local args, such as:

ARG REGISTRY='docker.io/hdlc'

FROM $REGISTRY/build:build AS build

ARG REGISTRY

COPY --from=$REGISTRY/pkg:icestorm /icestorm/usr/local/share/icebox /usr/local/share/icebox