Skip to content

Added --include flag to buildah add and buildah copy - #6988

Open
ajoshua2004 wants to merge 1 commit into
podman-container-tools:mainfrom
ajoshua2004:include
Open

Added --include flag to buildah add and buildah copy#6988
ajoshua2004 wants to merge 1 commit into
podman-container-tools:mainfrom
ajoshua2004:include

Conversation

@ajoshua2004

Copy link
Copy Markdown
Contributor

What type of PR is this?

/kind feature

What this PR does / why we need it:

Adds an --include flag to both add and copy cli commands. This is the complement to --exclude .
Its purpose is to only copy files with the corresponding pattern. Excludes will take priority when both match

This feature is not usable in Dockerfiles and Containerfiles

How to verify it

bats --filter "add --include" tests/add.bats
bats --filter "copy --include" tests/copy.bats

Which issue(s) this PR fixes:

Part of #6732

Special notes for your reviewer:

This is the precursor to the RequiredPaths flag that will be incoming.

Does this PR introduce a user-facing change?

`buildah copy --include` and `buildah add --include ` is the complement to the `buildah copy --exclude` and `buildah add --exclude` commands

@packit-as-a-service

Copy link
Copy Markdown

Ephemeral COPR build failed. @containers/packit-build please check.

Comment thread docs/buildah-add.1.md Outdated
Comment thread docs/buildah-add.1.md Outdated
Comment thread docs/buildah-copy.1.md
Comment thread copier/copier.go
// Matches uses filepath.FromSlash() to convert candidates before
// checking if they match the patterns it's been given, implying that
// it expects Unix-style paths.
matches, err := pm.Matches(filepath.ToSlash(rel)) //nolint:staticcheck

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

IDK, and I don't think it's an issue, but will ask. Do we have to worry about a symbolic link here? If someone set up a symbolic link to /etc/passwd or what have you, and the link was put in the include option, would it suck in the passwd info to the container? Mostly concerning in a rootless environment.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

links are handled in the same way as excludes so I don't believe we'd have to worry about links.

@ajoshua2004
ajoshua2004 force-pushed the include branch 2 times, most recently from 2802cf0 to dd88ebb Compare July 24, 2026 14:51
@ajoshua2004

Copy link
Copy Markdown
Contributor Author

@podman-container-tools/buildah-maintainers

Comment thread tests/add.bats Outdated
Comment thread copier/copier.go Outdated
Comment thread docs/buildah-add.1.md Outdated
Comment thread tests/add.bats Outdated
run_buildah_umount $cid
expect_output --from="$filelist" "$expect" "add recursive include"

# else arm: a single named file that matches include copies cleanly

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Not sure what the first part of this comment means.

Comment thread tests/add.bats
Comment thread tests/copy.bats
Complement to existing --exclude flag. When specified, only files matching
the given patterns are copied. Uses the same containerignore(5) pattern
format. Can be combined with --exclude, where exclude takes priority.

Signed-off-by: Joshua Arrevillaga <2004jarevillaga@gmail.com>
@ajoshua2004

Copy link
Copy Markdown
Contributor Author

PTAL @podman-container-tools/buildah-maintainers

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants