buildah icon indicating copy to clipboard operation
buildah copied to clipboard

[RFE] Add support for `--link` in `COPY/ADD`

Open lucacome opened this issue 3 years ago • 46 comments

Description

Buildkit added support for the --link flag. Quoting from the docs:

Enabling this flag in COPY or ADD commands allows you to copy files with enhanced semantics where your files remain independent on their own layer and don't get invalidated when commands on previous layers are changed.

When --link is used your source files are copied into an empty destination directory. That directory is turned into a layer that is linked on top of your previous state.

This is a feature request to add this feature in buildah šŸ™‚

lucacome avatar Oct 07 '22 18:10 lucacome

Hello @lucacome and @TomSweeneyRedHat,

I want to contribute to this issue but am new to the project, How can I get started? :)

CypherpunkSamurai avatar Oct 14 '22 14:10 CypherpunkSamurai

Well first you would need to add support for --link in https://github.com/openshift/imagebuilder I believe. @flouthoc Could you help @CypherpunkSamurai contribute.

rhatdan avatar Oct 15 '22 09:10 rhatdan

Hi,

Yes implementation must start from imagebuilder and introduce a new attribute link bool to Copy struct and must be set true when COPY or ADD contains --link and on buildah side if Copy.link == truethen layer must be created on a scratch base, in theory COPY --link must be replaced with a functionality similar to stage where scratch image is base and file is just copied to target path.

COPY --link /src /target

must create a intermediate image equivalent to

FROM scatch
COPY /src /target

flouthoc avatar Oct 21 '22 07:10 flouthoc

Hi @CypherpunkSamurai

I was wondering if you've had a chance to start working on this? Or do you need any help? šŸ™‚

lucacome avatar Nov 15 '22 01:11 lucacome

Really sorry about this, I had gotten a little busy with college work.

I'll start work asap by this Saturday.

CypherpunkSamurai avatar Nov 17 '22 07:11 CypherpunkSamurai

No problem college work should come first.

rhatdan avatar Nov 18 '22 20:11 rhatdan

Hello everyone, really sorry again for stalling this issue.

Ok Here's what I understand from the documentation of the --link tag for COPY and ADD build commands:

  • It creates a cached layer that can be reused
  • This cached layer is a layer from scratch. (i.e. a simple rootfs with busybox ? doubts here)

Here's how I understand how I need to implement it:

  • introduce a new attribute link bool to Copy struct and must be set true when COPY or ADD contains --link
  • on buildah side if Copy.link == truethen layer must be created on a scratch base, in theory COPY --link must be replaced with a functionality similar to stage where scratch image is base and file is just copied to target path.

Please check if this is correct

CypherpunkSamurai avatar Nov 19 '22 07:11 CypherpunkSamurai

Yes SGTM. Pretty much what's written here https://github.com/containers/buildah/issues/4325#issuecomment-1286568410 but I'd suggest if you have time to take a look and play with buildkit a bit before implementing this. My explanation in above comment is more conceptual and in past we have seen that buildkit's feature is not completely described in the documentation so its worth verifying edge cases before implementing this.

Note: Buildah mostly tries to match parity with buildkit as much as possible.

flouthoc avatar Nov 19 '22 07:11 flouthoc

Sure. I need to try both the tools first i guess. Would be interesting. I'll try my best to help this issue :)

CypherpunkSamurai avatar Nov 20 '22 15:11 CypherpunkSamurai

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

github-actions[bot] avatar Dec 21 '22 00:12 github-actions[bot]

Alright I researched quite a bit about rootfs and build root for the few weeks. I feel comfortable with linux rootfs and how it works.

Um, if you don't mind guys (@flouthoc and @rhatdan) can you please help me point out how buildah handles creating scratch rootfs? (in addition line number would be very cool)

CypherpunkSamurai avatar Dec 21 '22 17:12 CypherpunkSamurai

@CypherpunkSamurai Its hard to pin the exact line since I'll have to skim the code but I can tell that builder creates a container for FROM scratch instruction you can actually find the part where builder actually creates container.

flouthoc avatar Dec 22 '22 08:12 flouthoc

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

github-actions[bot] avatar Jan 22 '23 00:01 github-actions[bot]

Since we have not heard any more feedback, closing. Reopen if you want to continue looking into this one.

rhatdan avatar Jan 23 '23 17:01 rhatdan

@rhatdan I'm still interested in this and I'd like to keep it open. Maybe somebody else can take over from @CypherpunkSamurai ?

lucacome avatar Jan 23 '23 19:01 lucacome

@CypherpunkSamurai If you are running short on time, I'd request to assign this issue to me :)

flouthoc avatar Jan 24 '23 04:01 flouthoc

Sure. I'm having my exams right now, probably not a great time to work on this. I better not keep this issue stalling :)

On 24 January 2023 10:18:08 AM flouthoc @.***> wrote:

@CypherpunkSamurai If you are running short on time, I'd request to assign this issue to me :) — Reply to this email directly, view it on GitHub, or unsubscribe. You are receiving this because you were mentioned.Message ID: @.***>

CypherpunkSamurai avatar Jan 24 '23 06:01 CypherpunkSamurai

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

github-actions[bot] avatar Feb 24 '23 00:02 github-actions[bot]

Hey @flouthoc, any updates on this? This feature would be great to have :slightly_smiling_face:

der-eismann avatar Mar 21 '23 13:03 der-eismann

I am also very interested.

veritas9872 avatar Apr 15 '23 06:04 veritas9872

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

github-actions[bot] avatar May 16 '23 00:05 github-actions[bot]

Not stale.

sanmai-NL avatar May 16 '23 05:05 sanmai-NL

Any updates on this?

buildkit states concurrent, cache-efficient, and Dockerfile-agnostic builder toolkit so I was also wondering why podman is not using buildkit instead of buildah.

It seems like a lot of work to try and keep parity with buildkit and that effort could be put into improving buildkit? šŸ¤·ā€ā™‚ļø

lucacome avatar Jun 21 '23 20:06 lucacome

@flouthoc This is rising in importance since Podman-desktop needs this.

rhatdan avatar Oct 17 '23 12:10 rhatdan

Ditto, want this functionality

BlaineEXE avatar Nov 20 '23 14:11 BlaineEXE

Bump, would like this functionality. Currently have to modify Dockerfiles to work with podman due to this issue.

johnlauder avatar Dec 02 '23 22:12 johnlauder

@CypherpunkSamurai did you have any work done on this you could share, even if incomplete? I could try and contribute, and if I'm not able - some ground work could be of guidance.

sastorsl avatar Dec 08 '23 14:12 sastorsl

I gave it a try and switched from docker to podman, but without COPY --link it's useless for my projects. Since the issue is already pretty old: is there any chance this will be fixed any time in the near future?

sigbits avatar Mar 19 '24 15:03 sigbits

I’m currently running buildkitd in podman, then use buildctl to build images.

huww98 avatar Mar 19 '24 15:03 huww98

@flouthoc If you haven't started, I can take a shot at this.

danishprakash avatar May 07 '24 08:05 danishprakash