Bug 1802202

Summary: Dockerfile ARG values not handled properly in multistage builds
Product: OpenShift Container Platform Reporter: Adam Kaplan <adam.kaplan>
Component: BuildAssignee: Gabe Montero <gmontero>
Status: CLOSED DUPLICATE QA Contact: wewang <wewang>
Severity: medium Docs Contact:
Priority: unspecified    
Version: 4.4CC: aos-bugs, gmontero, wzheng
Target Milestone: ---   
Target Release: 4.5.0   
Hardware: Unspecified   
OS: Unspecified   
Whiteboard:
Fixed In Version: Doc Type: If docs needed, set a value
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: 2020-03-13 16:50:46 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: 1801875, 1839683    
Bug Blocks:    

Description Adam Kaplan 2020-02-12 15:05:09 UTC
Splitting out from Bug #1801388

If a multi-stage Dockerfile utilizes build ARGS in FROM statements, these are not correctly processed by buildah.

Steps to Reproduce:

1. Create a BuildConfig as follows:
```
apiVersion: build.openshift.io/v1
kind: BuildConfig
metadata:
  name: sample-build-docker-args-preset
spec:
  source:
    dockerfile: |-
      FROM centos
      ARG foo=centos
      FROM $foo
    type: Dockerfile
  strategy:
    dockerStrategy: {}
    type: Docker
```
2. Start the build

Actual Results:

Build fails with error:
```
I0211 22:06:43.140914       1 builder.go:318] Starting Docker build from build config sample-build-docker-args-preset-17 ...
F0211 22:06:43.209605       1 helpers.go:114] error: build error: error parsing name "$foo": error parsing image name "$foo": invalid reference format
```

Expected results:

Build succeeds

Additional Info:

https://github.com/openshift/builder/pull/130#discussion_r377979342

Comment 1 Gabe Montero 2020-02-12 15:10:58 UTC
I've added a dependency link to https://bugzilla.redhat.com/show_bug.cgi?id=1801875 because at the moment, based on the discussion between Ben, Nalin, and myself, we think
the buildah api's should handle the above scenario without any translations in openshift/builder

Nalin is investigating.

Based on his outcome, we can use this bug to either
a) bump buildah to get the fix
b) make the openshift/builer (via imagebuilder) translations when mutating the Dockerfile before it is passed to buildah

But again, at the moment, option a) is considered the correct approach.

Comment 2 Gabe Montero 2020-02-17 20:12:49 UTC
As this is a tracking bug to react to https://bugzilla.redhat.com/show_bug.cgi?id=1801875 I'm moving this to POST, at least for now.

Comment 3 Gabe Montero 2020-03-13 16:50:46 UTC
As the originator of https://bugzilla.redhat.com/show_bug.cgi?id=1801875 I'll see if/when it progresses and can open any bugs to update openshift/builder buildah dependencies as needed

closing this tracking bug

Comment 4 Adam Kaplan 2020-05-26 12:39:50 UTC

*** This bug has been marked as a duplicate of bug 1839683 ***