Bug 1461503 - Empty directories are missing in images created using binary type with Docker build strategy
Summary: Empty directories are missing in images created using binary type with Docker...
Keywords:
Status: CLOSED NEXTRELEASE
Alias: None
Product: OpenShift Container Platform
Classification: Red Hat
Component: Build
Version: 3.5.1
Hardware: Unspecified
OS: Unspecified
high
high
Target Milestone: ---
: ---
Assignee: Jim Minter
QA Contact: Wenjing Zheng
URL:
Whiteboard:
Depends On:
Blocks:
TreeView+ depends on / blocked
 
Reported: 2017-06-14 15:40 UTC by Alexis Solanas
Modified: 2020-12-14 08:52 UTC (History)
7 users (show)

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
Clone Of:
Environment:
Last Closed: 2017-08-14 18:46:46 UTC
Target Upstream Version:
Embargoed:


Attachments (Terms of Use)

Description Alexis Solanas 2017-06-14 15:40:52 UTC
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 16:51:12 UTC
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 16:52:01 UTC
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 17:11:29 UTC
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 07:09:34 UTC
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 13:52:08 UTC
@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 12:12:32 UTC
https://github.com/openshift/origin/pull/14992

Comment 13 Dongbo Yan 2017-07-05 09:57:10 UTC
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.