How to copy subdirectories of multiple un-named directories - ant

Using just Ant, I want to copy subdirectories of some top-level directories but the names of top-level directories can change so I need Ant to programatically determine which directories to copy.
In other words, given the sample directory structure below, copy the contents of each ./<projectX>/bin directory to ./bin.
bin
project1
\-- bin
\-- com
\-- name
\-- dir1
\-- file1.class
\-- file2.class
\-- file3.class
\-- dir2
\-- file4.class
\-- file5.class
project2
\-- bin
\-- com
\-- name
\-- dir3
\-- file6.class
\-- file7.class
\-- file8.class
project3
\-- bin
\-- com
\-- name
\-- dir4
\-- file9.class
\-- dir5
\-- file10.class
\-- file11.class
And the end result would be a bin directory that looks like this:
bin
\-- com
\-- name
\-- dir1
\-- file1.class
\-- file2.class
\-- file3.class
\-- dir2
\-- file4.class
\-- file5.class
\-- dir3
\-- file6.class
\-- file7.class
\-- file8.class
\-- dir4
\-- file9.class
\-- dir5
\-- file10.class
\-- file11.class
I've tried
<copy todir="${basedir}/bin">
<fileset dir="${basedir}">
<include name="**/bin/*"/>
<exclude name="bin"/>
</fileset>
</copy>
but that includes the projectX/bin directories underneath the top-level bin directory.

You can use a mapper to generate the destination paths from the sources, for example:
<copy todir="${basedir}/bin">
<fileset dir="${basedir}">
<include name="*/bin/**"/>
</fileset>
<regexpmapper from=".*/bin/(.*)" to="\1" />
</copy>

Related

Mount a relative path with DockerfileRunArguments

I have an ASP.NET core project running on Docker Desktop on Windows and I want to use the <DockerfileRunArguments> in my .csproj to bind mount a file from the host.
How can I mount a file with a relative path?
This is the structure of the project:
.
+-- source
| +-- project
| | +-- file.json
| | +-- Dockerfile
| +-- project2
| +-- project3
This is what I've tried but it throws an error:
<DockerfileContext>..\..</DockerfileContext>
<DockerfileRunArguments>-v "$(pwd)/source/project/file.json":"/whatever/file.json"</DockerfileRunArguments>
If I try an absolute path the file is mounted just fine.

How to COPY or ADD multiple files and directories in one layer with Dockerfile

I'm trying to ADD/COPY files and directories in one layer with Dockerfile like this:
ADD file.txt dir1 /app/
But it is only copying the content of dir1 instead of the dir itself, how can I copy/add the files and directories in one layer?
The docs on ADD clearly note, that only the content of the directory is copied but not the directory itself.
So for this to work you could create a subdirectory foo containing file.txt and dir1 and then do
ADD foo /app/
which would copy the content of the foo directory into your image.

Docker COPY lost intermediate path

Dockerfile and build context file tree, the core-site.xml file's relative path IS conf/etc/hadoop
.
├── Dockerfile
└── conf
├── etc
│   └── hadoop
│   └── core-site.xml
└── xxx.conf
Dockerfile(very simple) as below
FROM alpine:latest
RUN mkdir -p /data
WORKDIR /data
COPY conf/* /data/
After docker build -t any/any:any ., the COPY layer's file list as below. Intermediate path etc/ of file core-site.xml lost. Where the etc/ gone ?
data/
data/xxx.conf
data/hadoop/
data/hadoop/.wh..wh..opq
data/hadoop/core-site.xml
Remove the * so you just have COPY conf /data
The COPY command treats the copying of files and directories a bit differently. Your COPY statement expands to
COPY conf/etc /data/
COPY conf/xxx.conf /data/
The first statement actually copies the contents of conf/etc into the /data directory on the container.

in Dockerfile while copying file from target to webapps it gives error

I am trying to copy webapp in Dockerfile
COPY /opt/javawar/target /opt/apache-tomcat-8.0.20/webapps/
But I got this error
error: COPY failed: stat /var/lib/docker/tmp/docker-builder791542850/opt/javawar/target: no such file or directory
You can not copy from an absolute path, the path should be relative to Dockerfile,
So place the target in the directory where you place the Dockerfile.
The directory structure will look like
├── Dockerfile
└── target
then
COPY target /opt/apache-tomcat-8.0.20/webapps/
build-context

Docker COPY and keep directory

Need to copy multiple directories in my Dockerfile. Currently, I'm doing:
COPY dir1 /opt/dir1
COPY dir2 /opt/dir2
COPY dir3 /opt/dir3
I would prefer to consolidate those into one single statement, specifying all the sources in one go. However, this way the contents are copied, and I lose the dir1, dir2, dir3 structure:
COPY dir1 dir2 dir3 /opt/
Same in this case:
COPY dir1/ dir2/ dir3/ /opt/
Is there some way to achieve this with one line?
You should consider ADD instead of COPY: see Dockerfile ADD
If <src> is a local tar archive in a recognized compression format (identity, gzip, bzip2 or xz) then it is unpacked as a directory.
That means you can wrap your docker build step into a script which would first tar -cvf dirs.tar dir1 dir2 dir3
Your Dockerfile can then ADD dirs.tar: you will find your folders in your image.
See also Dockerfile Best Practices: ADD or COPY.

Resources