Closed sfitts closed 10 years ago
@mattgruter @sfitts Did you find a solution for your problem?
I also find the addFile API a bit confusing. There seems to be 2 addFile overloads:
addFile(File file)
, which puts the given file in the output folder and adds it to the dockerfile as
ADD <file> /
This seems to be pretty useless, since usually files tend to go somewhere else than /.
Then there is addFile(Closure copySpec)
, which gives full control over copying the file, but that seems a bit unnecessary because typically the file just needs to go into the docker build folder. (stageDir)
Instead, if anyhow possible I would like to see something as simple as this
void addFile(File file, String destination) {
stageDir.mkdir()
project.copy {
from file
into stageDir
}
instructions.add("ADD ${file.name} " + destination)
}
Or did I completely misunderstood something here?
@sfitts
The addFile(Closure copySpec)
API seems to be broken. Honestly I'm not sure how it ever worked. I'm working on a fix. So, no user error on your part.
@dwellner
The recommended way to use the addFile(File file)
API is with tar archive files:
addFile file('archive.tar')
Adding tar archives in a Dockerfile implictly unpacks the archive (see http://docs.docker.io/reference/builder/#add).
The idea here is to add the docker payload by first creating a tar archive with the correct directory structure (e.g. an archive created by a distTar
application task) and then passing the archive to addFile
.
Until the addFile(Closure copySpec)
API call is fixed, creating a tar archive is the most flexible way to add files. We'll probably also add a possibility to addFile(File file, String destination)
in the next release (coming soon).
Cheers, Matthias
Thanks for the update and for the explanation of how the other variant is designed to be used.
Fixed on branch 'dev'. Included in upcoming version 1.2
This is totally user error, but I cannot figure out how to use the variant of addFile that takes a closure. My assumption is that it wants a copySpec closure, something like
But this fails on the line that uses the closure as a substitution parameter for the ADD line. There is something I'm missing here (I'm a groovy newbie).