multi stage builds: Error: determining starting point for build: no FROM statement found
Trying to set the base image name using a build argument fails in 1.37.5 for multi stage builds. With buildah 1.33.6 this works as expected.
Example
ARG image_build
FROM $image_build as build
RUN echo foo >bar
ARG image_release
FROM $image_release
COPY --from=build bar bar
buildah bud --build-arg image_build=alpine:latest --build-arg image_release=alpine:3.20.3
[1/2] STEP 1/3: FROM alpine:latest AS build
[1/2] STEP 2/3: RUN echo foo >bar
[1/2] STEP 3/3: ARG image_release
Error: determining starting point for build: no FROM statement found
buildah --version
buildah version 1.37.5 (image-spec 1.1.0, runtime-spec 1.2.0)
To limit the bisect maybe a bit more: buildah v1.33.11 works fine too and 1.38.0 fails
A friendly reminder that this issue had no activity for 30 days.
I can reproduce this, I'll take a look at this. Thanks for reporting.
FROM instructions can only reference args declared in the header of the file, i.e., the part of the file before the first FROM.
Despite appearances from the use of whitespace in the quoted example, the ARG image_release line is treated as part of the first stage.
Move the ARG image_release line to be just after the ARG image_build line (before FROM $image_build as build) , and you should be all set.
@nalind Thanks for the explanation.
I just want to link the relevant part of the Dockerfile spec here which confirms your statement:
From https://docs.docker.com/reference/dockerfile/#understand-how-arg-and-from-interact
FROM instructions support variables that are declared by any ARG instructions that occur before the first FROM.
An ARG declared before a FROM is outside of a build stage, so it can't be used in any instruction after a FROM. To use the default value of an ARG declared before the first FROM use an ARG instruction without a value inside of a build stage:
I'm now using the --build-context flag instead of using build arguments to overwrite image references.
See also:
- https://www.mankier.com/1/buildah-build#--build-context
- https://docs.docker.com/reference/cli/docker/buildx/build/#build-context