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

add parents option to dockerfile COPY command #35639

Open
wclr opened this issue Nov 29, 2017 · 3 comments
Open

add parents option to dockerfile COPY command #35639

wclr opened this issue Nov 29, 2017 · 3 comments
Labels
area/builder kind/feature Functionality or other elements that the project doesn't currently have. Features are new and shiny

Comments

@wclr
Copy link

wclr commented Nov 29, 2017

Docs on COPY command state:

If <src> is any other kind of file, it is copied individually along with its metadata. In this case, 
if <dest> ends with a trailing slash /, 
it will be considered a directory and the contents of <src> will be written at <dest>/base(<src>).

I think it would be useful to have be able to have as a copy result <dest>/<src>.

This would allow combining in one COPY command files from different folders in the context, this can be useful when trying to optimize for example node apps builds:

# would place files to /app/package1/package.json & /app/some/dep
COPY some/dep package1/package.json /app/ --parents 
RUN cd package1 && npm install

# would place files to /app/package2/package.json & /app/other/dep
COPY other/dep/ package2/package.json /app/ --parents 
RUN cd package2 && npm install

Currently, have to split COPY commands for this case or do something else less optimal.

@thaJeztah thaJeztah added the kind/feature Functionality or other elements that the project doesn't currently have. Features are new and shiny label Jan 17, 2018
@thaJeztah
Copy link
Member

Related discussion in BuildKit: moby/buildkit#396

@nwalters512
Copy link

This is very much needed with the rise of Node monorepos. If I have a packages/ directory with many subdirectories, each containing a package.json, I need all those package.json files to be present when I run yarn install/npm install. Right now, I have two options:

  • Use individual COPY commands for each package, which is inexplicably slow on GitHub Actions and also a maintenance burden.
  • COPY the entire packages/ directory, which eliminates most of the benefits of Docker layer caching as the layer cache will be invalidated for most builds.

If COPY --parents existed, I believe one could do something like this and take full advantage of layer caching and the speed of a single COPY command:

COPY --parents packages/*/package.json apps/*/package.json /path/to/app/
# The container should now have `/path/to/app/packages/foo/package.json`,
# `/path/to/app/packages/bar/package.json`,
# `/path/to/app/apps/baz/package.json`, and so on.

@thaJeztah
Copy link
Member

There's a work-in-progress pull request in BuildKit implementing this;

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/builder kind/feature Functionality or other elements that the project doesn't currently have. Features are new and shiny
Projects
21.x Planning
  
To do
Development

No branches or pull requests

4 participants