Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

interpolation doesn't work in RUN #3301

Closed
jayunit100 opened this issue Nov 22, 2022 · 1 comment
Closed

interpolation doesn't work in RUN #3301

jayunit100 opened this issue Nov 22, 2022 · 1 comment

Comments

@jayunit100
Copy link

Run doesn't seem to like interpolation

If I run

ENV MOUNT_CMD=--mount=type=cache,target=blah
RUN $MOUNT_CMD go mod download

I get a error like

#14 0.404 /bin/sh: 1: --mount="type=cache,target=/root/.local/share/golang": not found

Its as if the "--mount..." isnt perceived as a RUN option.

Workaround? Maybe just mount the env var only, bc that is supported....

But mounting a option in workaround failed also...

ENV CACHE_GOBUILD=/root/.cache/go-build
ENV CACHE_GOLANG=/root/.local/share/golang
ENV CACHE_GOMOD=/go/pkg/mod

WORKDIR /workspace/tkr

RUN --mount=type=cache,target=$CACHE_GOBUILD go mod download

yields

failed to solve with frontend dockerfile.v0: failed to create LLB definition: dockerfile parse error line 49: invalid field '${CACHE_GOBUILD}' must be a key=value pair
@jedevc
Copy link
Member

jedevc commented Nov 22, 2022

We only support expanding the values inside the mount, not the keys, or a combination of the above (for more information, you might be interested in the PR that added the mount expansion functionality: #2089).

Only the arguments inside the cache-mount are evaluated using interpolation. Think of the order for parsing as parse instructions -> perform interpolation - there's not way of having the results of interpolation affect the parsing.

This is by design! 🎉 It's actually a massive pain to have interpolation affect parsing, since then you need quoting rules like in sh(/bash/dash/etc) to be able to have it not do that extra interpolation when your cache target might contain "special" characters like = or ,. The complexity of this really quickly spirals out of control, so we just don't support that.

If we want to allow programmatic usage of flags and similar, we'd probably lean towards doing something closer to #1209, instead of fundamentally changing how the Dockerfile is parsed.

@jedevc jedevc closed this as completed Nov 22, 2022
@jedevc jedevc closed this as not planned Won't fix, can't repro, duplicate, stale Nov 22, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants