Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow --build-arg to override FROM in Dockerfile #2404

Closed
nnachefski opened this issue Jun 13, 2020 · 23 comments
Closed

Allow --build-arg to override FROM in Dockerfile #2404

nnachefski opened this issue Jun 13, 2020 · 23 comments
Assignees
Labels
In Progress This issue is actively being worked by the assignee, please do not work on this at this time. kind/bug Categorizes issue or PR as related to a bug. locked - please file new issue/PR

Comments

@nnachefski
Copy link

I would like to be able to over override the FROM image in the Dockerfile from the command line

Example:

# buildah bud --build-arg=FROM=ubi8-custom --format=oci --tls-verify=false --layers -f Dockerfile.rhel8 -t image-registry.openshift-image-registry.svc:5000/custom-images/s2i-custom-core .
STEP 1: FROM registry.access.redhat.com/ubi8:latest
...
@rhatdan
Copy link
Member

rhatdan commented Jun 15, 2020

Interested in opening a PR to make this happen?

@nnachefski nnachefski changed the title Allow --build-args to override FROM in Dockerfile Allow --build-arg to override FROM in Dockerfile Jun 15, 2020
@nnachefski
Copy link
Author

negative. My Golang is.... nonexistent. I saw that Kaniko does indeed have this functionality. I'm going to give the kaniko ClusterTask a shot.

@rhatdan
Copy link
Member

rhatdan commented Jun 15, 2020

No problem, we will take a look at it.

@jamescassell
Copy link
Contributor

You can already do this:
test.Dockerfile:

ARG FROM=registry.access.redhat.com/ubi8
FROM $FROM
ARG FROM
ENV FROM=$FROM

to swap out the FROM, build it like podman build --build-arg=FROM=registry.fedoraproject.org/fedora -f from.Dockerfile

@rhatdan
Copy link
Member

rhatdan commented Jun 19, 2020

Also we have a preprocessor built into Buildah and Podman build. Basically you can add

if

then

endif

man buildah bud
...
      Dockerfiles  ending  with  a  ".in"  suffix  will  be preprocessed via CPP(1).  This can be useful to decompose Dockerfiles into several reusable parts that can be used via CPP's
       #include directive.  Notice, a Dockerfile.in file can still be used by other tools when manually preprocessing them via cpp -E.

@rhatdan
Copy link
Member

rhatdan commented Jun 19, 2020

@TomSweeneyRedHat Did we ever blog on this feature?

@rhatdan
Copy link
Member

rhatdan commented Jun 19, 2020

If not this entire issue would make for a nice blog.

@TomSweeneyRedHat
Copy link
Member

@rhatdan, I don't believe we did. I'll add it to the list.

@nnachefski
Copy link
Author

nnachefski commented Jun 19, 2020

You can already do this:
test.Dockerfile:

ARG FROM=registry.access.redhat.com/ubi8
FROM $FROM
ARG FROM
ENV FROM=$FROM

to swap out the FROM, build it like podman build --build-arg=FROM=registry.fedoraproject.org/fedora -f from.Dockerfile

Thanks for the help folks. This is good news, except i dont have access to change the Dockerfile. Basically, i'm inserting a custom layer on top of ubi8 image, and then using tekton to build a custom s2i chain on top of the customized base. That being said, i wont be able to change your Dockerfile for core/base/python36/node10 etc.... To do this, i would have to fork it and that is not an option as i dont want to maintain a separate code base for each runtime just to insert some ARG into the Dockerfile. I request that this be option be like Kanikos where you dont have to edit the Dockerfile to include the FROM arg before the FROM statement. I'd like it better if the only thing i had to do is patch the ClusterTask to include an extra arg (--build-arg).

@nnachefski
Copy link
Author

It's also worth noting that i've been doing this custom s2i chain builds with basic Openshift build objects for awhile now. 'oc new-build' has this functionality as i'm able to override the FROM image with a '-i' in the oc CLI. I want to port this work over to tekton for a customer and that's why i'm doing this now.

@rhatdan
Copy link
Member

rhatdan commented Jun 22, 2020

Ok I am fine with this change.

@rhatdan
Copy link
Member

rhatdan commented Jun 22, 2020

Getting a PR would make it faster.

@rhatdan
Copy link
Member

rhatdan commented Aug 6, 2020

@ashley-cui PTAL

@TomSweeneyRedHat
Copy link
Member

Actually I think this is tied in with the one that I'm working on now. I think the fix for #2496 will fit here too. Let me steal this back.

TomSweeneyRedHat added a commit to TomSweeneyRedHat/buildah that referenced this issue Aug 7, 2020
When an argument was passed into "COPY --from" command in
a Containerfile like

COPY --from=${toolchainname}

The argument was never resolved to the value that it had been
set to.

Addresses: containers#2496

It may also address containers#2404 but I've not yet tested.

Signed-off-by: TomSweeneyRedHat <[email protected]>
TomSweeneyRedHat added a commit to TomSweeneyRedHat/buildah that referenced this issue Aug 8, 2020
When an argument was passed into "COPY --from" command in
a Containerfile like

COPY --from=${toolchainname}

The argument was never resolved to the value that it had been
set to.

Addresses: containers#2496

It may also address containers#2404 but I've not yet tested.

Signed-off-by: TomSweeneyRedHat <[email protected]>
TomSweeneyRedHat added a commit to TomSweeneyRedHat/buildah that referenced this issue Aug 10, 2020
When an argument was passed into "COPY --from" command in
a Containerfile like

COPY --from=${toolchainname}

The argument was never resolved to the value that it had been
set to.

Addresses: containers#2496

It may also address containers#2404 but I've not yet tested.

Signed-off-by: TomSweeneyRedHat <[email protected]>
bors bot added a commit that referenced this issue Aug 10, 2020
2522: Handle COPY --from when an argument is used r=rhatdan a=TomSweeneyRedHat

When an argument was passed into "COPY --from" command in
a Containerfile like

COPY --from=${toolchainname}

The argument was never resolved to the value that it had been
set to.

Addresses: #2496

It may also address #2404 but I've not yet tested.

Signed-off-by: TomSweeneyRedHat <[email protected]>

<!--
Thanks for sending a pull request!

Please make sure you've read and understood our contributing guidelines
(https://github.com/containers/buildah/blob/master/CONTRIBUTING.md) as well as ensuring
that all your commits are signed with `git commit -s`.
-->

#### What type of PR is this?

<!--
Please label this pull request according to what type of issue you are
addressing, especially if this is a release targeted pull request.

Uncomment only one `/kind <>` line, hit enter to put that in a new line, and
remove leading whitespace from that line:
-->

> /kind api-change
> /kind bug
> /kind cleanup
> /kind deprecation
> /kind design
> /kind documentation
> /kind failing-test 
> /kind feature
> /kind flake
> /kind other

#### What this PR does / why we need it:

#### How to verify it

#### Which issue(s) this PR fixes:

<!--
Automatically closes linked issue when PR is merged.
Uncomment the following comment block and include the issue
number or None on one line.
Usage: `Fixes #<issue number>`, or `Fixes (paste link of issue)`, or `None`.
-->

<!--
Fixes #
or
None
-->

#### Special notes for your reviewer:

#### Does this PR introduce a user-facing change?

<!--
If no, just write `None` in the release-note block below. If yes, a release note
is required: Enter your extended release note in the block below. If the PR
requires additional action from users switching to the new release, include the
string "action required".

For more information on release notes please follow the kubernetes model:
https://git.k8s.io/community/contributors/guide/release-notes.md
-->

```release-note

```



Co-authored-by: TomSweeneyRedHat <[email protected]>
@nnachefski
Copy link
Author

Hey Tom,

Would love to help you test this. Where can i get the latest buildah image from so i can see if this works now?

@TomSweeneyRedHat
Copy link
Member

Nick, there's no ready made rpm at the moment. So there are two choices, A) you could clone the repo and build from upstream, or B) you could use Podman and run the quay.io/bulidah/upstream:latest image. I just updated that container image on quay.io a little bit ago, so it should have the latest/greatest there.

@nnachefski
Copy link
Author

nnachefski commented Aug 27, 2020

Hey Tom,

I dont think quay.io/bulidah/upstream:latest is a valid image. Or at least, not one that i have privs too see.

EDIT
I found it at quay.io/buildah/upstream:master

@nnachefski
Copy link
Author

nnachefski commented Aug 27, 2020

I'm setting this in my buildah ClusterTask:

--build-arg=FROM=$(resources.inputs.image.url)'

And the image URL is being populated during the Pipeline Run. But, buildah is ignoring the FROM build-arg and using the FROM in the Dockerfile. Any pointers on how to use this properly?

I'm using this buildah image 'quay.io/buildah/upstream:master'

Output from PipelineRun

STEP-CREATE-DIR-IMAGE-ZLPX4

STEP-GIT-SOURCE-S2I-BASE-GIT-FFJVQ

{"level":"info","ts":1598568843.9707274,"caller":"git/git.go:105","msg":"Successfully cloned https://github.com/sclorg/s2i-base-container.git @ master in path /workspace/source"}
{"level":"warn","ts":1598568843.9708374,"caller":"git/git.go:152","msg":"Unexpected error: creating symlink: symlink /tekton/home/.ssh /root/.ssh: file exists"}
{"level":"info","ts":1598568845.1111348,"caller":"git/git.go:133","msg":"Successfully initialized and updated submodules in path /workspace/source"}
STEP-DEBUG

building with ARGS: 'FOO=BAR FROM=image-registry.openshift-image-registry.svc:5000/openshift/ubi8-custom:latest'
STEP-BUILD

STEP 1: FROM registry.access.redhat.com/ubi8:latest
...
...
[Warning] one or more build args were not consumed: [FOO FROM]

@TomSweeneyRedHat
Copy link
Member

@nnachefski for this latest error, were you using the same Dockerfile that you included in an earlier comment in this thread?

We've had some issues with ARG handling in Containerfiles when an equal sign was in the mix. As a real quick try, can you drop the first equal sign?

i.e. --build-arg FROM=$(resources.inputs.image.url)'

and try that.

It's way past open eyelid time here, I'll check back in the morning.

@rhatdan
Copy link
Member

rhatdan commented Oct 7, 2020

@nnachefski @TomSweeneyRedHat What is going on with this one?

@rhatdan rhatdan added the kind/bug Categorizes issue or PR as related to a bug. label Oct 7, 2020
@nnachefski
Copy link
Author

this still doesnt work.

@nnachefski
Copy link
Author

nnachefski commented Oct 14, 2020

Using image quay.io/buildah/upstream:master

STEP-DEBUG
building with ARGS: 'FOO=BAR FROM=ubi8:latest'

STEP-BUILD
STEP 1: FROM ubi8:latest
Getting image source signatures
Copying blob sha256:c4d668e229cd131e0a8e4f8218dca628d9cf9697572875e355fe4b247b6aa9f0
Copying blob sha256:ec1681b6a383e4ecedbeddd5abc596f3de835aed6db39a735f62395c8edbff30
Copying config sha256:ecbc6f53bba0d1923ca9e92b3f747da8353a070fccbae93625bd8b47dbee772e
Writing manifest to image destination
Storing signatures
STEP 2: COPY testing.txt /etc/
STEP 3: COMMIT image-registry.openshift-image-registry.svc:5000/openshift/ubi8-custom:latest
--> fd65e042adf
[Warning] one or more build args were not consumed: [FOO FROM]

TomSweeneyRedHat added a commit to TomSweeneyRedHat/buildah that referenced this issue Nov 25, 2020
DO NOT MERGE:  I need to add tests, but before doing so
want to see if I've messed anything up with the CI.

This changes will allow the "FROM" statement in a Containerfile
to be overriden with a build-arg.  If I have this Dockerfile.fedora

```
FROM fedora
```

This command will instead build an alpine image:

```
STEP 1: FROM alpine
Completed short name "alpine" with unqualified-search registries (origin: /etc/containers/registries.conf)
Getting image source signatures
Copying blob 188c0c94c7c5 done
Copying config d6e46aa247 done
Writing manifest to image destination
Storing signatures
STEP 2: COMMIT tom
--> d6e46aa2470
d6e46aa2470df1d32034c6707c8041158b652f38d2a9ae3d7ad7e7532d22ebe0
```

Addresses: containers#2404

Signed-off-by: TomSweeneyRedHat <[email protected]>
TomSweeneyRedHat added a commit to TomSweeneyRedHat/buildah that referenced this issue Nov 25, 2020
This changes will allow the "FROM" statement in a Containerfile
to be overriden with a build-arg.  If I have this Dockerfile.fedora

```
FROM fedora
```

This command will instead build an alpine image:

```
STEP 1: FROM alpine
Completed short name "alpine" with unqualified-search registries (origin: /etc/containers/registries.conf)
Getting image source signatures
Copying blob 188c0c94c7c5 done
Copying config d6e46aa247 done
Writing manifest to image destination
Storing signatures
STEP 2: COMMIT tom
--> d6e46aa2470
d6e46aa2470df1d32034c6707c8041158b652f38d2a9ae3d7ad7e7532d22ebe0
```

Addresses: containers#2404

Signed-off-by: TomSweeneyRedHat <[email protected]>
TomSweeneyRedHat added a commit to TomSweeneyRedHat/buildah that referenced this issue Dec 3, 2020
This changes will allow the "FROM" statement in a Containerfile
to be overriden with a build-arg.  If I have this Dockerfile.fedora

```
FROM fedora
```

This command will instead build an alpine image:

```
STEP 1: FROM alpine
Completed short name "alpine" with unqualified-search registries (origin: /etc/containers/registries.conf)
Getting image source signatures
Copying blob 188c0c94c7c5 done
Copying config d6e46aa247 done
Writing manifest to image destination
Storing signatures
STEP 2: COMMIT tom
--> d6e46aa2470
d6e46aa2470df1d32034c6707c8041158b652f38d2a9ae3d7ad7e7532d22ebe0
```

Addresses: containers#2404

Signed-off-by: TomSweeneyRedHat <[email protected]>
@TomSweeneyRedHat TomSweeneyRedHat added the In Progress This issue is actively being worked by the assignee, please do not work on this at this time. label Dec 3, 2020
TomSweeneyRedHat added a commit to TomSweeneyRedHat/buildah that referenced this issue Dec 5, 2020
This changes will allow the "FROM" statement in a Containerfile
to be overriden with a build-arg.  If I have this Dockerfile.fedora

```
FROM fedora
```

This command will instead build an alpine image:

```
STEP 1: FROM alpine
Completed short name "alpine" with unqualified-search registries (origin: /etc/containers/registries.conf)
Getting image source signatures
Copying blob 188c0c94c7c5 done
Copying config d6e46aa247 done
Writing manifest to image destination
Storing signatures
STEP 2: COMMIT tom
--> d6e46aa2470
d6e46aa2470df1d32034c6707c8041158b652f38d2a9ae3d7ad7e7532d22ebe0
```

Addresses: containers#2404

Signed-off-by: TomSweeneyRedHat <[email protected]>
TomSweeneyRedHat added a commit to TomSweeneyRedHat/buildah that referenced this issue Dec 5, 2020
This changes will allow the "FROM" statement in a Containerfile
to be overriden with a build-arg.  If I have this Dockerfile.fedora

```
FROM fedora
```

This command will instead build an alpine image:

```
STEP 1: FROM alpine
Completed short name "alpine" with unqualified-search registries (origin: /etc/containers/registries.conf)
Getting image source signatures
Copying blob 188c0c94c7c5 done
Copying config d6e46aa247 done
Writing manifest to image destination
Storing signatures
STEP 2: COMMIT tom
--> d6e46aa2470
d6e46aa2470df1d32034c6707c8041158b652f38d2a9ae3d7ad7e7532d22ebe0
```

Addresses: containers#2404

Signed-off-by: TomSweeneyRedHat <[email protected]>
TomSweeneyRedHat added a commit to TomSweeneyRedHat/buildah that referenced this issue Dec 5, 2020
This changes will allow the "FROM" statement in a Containerfile
to be overriden with a build-arg.  If I have this Dockerfile.fedora

```
FROM fedora
```

This command will instead build an alpine image:

```
STEP 1: FROM alpine
Completed short name "alpine" with unqualified-search registries (origin: /etc/containers/registries.conf)
Getting image source signatures
Copying blob 188c0c94c7c5 done
Copying config d6e46aa247 done
Writing manifest to image destination
Storing signatures
STEP 2: COMMIT tom
--> d6e46aa2470
d6e46aa2470df1d32034c6707c8041158b652f38d2a9ae3d7ad7e7532d22ebe0
```

Addresses: containers#2404

Signed-off-by: TomSweeneyRedHat <[email protected]>
TomSweeneyRedHat added a commit to TomSweeneyRedHat/buildah that referenced this issue Dec 13, 2020
This changes will allow the "FROM" statement in a Containerfile
to be overriden with a new `--from` flag.  If I have this Dockerfile.fedora

```
FROM fedora
```

This command will instead build an alpine image:

```
STEP 1: FROM alpine
Completed short name "alpine" with unqualified-search registries (origin: /etc/containers/registries.conf)
Getting image source signatures
Copying blob 188c0c94c7c5 done
Copying config d6e46aa247 done
Writing manifest to image destination
Storing signatures
STEP 2: COMMIT tom
--> d6e46aa2470
d6e46aa2470df1d32034c6707c8041158b652f38d2a9ae3d7ad7e7532d22ebe0
```

Addresses: containers#2404

Signed-off-by: TomSweeneyRedHat <[email protected]>
TomSweeneyRedHat added a commit to TomSweeneyRedHat/buildah that referenced this issue Dec 13, 2020
These changes will allow the "FROM" statement in a Containerfile
to be overridden with a new `--from` option.  If I have this Dockerfile.fedora

```
FROM fedora
```

This command will instead build an alpine image:

```
STEP 1: FROM alpine
Completed short name "alpine" with unqualified-search registries (origin: /etc/containers/registries.conf)
Getting image source signatures
Copying blob 188c0c94c7c5 done
Copying config d6e46aa247 done
Writing manifest to image destination
Storing signatures
STEP 2: COMMIT tom
--> d6e46aa2470
d6e46aa2470df1d32034c6707c8041158b652f38d2a9ae3d7ad7e7532d22ebe0
```

Addresses: containers#2404

Signed-off-by: TomSweeneyRedHat <[email protected]>
TomSweeneyRedHat added a commit to TomSweeneyRedHat/buildah that referenced this issue Dec 13, 2020
These changes will allow the "FROM" statement in a Containerfile
to be overridden with a new `--from` option.  If I have this Dockerfile.fedora

```
FROM fedora
```

This command will instead build an alpine image:

```
STEP 1: FROM alpine
Completed short name "alpine" with unqualified-search registries (origin: /etc/containers/registries.conf)
Getting image source signatures
Copying blob 188c0c94c7c5 done
Copying config d6e46aa247 done
Writing manifest to image destination
Storing signatures
STEP 2: COMMIT tom
--> d6e46aa2470
d6e46aa2470df1d32034c6707c8041158b652f38d2a9ae3d7ad7e7532d22ebe0
```

Addresses: containers#2404

Signed-off-by: TomSweeneyRedHat <[email protected]>
TomSweeneyRedHat added a commit to TomSweeneyRedHat/buildah that referenced this issue Dec 13, 2020
These changes will allow the "FROM" statement in a Containerfile
to be overridden with a new `--from` option.  If I have this Dockerfile.fedora

```
FROM fedora
```

This command will instead build an alpine image:

```
STEP 1: FROM alpine
Completed short name "alpine" with unqualified-search registries (origin: /etc/containers/registries.conf)
Getting image source signatures
Copying blob 188c0c94c7c5 done
Copying config d6e46aa247 done
Writing manifest to image destination
Storing signatures
STEP 2: COMMIT tom
--> d6e46aa2470
d6e46aa2470df1d32034c6707c8041158b652f38d2a9ae3d7ad7e7532d22ebe0
```

Addresses: containers#2404

Signed-off-by: TomSweeneyRedHat <[email protected]>
TomSweeneyRedHat added a commit to TomSweeneyRedHat/buildah that referenced this issue Dec 16, 2020
These changes will allow the "FROM" statement in a Containerfile
to be overridden with a new `--from` option.  If I have this Dockerfile.fedora

```
FROM fedora
```

This command will instead build an alpine image:

```
STEP 1: FROM alpine
Completed short name "alpine" with unqualified-search registries (origin: /etc/containers/registries.conf)
Getting image source signatures
Copying blob 188c0c94c7c5 done
Copying config d6e46aa247 done
Writing manifest to image destination
Storing signatures
STEP 2: COMMIT tom
--> d6e46aa2470
d6e46aa2470df1d32034c6707c8041158b652f38d2a9ae3d7ad7e7532d22ebe0
```

Addresses: containers#2404

Signed-off-by: TomSweeneyRedHat <[email protected]>
TomSweeneyRedHat added a commit to TomSweeneyRedHat/buildah that referenced this issue Dec 18, 2020
These changes will allow the "FROM" statement in a Containerfile
to be overridden with a new `--from` option.  If I have this Dockerfile.fedora

```
FROM fedora
```

This command will instead build an alpine image:

```
STEP 1: FROM alpine
Completed short name "alpine" with unqualified-search registries (origin: /etc/containers/registries.conf)
Getting image source signatures
Copying blob 188c0c94c7c5 done
Copying config d6e46aa247 done
Writing manifest to image destination
Storing signatures
STEP 2: COMMIT tom
--> d6e46aa2470
d6e46aa2470df1d32034c6707c8041158b652f38d2a9ae3d7ad7e7532d22ebe0
```

Addresses: containers#2404

Signed-off-by: TomSweeneyRedHat <[email protected]>
@umohnani8
Copy link
Member

Looks like this was fixed in #2823. Can this be closed now @TomSweeneyRedHat ?

@rhatdan rhatdan closed this as completed Jan 27, 2021
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Sep 8, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
In Progress This issue is actively being worked by the assignee, please do not work on this at this time. kind/bug Categorizes issue or PR as related to a bug. locked - please file new issue/PR
Projects
None yet
Development

No branches or pull requests

6 participants