Red Hat Bugzilla – Bug 1461503
Empty directories are missing in images created using binary type with Docker build strategy
Last modified: 2017-08-16 15:51 EDT
Description of problem:
Version-Release number of selected component (if applicable):
Steps to Reproduce:
1. # oc new-project 01868320
2. # mkdir -p build/dir1/dir2/dir3/
3. # touch build/dir1/dir2/test.txt
4. # oc new-build build/. --strategy=docker -D $'FROM registry.access.redhat.com/rhel7 \nCOPY build/ /opt/' --name='testbc'
5. oc start-build testbc --from-dir=. -Fw
6. oc run -i test-img --image=172.30.247.236:5000/01868320/testbc:latest
$ sh-4.2$ ls -al /opt/dir1/dir2/
drwxr-xr-x. 2 root root 22 Jun 13 08:08 .
drwxr-xr-x. 3 root root 18 Jun 13 08:08 ..
-rw-r--r--. 1 root root 0 Jun 13 08:08 test.txt
dir3 (which is empty) is not included in the image
dir3 (and any empty directory) is included in the image
The same procedure works correctly on docker, and the empty directories are included in the image:
# cat Dockerfile
COPY build/ /opt/
# docker build -t test .
# docker run -it test
# ls -l /opt/dir1/dir2/
drwxr-xr-x. 2 root root 6 Jun 13 07:25 dir3
-rw-r--r--. 1 root root 0 Jun 13 07:25 test.txt
this is an issue with how we tar up the local content to send it to the build. Currently this code only includes files, not dirs, in the tar:
I'm not sure if there's a historical reason for that, or it was inadvertent.
Cesar any chance you know if there's a specific reason we do it that way? Or Michal?
I don't remember a specific reason for only including files and not directories. This is definitely not a regression though.
Ben, isn't it because of GIT? I do remember git omits the empty directories. To workaround this bug, can you just drop a .gitignore to that empty folder?
@Michal no, has nothing to do w/ git, it's the tar logic i pointed to in comment 1. This also affects binary builds (no git involved).
# oc run -i test-img1 --image=docker-registry.default.svc:5000/dyan5/testbc:latest
If you don't see a command prompt, try pressing enter.
ls -al /opt/dir1/dir2/
drwxr-xr-x. 3 root root 34 Jul 5 09:52 .
drwxr-xr-x. 3 root root 18 Jul 5 09:52 ..
drwxr-xr-x. 2 root root 6 Jul 5 09:52 dir3
-rw-r--r--. 1 root root 0 Jul 5 09:52 test.txt