Bug 1845345

Summary: Unable to build multi-stage image that has a --from=X that matches FROM X
Product: OpenShift Container Platform Reporter: Clayton Coleman <ccoleman>
Component: BuildAssignee: Adam Kaplan <adam.kaplan>
Status: CLOSED ERRATA QA Contact: wewang <wewang>
Severity: high Docs Contact:
Priority: unspecified    
Version: 4.5CC: adam.kaplan, aos-bugs, dwalsh, ealcaniz, erich, gmontero, jokerman, tsweeney, wjiang, wzheng
Target Milestone: ---   
Target Release: 4.5.z   
Hardware: Unspecified   
OS: Unspecified   
Whiteboard:
Fixed In Version: Doc Type: If docs needed, set a value
Doc Text:
Story Points: ---
Clone Of: 1843232 Environment:
Last Closed: 2020-08-17 20:05:19 UTC Type: ---
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:
Embargoed:
Bug Depends On: 1844596    
Bug Blocks:    

Description Clayton Coleman 2020-06-08 23:58:30 UTC
+++ This bug was initially created as a clone of Bug #1843232 +++

One of our tests is a multistage build

FROM scratch as test
USER 1001
FROM %[1]s
COPY --from=test /usr/bin/curl /test/
COPY --from=%[1]s /bin/echo /test/
COPY --from=%[1]s /bin/ping /test/

where %[1]s is "image-registry.openshift-image-registry.svc:5000/openshift/tools:latest"

This fails with 

STEP 5: COPY --from=image-registry.openshift-image-registry.svc:5000/openshift/tools:latest /bin/echo /test/
error: build error: error building at STEP "COPY --from=image-registry.openshift-image-registry.svc:5000/openshift/tools:latest /bin/echo /test/": the stage "image-registry.openshift-image-registry.svc:5000/openshift/tools:latest" has not been built

which is not correct. --from implies image OR stage by name.  I tried to run


FROM scratch as test
USER 1001
FROM %[1]s as other
COPY --from=test /usr/bin/curl /test/
COPY --from=%[1]s /bin/echo /test/
COPY --from=%[1]s /bin/ping /test/

and it still failed.

There was an attempted fix in https://github.com/containers/buildah/pull/2321, but it either didn't make it into 4.5/master or may not cover the whole problem.

Marked as 4.5, this needs to be fixed and backported potentially to 4.4.

--- Additional comment from Adam Kaplan on 2020-06-03 13:59:18 EDT ---

Targeting 4.6.0 - this is not a release blocker. Per Clayton's note, backport is requested to 4.5.z and 4.4.z

--- Additional comment from Adam Kaplan on 2020-06-05 14:00:55 EDT ---

This did not make it to 4.5/master - this merged in buildah master, but is not available in a v1.14.z stream. Openshift/builder currently uses buildah v1.14.2 [1].

Moving this to the Containers team so that we get this backported to buildah v1.14.z, and cloning to ensure this gets into builds.

[1] https://github.com/openshift/builder/blob/release-4.5/go.mod

Comment 1 Tom Sweeney 2020-07-02 20:07:19 UTC
Upstream PR at:  https://github.com/containers/buildah/pull/2401  working on the vendoring into openshift/builder which is proving problematic.

Comment 6 wewang 2020-08-07 04:13:03 UTC
Verified in version:
4.5.0-0.nightly-2020-08-06-215703

Steps:
1. Using Dockerfile as follow to build,build complete
```
FROM docker.io/library/busybox AS build
RUN rm -f /bin/paste
USER 1001
COPY --from=docker.io/library/busybox /bin/paste /test/
```

2. Using Dockerfile as follow to build,build complete
```
FROM docker.io/library/busybox AS test
RUN rm -f /bin/nl
FROM docker.io/library/alpine AS final
COPY --from=docker.io/library/busybox /bin/nl /test/
```

3. Using Dockerfile as follow to build,build failed
```
FROM busybox AS test
USER 1001
FROM busybox AS build
COPY --from=test /bin/cut /test/
COPY --from=build /bin/cp /test/
COPY --from=busybox /bin/paste /test/
```
[root@wangwen work]# oc logs -f build/test-3
STEP 3: FROM busybox AS build
STEP 4: COPY --from=test /bin/cut /test/
STEP 5: COPY --from=build /bin/cp /test/
error: build error: COPY --from=build: no stage or image found with that name

Comment 8 errata-xmlrpc 2020-08-17 20:05:19 UTC
Since the problem described in this bug report should be
resolved in a recent advisory, it has been closed with a
resolution of ERRATA.

For information on the advisory (OpenShift Container Platform 4.5.6 bug fix update), and where to find the updated
files, follow the link below.

If the solution does not work for you, open a new bug report.

https://access.redhat.com/errata/RHBA-2020:3330