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

buildkit: add from= field to bind and cache mounts so images can be used as source #3590

Merged

Conversation

flouthoc
Copy link
Collaborator

Following commit adds buildkit like support for from field to --mount=type=bind
and --mount=type=cache so images and stage can be used as mount source.

Usage looks like

RUN --mount=type=bind,source=.,from=<your-image>,target=/path ls /path

and

RUN --mount=type=cache,from=<your-image>,target=/path ls /path

Closes: #3501

@openshift-ci
Copy link
Contributor

openshift-ci bot commented Oct 18, 2021

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: flouthoc

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

docs/buildah-run.1.md Outdated Show resolved Hide resolved
docs/buildah-run.1.md Outdated Show resolved Hide resolved
pkg/parse/parse.go Outdated Show resolved Hide resolved
run.go Outdated Show resolved Hide resolved
@flouthoc flouthoc force-pushed the buildkit-mount-from branch 6 times, most recently from a2f101b to 86a1548 Compare October 20, 2021 09:07
@flouthoc
Copy link
Collaborator Author

flouthoc commented Oct 20, 2021

@nalind @TomSweeneyRedHat Made requested corrections. Could you please take a look again.

@flouthoc flouthoc requested a review from nalind October 20, 2021 16:33
@TomSweeneyRedHat
Copy link
Member

LGTM
@nalind does it LGTY?

@nalind
Copy link
Member

nalind commented Oct 20, 2021

The tests need to also exercise source values other than ".", including paths that start with "/", "./", and other values (all of which they need to verify are interpreted as being relative to root of the image or stage specified for the "from"). They also need to check that from values that reference other stages in multi-stage builds work as expected. These options should also be tested with buildah run, where "from" should probably be able to point to other containers, to line up with how the --from flag is treated for buildah copy.

@flouthoc
Copy link
Collaborator Author

@nalind Thanks i'll get these tests in.

@openshift-ci openshift-ci bot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Oct 24, 2021
@openshift-ci openshift-ci bot removed the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Oct 24, 2021
@flouthoc flouthoc force-pushed the buildkit-mount-from branch 4 times, most recently from c683b49 to 3941014 Compare October 24, 2021 12:18
@flouthoc
Copy link
Collaborator Author

The tests need to also exercise source values other than ".", including paths that start with "/", "./", and other values (all of which they need to verify are interpreted as being relative to root of the image or stage specified for the "from"). They also need to check that from values that reference other stages in multi-stage builds work as expected. These options should also be tested with buildah run, where "from" should probably be able to point to other containers, to line up with how the --from flag is treated for buildah copy.

@nalind Added requested tests.

I would also request you to take a look at commit 3941014 which makes sure we use common selinux label across all containers/builders spawned under a common Executor session. Its needed to mount different stages.

@flouthoc flouthoc force-pushed the buildkit-mount-from branch 2 times, most recently from 73a8402 to 91b47f1 Compare January 7, 2022 17:54
@nalind
Copy link
Member

nalind commented Jan 7, 2022

I'm not entirely sure we've got the behavior right for writable bind mounts, otherwise LGTM.

@flouthoc
Copy link
Collaborator Author

flouthoc commented Jan 7, 2022

I'm not entirely sure we've got the behavior right for writable bind mounts, otherwise LGTM.

Me and @nalind discussed this, so our design has some limitation on rw on bind mounts for images. Future solution could be something on the lines of overlay on top of build context but that will be new feature and on a different PR. @nalind Please correct me if i got this right or not.

@containers/build-maintainers @rhatdan @TomSweeneyRedHat PTAL


setDest := false

for _, val := range args {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there no way to consolidate this code together, this is the third time you have code to walk the arg list?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@rhatdan I agree we can reduce redundancy. Some of the options are not supported in other mounts so switch case is slightly different for each one.

However parsing is legacy code this is just a move around. So to prevent huge diff would it work if i do that in a follow up
PR where I will also fix selinux issue.

@rhatdan
Copy link
Member

rhatdan commented Jan 7, 2022

@flouthoc needs rebase.

@flouthoc flouthoc force-pushed the buildkit-mount-from branch 3 times, most recently from 6a65fa8 to fb163aa Compare January 8, 2022 09:05
@flouthoc
Copy link
Collaborator Author

flouthoc commented Jan 8, 2022

I'm not entirely sure we've got the behavior right for writable bind mounts, otherwise LGTM.

@nalind This is implemented in latest commit also added a test to verify this.

@test "bud-with-writeable-mount-bind-from-like-buildkit" {

@rhatdan
Copy link
Member

rhatdan commented Jan 8, 2022

Sadly @flouthoc needs a rebase.

…ed as source

Following commit adds buildkit like support for `from` field to `--mount=type=bind`
and `--mount=type=cache` so images and stage can be used as mount source.

Usage looks like
```dockerfile
RUN --mount=type=bind,source=.,from=<your-image>,target=/path ls /path
```
and
```dockerfile
RUN --mount=type=cache,from=<your-image>,target=/path ls /path
```

Signed-off-by: Aditya Rajan <arajan@redhat.com>
@rhatdan
Copy link
Member

rhatdan commented Jan 8, 2022

/lgtm

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

No --mount option with "podman build" nor Containerfile
6 participants