Bug 1461503 - Empty directories are missing in images created using binary type with Docker build strategy
Empty directories are missing in images created using binary type with Docker...
Status: CLOSED NEXTRELEASE
Product: OpenShift Container Platform
Classification: Red Hat
Component: Build (Show other bugs)
3.5.1
Unspecified Unspecified
high Severity high
: ---
: ---
Assigned To: Jim Minter
Wenjing Zheng
:
Depends On:
Blocks:
  Show dependency treegraph
 
Reported: 2017-06-14 11:40 EDT by Alexis Solanas
Modified: 2017-08-16 15 EDT (History)
7 users (show)

See Also:
Fixed In Version:
Doc Type: Bug Fix
Doc Text:
Cause: the internal library that generated tar files, e.g. for transferring binaries for binary builds, did not add tar records for directories Consequence: empty directories were incorrectly omitted from binary builds Fix: the library now adds tar records for directories Result: empty directories should be included in binary builds
Story Points: ---
Clone Of:
Environment:
Last Closed: 2017-08-14 14:46:46 EDT
Type: Bug
Regression: ---
Mount Type: ---
Documentation: ---
CRM:
Verified Versions:
Category: ---
oVirt Team: ---
RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: ---


Attachments (Terms of Use)

  None (edit)
Description Alexis Solanas 2017-06-14 11:40:52 EDT
Description of problem:




Version-Release number of selected component (if applicable):

 Openshift v3.5.5.15
 

How reproducible:

 Always


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/
   total 0
   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


Actual results:

 dir3 (which is empty) is not included in the image

Expected results:

 dir3 (and any empty directory) is included in the image

Additional info:

  The same procedure works correctly on docker, and the empty directories are included in the image:

  # cat Dockerfile 
  FROM registry.access.redhat.com/rhel7 
  COPY build/ /opt/

  # docker build -t test .
  # docker run -it test
  # ls -l /opt/dir1/dir2/
  total 0
  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
Comment 1 Ben Parees 2017-06-16 12:51:12 EDT
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:
https://github.com/openshift/origin/blob/master/vendor/github.com/openshift/source-to-image/pkg/tar/tar.go#L207

I'm not sure if there's a historical reason for that, or it was inadvertent.
Comment 2 Ben Parees 2017-06-16 12:52:01 EDT
Cesar any chance you know if there's a specific reason we do it that way?  Or Michal?
Comment 3 Cesar Wong 2017-06-16 13:11:29 EDT
I don't remember a specific reason for only including files and not directories. This is definitely not a regression though.
Comment 7 Michal Fojtik 2017-06-29 03:09:34 EDT
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?
Comment 8 Ben Parees 2017-06-29 09:52:08 EDT
@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).
Comment 11 Jim Minter 2017-07-04 08:12:32 EDT
https://github.com/openshift/origin/pull/14992
Comment 13 Dongbo Yan 2017-07-05 05:57:10 EDT
verified
openshift v3.6.133
kubernetes v1.6.1+5115d708d7

# 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/
total 0
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

Note You need to log in before you can comment on or make changes to this bug.