`findBaseImage` in dockerfileUtils.ts does not handle buildkit automatic variables in layers name
Giving a simple Dockerfile example, leveraging the TARGETARCH automatic variable provided in the global scope by buildkit:
ARG APT_FLAGS="-y -qq --no-install-recommends --no-install-suggests"
FROM node AS base-arm64
ONBUILD ARG PACKAGES="\
build-essential \
python3 \
"
FROM node AS base-amd64
ONBUILD ARG PACKAGES=""
FROM base-${TARGETARCH} AS base
apt-get install ${APT_FLAGS} ${PACKAGES}
# do common stuff
The TARGETARCH global scope variable (Nor for that matter any others) does not seem available for replacement when searching the base image in the findBaseImage function called by internalGetImageBuildInfoFromDockerfile during the build
https://github.com/devcontainers/cli/blob/f3be29d61167bef3ca430bf106ea2fc203ae0f3b/src/spec-node/dockerfileUtils.ts#L95
in our case ending up returning the value base- which does not exist and then fails:
[1197 ms] Start: Run: docker inspect --type image base-
[3802 ms] Error fetching image details: No manifest found for docker.io/library/base-.
[3802 ms] Start: Run: docker pull base-
invalid reference format
[3903 ms] []
[3903 ms] Error response from daemon: no such image: base-: invalid reference format
Also, another issue I found along the way when inspecting available values, parsing does not handle quoted values (nor multilines). Based on the previous Dockerfile example, we end up in the provided replacements to replaceVariables function with:
// [...]
{ instruction: 'ARG', name: 'APT_FLAGS', value: '"-y' },
{ instruction: 'ARG', name: 'PACKAGES', value: '"\\' },
// [...]
@chrmarti Additionally, trying to find a workaround in the meantime, I just noticed that parsing of variables with replacements (ie. ${FOO:-bar}) does not work either.
With something like:
ARG ARCH=${TARGETARCH:-amd64}
# [...]
FROM base-${ARCH} AS base
# [...]
The CLI complains:
[63348916 ms] Start: Run: docker inspect --type image base-:-amd64}
[63351485 ms] Error fetching image details: No manifest found for docker.io/library/base-:-amd64}.
[63351485 ms] Start: Run: docker pull base-:-amd64}
invalid reference format
[63352081 ms] []
[63352081 ms] Error response from daemon: no such image: base-:-amd64}: invalid reference format
[63352081 ms] Command failed: docker inspect --type image base-:-amd64}