Jib: docker inspect output parsing fails on Windows

Created on 7 Feb 2020  路  8Comments  路  Source: GoogleContainerTools/jib

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.

All 8 comments

Ah, thanks. I initially thought this is only when the image is a Windows image, but you confirmed in https://github.com/GoogleContainerTools/jib/issues/2215#issuecomment-583482569 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: https://github.com/GoogleContainerTools/jib/blob/2e7b670a44ebdca60b400f8b540eb5c567dd3e11/jib-core/src/main/java/com/google/cloud/tools/jib/filesystem/XdgDirectories.java#L121

That of course requires toLowerCase.

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

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.

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

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.

@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.

@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.

@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.

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

Was this page helpful?
0 / 5 - 0 ratings