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

dockerfile: allow pivot point for --parents flag #4728

Merged
merged 3 commits into from
Mar 4, 2024

Conversation

tonistiigi
Copy link
Member

follow-up for #3001

Similarily to rsync --relative flag add support for /./ pivot point to mark which parent directories as kept.

This is especially useful in multi-stage builds because --from paths need to be always full paths.

FROM ... AS base
RUN ./generate-lot-of-files -o /out/

FROM scratch
COPY --from=base --parents /out/./**/bin/ /
# /usr/bin/bar
# /usr/local/bin/foo

cc @DYefimov

Signed-off-by: Tonis Tiigi <[email protected]>
This replicates similar functionality in rsync.

Signed-off-by: Tonis Tiigi <[email protected]>
As with Rsync, it is possible to limit which parent directories are preserved by
inserting a dot and a slash (`./`) into the source path. If such point exists, only parent
directories after it will be preserved. This may be especially useful copies between stages
with `--from` where the source paths need to be absolute.
Copy link
Member

Choose a reason for hiding this comment

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

Dockerfile version should be mentioned

Copy link
Member Author

Choose a reason for hiding this comment

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

line 1578

parent, pattern, ok := strings.Cut(src, "/./")
if !ok {
pattern = src
src = "/"
Copy link
Member

Choose a reason for hiding this comment

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

os.PathSeparator should be used ?

Copy link
Member Author

Choose a reason for hiding this comment

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

No, it should always be slash. Windows works with slashes as well. If the input is not / ( and windows) then it is converted to / in NormalizePath().

@jmurzy
Copy link

jmurzy commented Mar 3, 2024

That was fast. You rock! Thank you! 🙏🏻

@AkihiroSuda AkihiroSuda merged commit b399eef into moby:master Mar 4, 2024
73 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants