Description of problem: Not able to achieve multi-stage build in Openshift 3.11 # oc new-build -D $'FROM golang:alpine AS builder\nENV alertmanager_version v0.15.3\nFROM alpine:latest\nENTRYPOINT ["/bin/alertmanager"]' --> Found Docker image 9617696 (6 weeks old) from Docker Hub for "alpine:latest" * An image stream tag will be created as "alpine:latest" that will track the source image * A Docker build using a predefined Dockerfile will be created * The resulting image will be pushed to image stream tag "alpine:latest" * Every time "alpine:latest" changes a new build will be triggered error: output image of "alpine:latest" should be different than input, set a different tag with --to
There are two issues here: 1. `oc new-build` created a new imagestream tag that referenced and tracked `docker.io/alpine:latest`. Pushing back to this imagestream tag is not allowed, hence the original error message. 2. Failures using multiple FROM aliases in a multistage dockerfile is a known issue in 3.11. Multistage dockerfile builds are tech preview for this version [1] - in 4.1 multistage dockerfiles should work. Using chained builds is a recommended workaround if a multistage dockerfile build does not work [2]. That said, there appears to be a bug in `new-build` processing a multistage dockerfile with multiple aliases. In 4.1.20 I get the following error: ``` $ oc new-build -D $'FROM golang:alpine AS builder\nENV alertmanager_version v0.15.3\nFROM alpine:latest AS runner\nENTRYPOINT ["/bin/alertmanager"]' --to test-multi:latest error: unable to locate any images in image streams, local docker images with name "runner" The 'oc new-build' command will match arguments to the following types: 1. Images tagged into image streams in the current project or the 'openshift' project - if you don't specify a tag, we'll add ':latest' 2. Images in the Docker Hub, on remote registries, or on the local Docker engine 3. Git repository URLs or local paths that point to Git repositories --allow-missing-images can be used to force the use of an image that was not matched See 'oc new-build -h' for examples. ``` [1] https://docs.openshift.com/container-platform/3.11/release_notes/ocp_3_11_release_notes.html#ocp-311-technology-preview [2] https://docs.openshift.com/container-platform/3.11/dev_guide/builds/advanced_build_operations.html#dev-guide-chaining-builds
Seems like the problem affects other Dockerfiles with no multi-stage as well: [rmarasch@localhost k]$ oc new-build -D 'FROM fedora\nENTRYPOINT ["/bin/echo", "hello"]' --to test:latest error: unable to locate any images in image streams, local docker images with name "\"hello\"]" The 'oc new-build' command will match arguments to the following types: 1. Images tagged into image streams in the current project or the 'openshift' project - if you don't specify a tag, we'll add ':latest' 2. Images in the Docker Hub, on remote registries, or on the local Docker engine 3. Git repository URLs or local paths that point to Git repositories --allow-missing-images can be used to force the use of an image that was not matched See 'oc new-build -h' for examples. [rmarasch@localhost k]$
Thanks Ricardo Maraschini, verified in version: Client Version: v4.3.0 Server Version: 4.3.0-0.nightly-2019-11-18-175710 Kubernetes Version: v1.16.2 steps: [wewang@Desktop Downloads]$ oc new-build -D $'FROM golang:alpine AS builder\nENV alertmanager_version v0.15.3\nFROM alpine:latest\nENTRYPOINT ["/bin/alertmanager"]' --to=< bash: syntax error near unexpected token `newline' [wewang@Desktop Downloads]$ oc new-build -D $'FROM golang:alpine AS builder\nENV alertmanager_version v0.15.3\nFROM alpine:latest\nENTRYPOINT ["/bin/alertmanager"]' --to=test --> Found container image 965ea09 (4 weeks old) from Docker Hub for "alpine:latest" * An image stream tag will be created as "alpine:latest" that will track the source image * A Docker build using a predefined Dockerfile will be created * The resulting image will be pushed to image stream tag "test:latest" * Every time "alpine:latest" changes a new build will be triggered --> Creating resources with label build=test ... imagestream.image.openshift.io "alpine" created imagestream.image.openshift.io "test" created buildconfig.build.openshift.io "test" created --> Success [wewang@Desktop Downloads]$ oc get builds NAME TYPE FROM STATUS STARTED DURATION test-1 Docker Dockerfile Pending [wewang@Desktop Downloads]$ oc get builds NAME TYPE FROM STATUS STARTED DURATION test-1 Docker Dockerfile Complete About a minute ago 59s
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, 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:0062