docker / buildx

Docker CLI plugin for extended build capabilities with BuildKit
Apache License 2.0
3.52k stars 473 forks source link

Lowercase error when using automatic platform args in stage names #1812

Open agirault opened 1 year ago

agirault commented 1 year ago

Contributing guidelines

I've found a bug and checked that ...

Description

Using TARGETARCH or other automatic platform args in the global scope in a stage name will result in an error due to it not being lowercase

Expected behaviour

${TARGETARCH} should be resolved to arm64 or amd64 resulting in a valid lowercase stage. The build should succeed and copy from the adequate stage, given behavior changes between both archs (basically if/else in dockerfile)

Actual behaviour

ERROR: failed to solve: failed to parse stage name "foo-${TARGETARCH}": invalid reference format: repository name must be lowercase

Buildx version

github.com/docker/buildx v0.10.4 c513d34

Builders list

NAME/NODE                DRIVER/ENDPOINT             STATUS   BUILDKIT PLATFORMS
multiarch                docker-container                              
  multiarch0             unix:///var/run/docker.sock inactive          linux/arm64*, linux/amd64*
default *                docker                                        
  default                default                     running  23.0.6   linux/amd64, linux/amd64/v2, linux/amd64/v3, linux/amd64/v4, linux/arm64, linux/riscv64, linux/ppc64le, linux/s390x, linux/386, linux/mips64le, linux/mips64, linux/arm/v7, linux/arm/v6

Configuration

# syntax=docker/dockerfile:1

ARG BASE=ubuntu:20.04

FROM ${BASE} AS test-arm64
RUN echo "I am arm64" > /opt/who

FROM ${BASE} AS test-amd64
RUN echo "I am amd64" > /opt/who

FROM ${BASE} AS final
ARG TARGETARCH
COPY --from=test-${TARGETARCH} /opt/who /opt/who
RUN cat /opt/who
agirault commented 1 year ago

Found a workaround by using a additional dummy stage:

# syntax=docker/dockerfile:1

ARG BASE=ubuntu:20.04

FROM ${BASE} AS test-arm64
RUN echo "I am arm64" > /opt/who

FROM ${BASE} AS test-amd64
RUN echo "I am amd64" > /opt/who

FROM test-${TARGETARCH} AS test

FROM ${BASE} AS final
COPY --from=test /opt/who /opt/who
RUN cat /opt/who