Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Ability for ADD to unTar a file #792

Merged
merged 3 commits into from
Jan 21, 2020
Merged

Fix Ability for ADD to unTar a file #792

merged 3 commits into from
Jan 21, 2020

Conversation

loganprice
Copy link
Contributor

@loganprice loganprice commented Sep 27, 2019

Currently when ADD a tar file to / it does save the changes to the layer even though the Tar file gets unpackaged. You can see the current behavior in the debug log below :

DEBU[0044] Getting files and contents at root /workspace/build/distributions/test12345.tar 
INFO[0044] Using files from context: [/workspace/build/distributions/test12345.tar] 
INFO[0044] ADD build/distributions/test12345.tar /      
DEBU[0044] Resolved build/distributions/test12345.tar to build/distributions/test12345.tar 
DEBU[0044] Resolved / to /                              
DEBU[0044] Getting files and contents at root /workspace/build/distributions/test12345.tar 
INFO[0045] Unpacking local tar archive build/distributions/test12345.tar to / 
DEBU[0045] creating dir /test12345                      
DEBU[0045] creating dir /test12345/lib                  
DEBU[0045] creating file /test12345/lib/test12345-0.0.1.jar 
DEBU[0045] creating file /test12345/lib/platform-connector-spring-boot-2.0.4.jar 
DEBU[0045] creating file /test12345/lib/spring-boot-starter-actuator-2.1.6.RELEASE.jar 
DEBU[0045] creating file /test12345/lib/spring-boot-starter-web-2.1.6.RELEASE.jar 
DEBU[0045] creating file /test12345/lib/spring-boot-starter-log4j2-2.1.6.RELEASE.jar 
DEBU[0045] creating file /test12345/lib/platform-connector-metrics3-2.0.4.jar 
DEBU[0045] creating file /test12345/lib/platform-connector-logging-log4j-2.0.4.jar 
DEBU[0045] creating file /test12345/lib/platform-connector-core-2.0.4.jar 
DEBU[0045] creating file /test12345/lib/metrics-spring-3.1.3.jar 
...
DEBU[0045] creating dir /test12345/bin                  
DEBU[0045] creating file /test12345/bin/test12345.bat   
DEBU[0045] creating file /test12345/bin/test12345       
DEBU[0045] Added [/ / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / /] from local tar archive build/distributions/test12345.tar 
INFO[0045] Taking snapshot of files...                  
DEBU[0045] Taking snapshot of files [/ / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / /] 

Which results in an image without the content of the tar file. After the change I made to the kaniko source code I see the expected behavior in the debug log:

DEBU[0030] Resolved build/distributions/test12345.tar to build/distributions/test12345.tar 
DEBU[0030] Resolved / to /                              
DEBU[0030] Getting files and contents at root /workspace/build/distributions/test12345.tar 
INFO[0030] Using files from context: [/workspace/build/distributions/test12345.tar] 
INFO[0030] ADD build/distributions/test12345.tar /      
DEBU[0030] Resolved build/distributions/test12345.tar to build/distributions/test12345.tar 
DEBU[0030] Resolved / to /                              
DEBU[0030] Getting files and contents at root /workspace/build/distributions/test12345.tar 
INFO[0030] Unpacking local tar archive build/distributions/test12345.tar to / 
Path: /workspace/build/distributions/test12345.tar
Destination: /
DEBU[0031] creating dir /test12345                      
DEBU[0031] creating dir /test12345/lib                  
DEBU[0031] creating file /test12345/lib/test12345-0.0.1.jar 
DEBU[0031] creating file /test12345/lib/platform-connector-spring-boot-2.0.4.jar 
DEBU[0031] creating file /test12345/lib/spring-boot-starter-actuator-2.1.6.RELEASE.jar 
DEBU[0031] creating file /test12345/lib/spring-boot-starter-web-2.1.6.RELEASE.jar 
DEBU[0031] creating file /test12345/lib/spring-boot-starter-log4j2-2.1.6.RELEASE.jar 
DEBU[0031] creating file /test12345/lib/platform-connector-metrics3-2.0.4.jar 
DEBU[0031] creating file /test12345/lib/platform-connector-logging-log4j-2.0.4.jar 
DEBU[0031] creating file /test12345/lib/platform-connector-core-2.0.4.jar 
DEBU[0031] creating file /test12345/lib/metrics-spring-3.1.3.jar 
...
DEBU[0031] creating dir /test12345/bin                  
DEBU[0031] creating file /test12345/bin/test12345.bat   
DEBU[0031] creating file /test12345/bin/test12345       
Extracted Files: [/test12345 /test12345/lib /test12345/lib/test12345-0.0.1.jar /test12345/lib/platform-connector-spring-boot-2.0.4.jar /test12345/lib/spring-boot-starter-actuator-2.1.6.RELEASE.jar /test12345/lib/spring-boot-starter-web-2.1.6.RELEASE.jar /test12345/lib/spring-boot-starter-log4j2-2.1.6.RELEASE.jar /test12345/lib/platform-connector-metrics3-2.0.4.jar /test12345/lib/platform-connector-logging-log4j-2.0.4.jar /test12345/lib/platform-connector-core-2.0.4.jar /test12345/lib/metrics-spring-3.1.3.jar /test12345/lib/log4j-slf4j-impl-2.11.2.jar /test12345/lib/jul-to-slf4j-1.7.26.jar /test12345/lib/metrics-jvm-3.2.6.jar /test12345/lib/hdrhistogram-metrics-reservoir-1.1.2.jar /test12345/lib/metrics-core-3.2.6.jar /test12345/lib/metrics-healthchecks-3.1.2.jar /test12345/lib/metrics-annotation-3.1.2.jar /test12345/lib/slf4j-api-1.7.26.jar /test12345/lib/log4j-jul-2.11.2.jar /test12345/lib/log4j-core-2.11.2.jar /test12345/lib/log4j-api-2.11.2.jar /test12345/lib/spring-boot-starter-json-2.1.6.RELEASE.jar /test12345/lib/spring-boot-starter-2.1.6.RELEASE.jar /test12345/lib/spring-boot-actuator-autoconfigure-2.1.6.RELEASE.jar /test12345/lib/micrometer-core-1.1.5.jar /test12345/lib/spring-boot-starter-tomcat-2.1.6.RELEASE.jar /test12345/lib/hibernate-validator-6.0.17.Final.jar /test12345/lib/spring-webmvc-5.1.8.RELEASE.jar /test12345/lib/spring-web-5.1.8.RELEASE.jar /test12345/lib/jackson-datatype-jsr310-2.9.9.jar /test12345/lib/jackson-datatype-jdk8-2.9.9.jar /test12345/lib/jackson-module-parameter-names-2.9.9.jar /test12345/lib/jackson-databind-2.9.9.jar /test12345/lib/vault-java-driver-3.1.0.jar /test12345/lib/cglib-nodep-3.2.5.jar /test12345/lib/jackson-dataformat-yaml-2.9.8.jar /test12345/lib/frigga-0.18.0.jar /test12345/lib/jsr305-3.0.1.jar /test12345/lib/disruptor-3.3.7.jar /test12345/lib/spring-boot-autoconfigure-2.1.6.RELEASE.jar /test12345/lib/spring-boot-actuator-2.1.6.RELEASE.jar /test12345/lib/spring-boot-2.1.6.RELEASE.jar /test12345/lib/javax.annotation-api-1.3.2.jar /test12345/lib/spring-context-5.1.8.RELEASE.jar /test12345/lib/spring-aop-5.1.8.RELEASE.jar /test12345/lib/spring-beans-5.1.8.RELEASE.jar /test12345/lib/spring-expression-5.1.8.RELEASE.jar /test12345/lib/spring-core-5.1.8.RELEASE.jar /test12345/lib/snakeyaml-1.23.jar /test12345/lib/HdrHistogram-2.1.9.jar /test12345/lib/LatencyUtils-2.0.3.jar /test12345/lib/tomcat-embed-websocket-9.0.21.jar /test12345/lib/tomcat-embed-core-9.0.21.jar /test12345/lib/tomcat-embed-el-9.0.21.jar /test12345/lib/validation-api-2.0.1.Final.jar /test12345/lib/jboss-logging-3.3.2.Final.jar /test12345/lib/classmate-1.3.4.jar /test12345/lib/jackson-core-2.9.9.jar /test12345/lib/spring-jcl-5.1.8.RELEASE.jar /test12345/lib/jackson-annotations-2.9.0.jar /test12345/lib/tomcat-annotations-api-9.0.21.jar /test12345/bin /test12345/bin/test12345.bat /test12345/bin/test12345]
DEBU[0031] Added [/test12345 /test12345/lib /test12345/lib/test12345-0.0.1.jar /test12345/lib/platform-connector-spring-boot-2.0.4.jar /test12345/lib/spring-boot-starter-actuator-2.1.6.RELEASE.jar /test12345/lib/spring-boot-starter-web-2.1.6.RELEASE.jar /test12345/lib/spring-boot-starter-log4j2-2.1.6.RELEASE.jar /test12345/lib/platform-connector-metrics3-2.0.4.jar /test12345/lib/platform-connector-logging-log4j-2.0.4.jar /test12345/lib/platform-connector-core-2.0.4.jar /test12345/lib/metrics-spring-3.1.3.jar /test12345/lib/log4j-slf4j-impl-2.11.2.jar /test12345/lib/jul-to-slf4j-1.7.26.jar /test12345/lib/metrics-jvm-3.2.6.jar /test12345/lib/hdrhistogram-metrics-reservoir-1.1.2.jar /test12345/lib/metrics-core-3.2.6.jar /test12345/lib/metrics-healthchecks-3.1.2.jar /test12345/lib/metrics-annotation-3.1.2.jar /test12345/lib/slf4j-api-1.7.26.jar /test12345/lib/log4j-jul-2.11.2.jar /test12345/lib/log4j-core-2.11.2.jar /test12345/lib/log4j-api-2.11.2.jar /test12345/lib/spring-boot-starter-json-2.1.6.RELEASE.jar /test12345/lib/spring-boot-starter-2.1.6.RELEASE.jar /test12345/lib/spring-boot-actuator-autoconfigure-2.1.6.RELEASE.jar /test12345/lib/micrometer-core-1.1.5.jar /test12345/lib/spring-boot-starter-tomcat-2.1.6.RELEASE.jar /test12345/lib/hibernate-validator-6.0.17.Final.jar /test12345/lib/spring-webmvc-5.1.8.RELEASE.jar /test12345/lib/spring-web-5.1.8.RELEASE.jar /test12345/lib/jackson-datatype-jsr310-2.9.9.jar /test12345/lib/jackson-datatype-jdk8-2.9.9.jar /test12345/lib/jackson-module-parameter-names-2.9.9.jar /test12345/lib/jackson-databind-2.9.9.jar /test12345/lib/vault-java-driver-3.1.0.jar /test12345/lib/cglib-nodep-3.2.5.jar /test12345/lib/jackson-dataformat-yaml-2.9.8.jar /test12345/lib/frigga-0.18.0.jar /test12345/lib/jsr305-3.0.1.jar /test12345/lib/disruptor-3.3.7.jar /test12345/lib/spring-boot-autoconfigure-2.1.6.RELEASE.jar /test12345/lib/spring-boot-actuator-2.1.6.RELEASE.jar /test12345/lib/spring-boot-2.1.6.RELEASE.jar /test12345/lib/javax.annotation-api-1.3.2.jar /test12345/lib/spring-context-5.1.8.RELEASE.jar /test12345/lib/spring-aop-5.1.8.RELEASE.jar /test12345/lib/spring-beans-5.1.8.RELEASE.jar /test12345/lib/spring-expression-5.1.8.RELEASE.jar /test12345/lib/spring-core-5.1.8.RELEASE.jar /test12345/lib/snakeyaml-1.23.jar /test12345/lib/HdrHistogram-2.1.9.jar /test12345/lib/LatencyUtils-2.0.3.jar /test12345/lib/tomcat-embed-websocket-9.0.21.jar /test12345/lib/tomcat-embed-core-9.0.21.jar /test12345/lib/tomcat-embed-el-9.0.21.jar /test12345/lib/validation-api-2.0.1.Final.jar /test12345/lib/jboss-logging-3.3.2.Final.jar /test12345/lib/classmate-1.3.4.jar /test12345/lib/jackson-core-2.9.9.jar /test12345/lib/spring-jcl-5.1.8.RELEASE.jar /test12345/lib/jackson-annotations-2.9.0.jar /test12345/lib/tomcat-annotations-api-9.0.21.jar /test12345/bin /test12345/bin/test12345.bat /test12345/bin/test12345] from local tar archive build/distributions/test12345.tar 
INFO[0031] Taking snapshot of files...                  
DEBU[0031] Taking snapshot of files [/test12345 /test12345/lib /test12345/lib/test12345-0.0.1.jar /test12345/lib/platform-connector-spring-boot-2.0.4.jar /test12345/lib/spring-boot-starter-actuator-2.1.6.RELEASE.jar /test12345/lib/spring-boot-starter-web-2.1.6.RELEASE.jar /test12345/lib/spring-boot-starter-log4j2-2.1.6.RELEASE.jar /test12345/lib/platform-connector-metrics3-2.0.4.jar /test12345/lib/platform-connector-logging-log4j-2.0.4.jar /test12345/lib/platform-connector-core-2.0.4.jar /test12345/lib/metrics-spring-3.1.3.jar /test12345/lib/log4j-slf4j-impl-2.11.2.jar /test12345/lib/jul-to-slf4j-1.7.26.jar /test12345/lib/metrics-jvm-3.2.6.jar /test12345/lib/hdrhistogram-metrics-reservoir-1.1.2.jar /test12345/lib/metrics-core-3.2.6.jar /test12345/lib/metrics-healthchecks-3.1.2.jar /test12345/lib/metrics-annotation-3.1.2.jar /test12345/lib/slf4j-api-1.7.26.jar /test12345/lib/log4j-jul-2.11.2.jar /test12345/lib/log4j-core-2.11.2.jar /test12345/lib/log4j-api-2.11.2.jar /test12345/lib/spring-boot-starter-json-2.1.6.RELEASE.jar /test12345/lib/spring-boot-starter-2.1.6.RELEASE.jar /test12345/lib/spring-boot-actuator-autoconfigure-2.1.6.RELEASE.jar /test12345/lib/micrometer-core-1.1.5.jar /test12345/lib/spring-boot-starter-tomcat-2.1.6.RELEASE.jar /test12345/lib/hibernate-validator-6.0.17.Final.jar /test12345/lib/spring-webmvc-5.1.8.RELEASE.jar /test12345/lib/spring-web-5.1.8.RELEASE.jar /test12345/lib/jackson-datatype-jsr310-2.9.9.jar /test12345/lib/jackson-datatype-jdk8-2.9.9.jar /test12345/lib/jackson-module-parameter-names-2.9.9.jar /test12345/lib/jackson-databind-2.9.9.jar /test12345/lib/vault-java-driver-3.1.0.jar /test12345/lib/cglib-nodep-3.2.5.jar /test12345/lib/jackson-dataformat-yaml-2.9.8.jar /test12345/lib/frigga-0.18.0.jar /test12345/lib/jsr305-3.0.1.jar /test12345/lib/disruptor-3.3.7.jar /test12345/lib/spring-boot-autoconfigure-2.1.6.RELEASE.jar /test12345/lib/spring-boot-actuator-2.1.6.RELEASE.jar /test12345/lib/spring-boot-2.1.6.RELEASE.jar /test12345/lib/javax.annotation-api-1.3.2.jar /test12345/lib/spring-context-5.1.8.RELEASE.jar /test12345/lib/spring-aop-5.1.8.RELEASE.jar /test12345/lib/spring-beans-5.1.8.RELEASE.jar /test12345/lib/spring-expression-5.1.8.RELEASE.jar /test12345/lib/spring-core-5.1.8.RELEASE.jar /test12345/lib/snakeyaml-1.23.jar /test12345/lib/HdrHistogram-2.1.9.jar /test12345/lib/LatencyUtils-2.0.3.jar /test12345/lib/tomcat-embed-websocket-9.0.21.jar /test12345/lib/tomcat-embed-core-9.0.21.jar /test12345/lib/tomcat-embed-el-9.0.21.jar /test12345/lib/validation-api-2.0.1.Final.jar /test12345/lib/jboss-logging-3.3.2.Final.jar /test12345/lib/classmate-1.3.4.jar /test12345/lib/jackson-core-2.9.9.jar /test12345/lib/spring-jcl-5.1.8.RELEASE.jar /test12345/lib/jackson-annotations-2.9.0.jar /test12345/lib/tomcat-annotations-api-9.0.21.jar /test12345/bin /test12345/bin/test12345.bat /test12345/bin/test12345] 

Dockerfile for reference looks like

FROM openjdk:8-jre-alpine

ADD build/distributions/test12345.tar /

ENTRYPOINT ["/test12345/bin/test12345"]

@googlebot
Copy link

Thanks for your pull request. It looks like this may be your first contribution to a Google open source project (if not, look below for help). Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

📝 Please visit https://cla.developers.google.com/ to sign.

Once you've signed (or fixed any issues), please reply here with @googlebot I signed it! and we'll verify it.


What to do if you already signed the CLA

Individual signers
Corporate signers

ℹ️ Googlers: Go here for more info.

@loganprice
Copy link
Contributor Author

@googlebot I signed it!

@googlebot
Copy link

We found a Contributor License Agreement for you (the sender of this pull request), but were unable to find agreements for all the commit author(s) or Co-authors. If you authored these, maybe you used a different email address in the git commits than was used to sign the CLA (login here to double check)? If these were authored by someone else, then they will need to sign a CLA as well, and confirm that they're okay with these being contributed to Google.
In order to pass this check, please resolve this problem and then comment @googlebot I fixed it.. If the bot doesn't comment, it means it doesn't think anything has changed.

ℹ️ Googlers: Go here for more info.

@loganprice
Copy link
Contributor Author

@googlebot I fixed it.

@googlebot
Copy link

CLAs look good, thanks!

ℹ️ Googlers: Go here for more info.

@@ -175,7 +175,7 @@ func unTar(r io.Reader, dest string) ([]string, error) {
if err := extractFile(dest, hdr, tr); err != nil {
return nil, err
}
extractedFiles = append(extractedFiles, dest)
extractedFiles = append(extractedFiles, filepath.Join(dest, filepath.Clean(hdr.Name)))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@loganprice Can you please add tests for it.

  • That would help prevent future breakage.
  • It would help reviewers understand the impact of the change.

Thanks
Tejal

Copy link
Contributor Author

@loganprice loganprice Sep 30, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@tejal29 Unit test have been added

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@tejal29 just curious to then PRs get reviewed? I added a unit test as requested.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking now @loganprice

tejal29
tejal29 previously approved these changes Oct 4, 2019
@tejal29
Copy link
Contributor

tejal29 commented Oct 4, 2019

will merge once test pass.

@tejal29
Copy link
Contributor

tejal29 commented Oct 4, 2019

hmm looks like the integration test test_Dockerfile_test_add failed

TestRun/test_Dockerfile_test_add (10.74s)
        integration_test.go:224: diff = [
              {
                "Image1": "gcr.io/kaniko-test/docker-dockerfile_test_add",
                "Image2": "gcr.io/kaniko-test/kaniko-dockerfile_test_add",
                "DiffType": "File",
                "Diff": {
                  "Adds": [
                    {
                      "Name": "/otherdestination",
                      "Size": 2505763
                    }
                  ],
                  "Dels": [
                    {
                      "Name": "/sys/fs",
                      "Size": 0
                    },
                    {
                      "Name": "/sys/fs/foo",
                      "Size": 0
                    }
                  ],
                  "Mods": [
                    {
                      "Name": "/newdir/integration_test.go",
                      "Size1": 14824,
                      "Size2": 14824
                    },
                    {
                      "Name": "/newdir/dockerfiles/Dockerfile_test_add",
                      "Size1": 1080,
                      "Size2": 1275
                    }
                  ]
                }
              },
              {
                "Image1": "gcr.io/kaniko-test/docker-dockerfile_test_add",
                "Image2": "gcr.io/kaniko-test/kaniko-dockerfile_test_add",
                "DiffType": "Metadata",
                "Diff": {
                  "Adds": [
                    "Env: DEBIAN_FRONTEND=noninteractive,PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin,PORT=8080,contextenv=./context,VERSION=v1.4.3,URL=https://github.com/GoogleCloudPlatform/docker-credential-gcr/releases/download/v1.4.3/docker-credential-gcr_linux_386-1.4.3.tar.gz"
                  ],
                  "Dels": [
                    "Env: DEBIAN_FRONTEND=noninteractive,PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin,PORT=8080,contextenv=./context,VERSION=v1.4.3"
                  ]
                }
              }
            ]
        integration_test.go:227: json: cannot unmarshal string into Go struct field .Adds of type integration.fileDiff
        integration_test.go:227: []integration.diffOutput differ (-got, +want): {[]integration.diffOutput}[0].Diff.Adds:
            	-: []integration.fileDiff{{Name: "/otherdestination", Size: 2505763}}
            	+: []integration.fileDiff(nil)
            {[]integration.diffOutput}[1].Diff.Adds[0->?]:
            	-: integration.fileDiff{}
            	+: <non-existent>
            {[]integration.diffOutput}[1].Diff.Dels[0->?]:
            	-: integration.fileDiff{}
            	+: <non-existent>

@tejal29 tejal29 self-requested a review October 4, 2019 08:28
@tejal29 tejal29 dismissed their stale review October 4, 2019 08:29

kokoro tests failed

@tejal29
Copy link
Contributor

tejal29 commented Oct 4, 2019

@iciclespider
Copy link

I just bumped into this bug and am wondering what the status is? What is needed to get this merged?

@iciclespider
Copy link

I created the following Issue that demonstrates that this PR is fixing an outright bug: ADD of local tar fails if last layer of stage

@cvgw
Copy link
Contributor

cvgw commented Dec 22, 2019

rebased against master

@googlebot googlebot added the cla: yes CLA signed by all commit authors label Dec 22, 2019
@cvgw
Copy link
Contributor

cvgw commented Dec 23, 2019

@tejal29 looks like the integration tests passed after rebasing against master

@tejal29 tejal29 merged commit b1970a3 into GoogleContainerTools:master Jan 21, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cla: yes CLA signed by all commit authors
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants