Bug 1843405

Summary: Dockerfile builds ignore preamble build args
Product: OpenShift Container Platform Reporter: OpenShift BugZilla Robot <openshift-bugzilla-robot>
Component: BuildAssignee: Nalin Dahyabhai <nalin>
Status: CLOSED ERRATA QA Contact: wewang <wewang>
Severity: medium Docs Contact:
Priority: unspecified    
Version: 4.4CC: adam.kaplan, aos-bugs, wzheng
Target Milestone: ---   
Target Release: 4.5.z   
Hardware: Unspecified   
OS: Unspecified   
Whiteboard:
Fixed In Version: Doc Type: Bug Fix
Doc Text:
Previously, if a Dockerfile used in Docker strategy builds used the ARG instruction to define build arguments before the first FROM instruction occurred in the Dockerfile, that instruction would be dropped when the Dockerfile was preprocessed to incorporate any overrides which might have been specified in the Build or BuildConfig. References to those arguments would subsequently not be resolved properly while building an image using the preprocessed Dockerfile. The preprocessing logic has been modified so that it preserves ARG instructions which are encountered before the first FROM instruction when generating the updated Dockerfile contents, so this problem should no longer occur.
Story Points: ---
Clone Of: Environment:
Last Closed: 2020-08-10 13:50:20 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: 1842982    
Bug Blocks:    

Description OpenShift BugZilla Robot 2020-06-03 09:02:39 UTC
+++ This bug was initially created as a clone of Bug #1842982 +++

Description of problem:

If a Dockerfile used in Docker strategy builds has build args that precede the first FROM statement, the build arg is dropped from the generated Dockerfile.


Version-Release number of selected component (if applicable): 4.4


How reproducible: Always


Steps to Reproduce:
1. Create a Docker strategy build with a BuildConfig that has ARG instructions that precede the first FROM statement:

```
apiVersion: build.openshift.io/v1
kind: BuildConfig
metadata:
  name: dropped-build-arg
spec:
  source:
    dockerfile: |-
      ARG foo=centos
      FROM registry.redhat.io/ubi8/ubi:latest
      RUN echo "hello from ubi!"
      FROM $foo
      RUN echo "hello from $foo"
    type: Dockerfile
  strategy:
    dockerStrategy: {}
    type: Docker

2. Start the build


Actual results:

Build will fail - no such image $foo

Expected results:

Build should succeed.


Additional info:

Comment 6 wewang 2020-07-30 03:09:12 UTC
Now latest payload is 4.5.0-0.nightly-2020-07-29-230326, should wait newer payload with the pr merged.

Comment 7 wewang 2020-07-31 00:37:21 UTC
Verified in version: 
4.5.0-0.nightly-2020-07-30-020337

Steps:
1. Create a bc:
```
apiVersion: build.openshift.io/v1
kind: BuildConfig
metadata:
  name: dropped-build-arg
spec:
  source:
    dockerfile: |-
      ARG foo=centos
      FROM registry.redhat.io/ubi8/ubi:latest
      RUN echo "hello from ubi!"
      FROM $foo
      RUN echo "hello from $foo"
    type: Dockerfile
  strategy:
    dockerStrategy: {}
    type: Docker
```
2. Start build with bc, build complete

Comment 9 errata-xmlrpc 2020-08-10 13:50: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 (OpenShift Container Platform 4.5.5 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:3188