Skip to content

findBaseImage in dockerfileUtils.ts does not handle buildkit automatic variables in layers name #275

@sylver

Description

@sylver

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

export function findBaseImage(dockerfile: Dockerfile, buildArgs: Record<string, string>, target: string | undefined) {

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: '"\\' },
  // [...]

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions