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

Extend --from flag with support for multi-stage builds in buildah build #5401

Open
parthyadav3105 opened this issue Mar 14, 2024 · 5 comments
Labels
kind/feature Categorizes issue or PR as related to a new feature. stale-issue

Comments

@parthyadav3105
Copy link

/kind feature

Description
When using buildah build --from for Containerfile having multi-stage builds, it is not sufficient for modifying FROM instructions of later build stages in the file.
This issue requests support for changing FROM instructions in Containerfile having multiple build stages.

The same has been previously mentioned here #4821 (comment)

@flouthoc
How about if we can add a new option to buildah build --from-target which will swap the base image for target or last stage in a multi-stage build. Regarding the commit problem i did not get the issue completely if buildah manages the commits, you can use the final built image, what is the issue there ?

This is the exact requirement that I want to achieve.

I propose to extend the existing --from flag while keeping it backwards compatible with the following syntax:
--from "target=image,target2=image"
Here --from takes a comma separated list. If the target is omitted then that means first FROM instruction.

Examples:

  • --from builder=ubuntu:22.04,final=alpine:latest # changes FROM instructions of builder stage with "ubuntu:22.04" and final stage with "alpine:latest"
  • --from nginx:latest # changes first FROM instruction

Another alternative to comma-separated list is to use --from multiple times.

@openshift-ci openshift-ci bot added the kind/feature Categorizes issue or PR as related to a new feature. label Mar 14, 2024
@rhatdan
Copy link
Member

rhatdan commented Mar 15, 2024

Could you show an original Containerfile and what you would expect to be changed via the --from or --from-target command?

@parthyadav3105
Copy link
Author

I have following file:

FROM ubuntu:latest as Downloader

RUN apt-get update && apt-get install -y curl

# Download and install Go
RUN curl -L https://go.dev/dl/go1.20.6.linux-amd64.tar.gz --output /tmp/go1.20.6.linux-amd64.tar.gz \
    && tar -C /usr/local -xzf /tmp/go1.20.6.linux-amd64.tar.gz \
    && rm /tmp/go1.20.6.linux-amd64.tar.gz

# Change the base image
FROM centos:latest as NewBase

COPY --from=Downloader /usr/local/go /usr/local/go

# Set environment variables to add Go to the PATH
ENV PATH="$PATH:/usr/local/go/bin"

I want to change centos:latest to fedora:latest in NewBase target.
This is a simple example.

I have more complex base images and I want to make use of multi-stage builds and cache to speed up image building.
buildah build --from "NewBase=fedora:latest" --layers -t parthyadav/multi-stage .

Copy link

A friendly reminder that this issue had no activity for 30 days.

@parthyadav3105
Copy link
Author

I still need this(ability to change FROM instruction other than first FROM statement) (My usecase is specific to very last FROM instruction).

Copy link

A friendly reminder that this issue had no activity for 30 days.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind/feature Categorizes issue or PR as related to a new feature. stale-issue
Projects
None yet
Development

No branches or pull requests

2 participants