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

Change ADD in dockerfile syntax to support renaming output file #2571

Open
mofosyne opened this issue Jun 30, 2024 · 3 comments
Open

Change ADD in dockerfile syntax to support renaming output file #2571

mofosyne opened this issue Jun 30, 2024 · 3 comments

Comments

@mofosyne
Copy link

mofosyne commented Jun 30, 2024

Description

Say you got an existing line like

RUN wget -nv -O /usr/local/bin/nrfutil https://developer.nordicsemi.com/.pc-tools/nrfutil/x64-linux/nrfutil-v2.2

It would be nice to be able to rewrite it as

ADD https://developer.nordicsemi.com/.pc-tools/nrfutil/x64-linux/nrfutil-v2.2 /usr/local/bin/nrfutil

Where nrfutil-v2.2 is renamed to nrfutil

Right now, if I understand correctly you can only really do ADD https://developer.nordicsemi.com/.pc-tools/nrfutil/x64-linux/nrfutil-v2.2 /usr/local/bin/ as the definition of ADD only supports adding file to a folder path. Which would force you to add RUN mv nrfutil-v2.2 /usr/local/bin/nrfutil which is quite ugly.

@vvoland
Copy link
Contributor

vvoland commented Jul 1, 2024

I think you can already do that:

❱ printf 'FROM busybox\nADD https://github.com/docker/compose/releases/download/v2.28.1/docker-compose-linux-armv6 /usr/local/bin/compose' | docker build -o . -
...
❱ ls usr/local/bin/ -lah
total 59M
drwxr-xr-x 3 pawel staff  96 Jul  1 17:27 ./
drwxr-xr-x 3 pawel staff  96 Jul  1 17:27 ../
-rw------- 1 pawel staff 58M Jun 24 15:06 compose

Are you getting some error when attempting to do that with your URL?

@thaJeztah
Copy link
Member

Yes, it's supported indeed, but I think the documentation could use a touch-up to be more clear on that. It's there if you somewhat read between the lines, but it's not very clear; https://docs.docker.com/reference/dockerfile/#add

If <src> is a URL and <dest> does end with a trailing slash, then the filename is inferred from the URL and the file is downloaded to <dest>/<filename>. For instance, ADD http://example.com/foobar / would create the file /foobar. The URL must have a nontrivial path so that an appropriate filename can be discovered in this case (http://example.com doesn't work).

The above describes that if it DOES end with a trailing / then the filename to use is inferred from the <src> (so uses the same filename as the source). However it doesn't describe what happens if it doesn't end with a trailing /.

There is a mention of the same situation but when using a local source (not a URL);

If <src> is a file, and <dest> doesn't end with a trailing slash, the contents of <src> will be written as filename <dest>.

So we should either combine those, or perhaps repeat that last information for the "URL" section.

As it all becomes a bit, complicated, I'm wondering if that section should be split into three (or more) sections. That would possibly come at the cost of repeating some of the information but (maybe? would have to try) could make it clearer to understand, and may make it clear what kind of sources ADD (and COPY) support. Although, hm... maybe the list gets long

  • Add from a local file
  • Add from a URL
  • Add from a Git URL
  • Add from a stage
  • Add from an image
  • ...

@thaJeztah
Copy link
Member

Let me transfer this to the buildx repository (where most of the build-related docs are now maintained), although the Dockerfile reference is maintained in the Buildkit repository (but can't transfer it there because it's a different org).

Also /cc @dvdksn (for docs)

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

No branches or pull requests

3 participants