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

docker inspect output parsing fails on Windows #2270

Closed
augi opened this issue Feb 7, 2020 · 8 comments · Fixed by #2271
Closed

docker inspect output parsing fails on Windows #2270

augi opened this issue Feb 7, 2020 · 8 comments · Fixed by #2271
Milestone

Comments

@augi
Copy link

augi commented Feb 7, 2020

Environment:

  • Jib version: 2.0.0
  • Build tool: Gradle 5.6.2
  • OS: Windows 10

Description of the issue:
Output from docker inspect is not valid JSON on Windows and so the parsing fails on following error:

Execution failed for task ':jibDockerBuild'.
> com.google.cloud.tools.jib.plugins.common.BuildStepsExecutionException: Unexpected character ('s' (code 115)): was expecting double-quote to start field name
   at [Source: (String)"{size:11421955405,imageId:sha256:68204dc2fc12499d321ef43f00c439bbf2300b280d14737a92841d4b22ddd58c,diffIds:["sha256:f358be10862ccbc329638b9e10b3d497dd7cd28b0e8c7931b4a545c88d7f7cd6","sha256:ffce47ae4ffd0b88677730d9949223ae0f4de9c7b14fd7f23112a1724381dac8","sha256:9fb133e2afa1efc256864786d3fe44c896e171aebb52255e44bc5a6e38024ece","sha256:54f1b480fa3dca5845816d23b22bdb748d0fa22217ae9387121683dfe403da5a","sha256:e2e665092bb91d64c1fab2d3e6b5a80f3a52388badd5df17704f57405c81ad03","sha256:f47af1187470c38"[truncated 422 chars]; line: 1, column: 3]

See also this report

The docker inspect is issued when using base Docker image from daemon (instead of from registry), see the docker:// prefix below. It's possible that docker inspect is used also in different use-cases.

Expected behavior:
jib doesn't fail on invalid JSON parsing, when running on Windows and using base image from Docker daemon.

Steps to reproduce:

  1. Use build.gradle as shown below.
  2. Execute jibDockerBuild.

jib-gradle-plugin Configuration:

jib {
  from {
        image = 'docker://my-image:1.0.0'
  }
}

Log output:

Execution failed for task ':server:jibDockerBuild'.
> com.google.cloud.tools.jib.plugins.common.BuildStepsExecutionException: Unexpected character ('s' (code 115)): was expecting double-quote to start field name
   at [Source: (String)"{size:513050736,imageId:sha256:6bf020e553c504672ab41c4ee45c008d331aba465ad0f8d99752d75aa830b7c4,diffIds:["sha256:d69483a6face4499acb974449d1303591fcbb5cdce5420f36f8a6607bda11854","sha256:fa546c09dbca96caa9a87ce37518b215364492deeb58dc8f4e5884ed65ae67ad","sha256:fab7516865bc195a22c493e9a7222c8e42ebf21c0d78f443c0d0bd53a0abae84","sha256:8741a416c3f1340e9cd95c049332b5c7dbbee05d8c3cbe52dd67dd48ab760d4f","sha256:7fef8cf5257ba113bf651c0acfec5f5a03ea5c872b1f31f8ca7b968bc6d20f81"]}"; line: 1, column: 3]

Additional Information:
The problem is in this method. If I tried to execute the command manually then I really got invalid JSON:

D:\Work>docker inspect -f "{"size":{{.Size}},"imageId":"{{.Id}}","diffIds":{{json .RootFS.Layers}}}" --type image openjdk:11.0.1-windowsservercore-ltsc2016
{size:11421955405,imageId:sha256:68204dc2fc12499d321ef43f00c439bbf2300b280d14737a92841d4b22ddd58c,diffIds:["sha256:f358be10862ccbc329638b9e10b3d497dd7cd28b0e8c7931b4a545c88d7f7cd6","sha256:ffce47ae4ffd0b88677730d9949223ae0f4de9c7b14fd7f23112a1724381dac8","sha256:9fb133e2afa1efc256864786d3fe44c896e171aebb52255e44bc5a6e38024ece","sha256:54f1b480fa3dca5845816d23b22bdb748d0fa22217ae9387121683dfe403da5a","sha256:e2e665092bb91d64c1fab2d3e6b5a80f3a52388badd5df17704f57405c81ad03","sha256:f47af1187470c38d468414f8ff92ac928930386da466c0d6b27bb8f5b37c7442","sha256:a89f3bd646ef45a00237d10e870b50b16d0f203ea970be8f07588e071dd2020d","sha256:3951066b4972f280ccdbaa3fd59ae91e295e1cc38b138a14d7d377e16ee992bd","sha256:cfd212e34afa290dc5c780eb684c56477f21f1803af3341fbef59a38a18048a7","sha256:68d52bc69bc5310bb9d442ac1a828355146e698a72ff3639bb192ba14579eaf4","sha256:8baf500f12aeb8dadde42b0aa8bf444e201001170145952838a1e84c74802bfa"]}

The solution is to use triple-doublequotes to ensure doublequotes are present in the output:

D:\Work>docker inspect -f "{"""size""":{{.Size}},"""imageId""":"""{{.Id}}""","""diffIds""":{{json .RootFS.Layers}}}" --type image openjdk:11.0.1-windowsservercore-ltsc2016
{"size":11421955405,"imageId":"sha256:68204dc2fc12499d321ef43f00c439bbf2300b280d14737a92841d4b22ddd58c","diffIds":["sha256:f358be10862ccbc329638b9e10b3d497dd7cd28b0e8c7931b4a545c88d7f7cd6","sha256:ffce47ae4ffd0b88677730d9949223ae0f4de9c7b14fd7f23112a1724381dac8","sha256:9fb133e2afa1efc256864786d3fe44c896e171aebb52255e44bc5a6e38024ece","sha256:54f1b480fa3dca5845816d23b22bdb748d0fa22217ae9387121683dfe403da5a","sha256:e2e665092bb91d64c1fab2d3e6b5a80f3a52388badd5df17704f57405c81ad03","sha256:f47af1187470c38d468414f8ff92ac928930386da466c0d6b27bb8f5b37c7442","sha256:a89f3bd646ef45a00237d10e870b50b16d0f203ea970be8f07588e071dd2020d","sha256:3951066b4972f280ccdbaa3fd59ae91e295e1cc38b138a14d7d377e16ee992bd","sha256:cfd212e34afa290dc5c780eb684c56477f21f1803af3341fbef59a38a18048a7","sha256:68d52bc69bc5310bb9d442ac1a828355146e698a72ff3639bb192ba14579eaf4","sha256:8baf500f12aeb8dadde42b0aa8bf444e201001170145952838a1e84c74802bfa"]}

So IMHO the solution is to use slightly different command, based on current OS.

I'm willing to prepare a PR for this. It would be great if you suggested me the preferred way how to detect Windows OS.

@augi augi changed the title Docker inspect output fails on Windows docker inspect output parsing fails on Windows Feb 7, 2020
@chanseokoh
Copy link
Member

chanseokoh commented Feb 7, 2020

Ah, thanks. I initially thought this is only when the image is a Windows image, but you confirmed in #2215 (comment) that it is a general problem. So looks like anyone on Windows just cannot use a local Docker engine image.

I know we have this code:

That of course requires toLowerCase.

    String osName = properties.getProperty("os.name").toLowerCase(Locale.ENGLISH);

@chanseokoh chanseokoh added this to the v2.1.0 milestone Feb 7, 2020
@augi
Copy link
Author

augi commented Feb 7, 2020

So looks like anyone on Windows just cannot use a local Docker engine image.

Exactly! I've tested it with both Windows Containers and Linux Containers, and the error is still the same.

@chanseokoh
Copy link
Member

Um, hold on. I think we may fix this using a different approach.

@augi
Copy link
Author

augi commented Feb 10, 2020

Thanks! Is a nightly build with this change available? I would like to test it on Windows, maybe there is another issue, so we could move the Windows Containers support more quickly.

@chanseokoh
Copy link
Member

chanseokoh commented Feb 10, 2020

@augi it's easy to build it yourself.

$ git clone https://github.com/GoogleContainerTools/jib.git
$ cd jib
$ ./gradlew :jib-gradle-plugin:install

This will build 2.0.1-SNAPSHOT and install it into your local Maven repo (~/.m2/repository). Then configure your build script at the beginning like

buildscript {
  repositories {
    mavenLocal() // resolve in ~/.m2/repository
    mavenCentral()
  }
  dependencies {
    classpath 'com.google.cloud.tools:jib-gradle-plugin:2.0.1-SNAPSHOT'
  }
}

// instead of using the `plugins` block, use `apply plugin`:
//plugins {
//  id 'com.google.cloud.tools.jib' version '2.0.0'
//}
apply plugin: 'com.google.cloud.tools.jib'
...

Thanks for testing this out! I'm curious too.

@augi
Copy link
Author

augi commented Feb 12, 2020

@chanseokoh Please see #2288 - this is another issue with Windows Containers. Maybe the fix will be part of #1568

If I can help, just let me know.

@chanseokoh
Copy link
Member

@augi we've release Jib 2.1.0, and at least it will fix this particular issue. However, as you already know, we still have issues like #2288 and #2215. Building Windows containers is basically not supported.

@chanseokoh
Copy link
Member

But at least, you can now load local Docker images on Windows!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants