balena-io / balena-cli

The official balena CLI tool.
Apache License 2.0
455 stars 142 forks source link

Named buiid stages are treated as not supporting multiarch #2370

Open klutchell opened 3 years ago

klutchell commented 3 years ago

Expected Behavior

When the FROM target is a named build stage and not a registry image we should exclude it from the multiarch checks.

Actual Behavior

When the FROM target is a named build stage and not a registry image we disable architecture selection.

Steps to Reproduce the Problem

Create a Dockerfile where one build stage is based on another build stage.

This is uncommon usage as why bother with multiple stages in this format? The only real answer is that sometimes it's convenient to use docker build . --target build.

FROM alpine AS build
RUN echo "Build stage"
FROM build
RUN echo "Run stage based on build stage"
balena deploy --build myOrg/myFleet -e
[Warn]      Multi-stage Dockerfile found with a mix of base images that require
[Warn]      CPU architecture selection and base images that do not support it.
[Warn]      The following base images do not support CPU architecture selection:
[Warn]      - build
[Warn]      The following base images require CPU architecture selection:
[Warn]      - alpine

Specifications

pdcastro commented 3 years ago

Ha. Indeed, despite considering multistage dockerfiles during the multiarch implementation, somehow I think we assumed that the FROM line would always be pointing to an image from a registry with an inspectable manifest. I had myself only tested references to previous stages in a COPY instruction, for example:

https://github.com/balena-io-modules/balena-multibuild/pull/96#discussion_r711400335

FROM balenalib/%%BALENA_MACHINE_NAME%%-node as base
FROM --platform=linux/arm/v7 busybox as base2
FROM --platform=linux/arm/v7 debian:10
COPY --from=base /usr/local/bin/node /tmp/node
COPY --from=base2 /bin/busybox /tmp/busybox
CMD ["/bin/bash"]

"What is the essential nature of build in FROM build?" I suppose it is a reference to an image that only exists in the Docker Engine local cache. cc: @toochevere

Btw @klutchell, I assume it was typo where the Dockerfile reads FROM builder instead of FROM build. Right?

klutchell commented 3 years ago

Yes, typo fixed. It was an example I typed very quickly and not the actual file where I reproduced the issue.