Bug 1759920 - `oc new-build` Fails If Inline Dockerfile Has Multiple Aliases
Summary: `oc new-build` Fails If Inline Dockerfile Has Multiple Aliases
Keywords:
Status: CLOSED ERRATA
Alias: None
Product: OpenShift Container Platform
Classification: Red Hat
Component: oc
Version: 3.11.0
Hardware: Unspecified
OS: Unspecified
high
medium
Target Milestone: ---
: 4.3.0
Assignee: Ricardo Maraschini
QA Contact: wewang
URL:
Whiteboard: devex
Depends On:
Blocks: 1770741
TreeView+ depends on / blocked
 
Reported: 2019-10-09 12:28 UTC by Abhishek
Modified: 2020-05-13 21:27 UTC (History)
10 users (show)

Fixed In Version:
Doc Type: If docs needed, set a value
Doc Text:
Clone Of:
: 1770741 (view as bug list)
Environment:
Last Closed: 2020-05-13 21:27:20 UTC
Target Upstream Version:
wewang: needinfo-


Attachments (Terms of Use)


Links
System ID Priority Status Summary Last Updated
Github openshift oc pull 136 'None' closed Bug 1759920: Fixed Dockerfile FROM statement parser. 2020-06-03 11:41:56 UTC
Red Hat Product Errata RHBA-2020:0062 None None None 2020-01-23 11:07:03 UTC

Description Abhishek 2019-10-09 12:28:33 UTC
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

Comment 2 Adam Kaplan 2019-10-15 15:23:08 UTC
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

Comment 3 Ricardo Maraschini 2019-10-30 16:29:50 UTC
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]$

Comment 11 wewang 2019-11-19 01:55:35 UTC
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

Comment 13 errata-xmlrpc 2020-05-13 21:27:20 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, 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


Note You need to log in before you can comment on or make changes to this bug.