gradle-docker-plugin: Do not parse config file if it doesn't exist

Hi,

First off, thanks for producing such a useful plugin, I use it a lot and think it is great!

I have recently updated one of my projects to use version 6.0.0 and I have everything working fine, but I am finding that an exception is thrown and logged which is creating a bit of noise in my logs, so I was wondering if there might be a way around it?

It seems to be coming from the way the plugin is trying to lookup auth config, I wondered if it might just be the setup on my local mac, but it is happening on my travis CI builds too (the project is private at the moment but I was planning on making it public soon, I can do that earlier if seeing the whole logs would help?)

The exception that is being thrown is:

Failure when attempting to lookup auth config (docker repository: , configFile: /home/travis/.docker/config.json. Falling back to docker-java default behaviour
groovy.json.JsonException: Unable to process file: /home/travis/.docker/config.json
	at org.apache.groovy.json.internal.BaseJsonParser.parse(BaseJsonParser.java:158)
	at groovy.json.JsonSlurper.parseFile(JsonSlurper.java:365)
	at groovy.json.JsonSlurper.parse(JsonSlurper.java:348)
	at com.bmuschko.gradle.docker.internal.RegistryAuthLocator.lookupAuthConfig(RegistryAuthLocator.groovy:109)
	at com.bmuschko.gradle.docker.internal.RegistryAuthLocator.lookupAuthConfig(RegistryAuthLocator.groovy:81)
	at com.bmuschko.gradle.docker.tasks.image.DockerPushImage.runRemoteCommand(DockerPushImage.groovy:55)
	at com.bmuschko.gradle.docker.tasks.AbstractDockerRemoteApiTask.start(AbstractDockerRemoteApiTask.groovy:73)
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

When I run on my local mac it is similar but not exactly the same, although it does look to be the same sort of problem:

Failure when attempting to lookup auth config (docker repository: , configFile: /Users/michaelruocco/.docker/config.json. Falling back to docker-java default behaviour
groovy.json.JsonException: null not parse properly

The current character read is 'n' with an int value of 110
null not parse properly
line number 1
index number 1
no credentials server URL
.^
        at org.apache.groovy.json.internal.JsonParserCharArray.decodeNull(JsonParserCharArray.java:234)
        at org.apache.groovy.json.internal.JsonParserCharArray.decodeValueInternal(JsonParserCharArray.java:178)
        at org.apache.groovy.json.internal.JsonParserCharArray.decodeValue(JsonParserCharArray.java:157)
        at org.apache.groovy.json.internal.JsonParserCharArray.decodeFromChars(JsonParserCharArray.java:46)
        at org.apache.groovy.json.internal.JsonParserCharArray.parse(JsonParserCharArray.java:384)
        at org.apache.groovy.json.internal.BaseJsonParser.parse(BaseJsonParser.java:112)
        at groovy.json.JsonSlurper.parseText(JsonSlurper.java:205)
        at com.bmuschko.gradle.docker.internal.RegistryAuthLocator.runCredentialProvider(RegistryAuthLocator.groovy:252)
        at com.bmuschko.gradle.docker.internal.RegistryAuthLocator.authConfigUsingStore(RegistryAuthLocator.groovy:271)
        at com.bmuschko.gradle.docker.internal.RegistryAuthLocator.lookupAuthConfig(RegistryAuthLocator.groovy:123)
        at com.bmuschko.gradle.docker.internal.RegistryAuthLocator.lookupAuthConfig(RegistryAuthLocator.groovy:81)
        at com.bmuschko.gradle.docker.tasks.image.DockerPushImage.runRemoteCommand(DockerPushImage.groovy:55)

In either case the plugin says that it will fall back to the default behaviour and then my image is still pushed as required so there is no functional problem. I tried to look at the docs and config to see if there was a way to turn off the auth config lookup (with the idea it would make the plugin just use the default behaviour and bypass the auth config lookup, but I wasn’t able to find anything. Feel free to point me in the right direction if I have missed it!

For reference the relevant config that I have in my build.gradle file is:

plugins {
    id 'com.bmuschko.docker-remote-api' version '6.0.0'
}
...
import com.bmuschko.gradle.docker.tasks.image.DockerBuildImage;
import com.bmuschko.gradle.docker.tasks.image.DockerPushImage;
...
docker {
    registryCredentials {
        username = System.getenv("DOCKER_USERNAME")
        password = System.getenv("DOCKER_PASSWORD")
    }
}

task buildImage(type: DockerBuildImage) {
    inputDir.set(file('.'))
    images.add('michaelruocco/verification-context-spring-app:latest')
}

task pushImage(type: DockerPushImage) {
    images.set(buildImage.images)
}

As I said feel free to point me in the right direction if I am just doing something stupid and missing some config, but any input you can offer would be much appreciated!

Thanks.

About this issue

  • Original URL
  • State: closed
  • Created 5 years ago
  • Comments: 43 (18 by maintainers)

Most upvoted comments

I released a new version that addressed the issue of a non-existent config file. Most users in this issue reported that very use case. Please open other, more specific issues for other use cases. Thanks!

I get a similar a different problem when trying to push an image, and the RegistryAuthLocator throws an error $HOME/.docker/config.json file does not exist if the file does not exist (Jenkins on Linux).

As @bmuschko says, at this should not be logged as an error, and I think it should be warn or below. Having no config.json file is not an error condition, and the best thing would be to return the defaultAuthConfig without an error if the configFile does not exist. Having a config.json that cannot be parsed, however, should be logged as a warn.

09:38:59  Failure when attempting to lookup auth config (docker repository: reflex-docker-snapshot.hannover-re.com, configFile: /home/jenkins/.docker/config.json. Falling back to docker-java default behaviour
09:38:59  groovy.json.JsonException: Unable to process file: /home/jenkins/.docker/config.json
09:38:59  	at org.apache.groovy.json.internal.BaseJsonParser.parse(BaseJsonParser.java:158)
09:38:59  	at groovy.json.JsonSlurper.parseFile(JsonSlurper.java:365)
09:38:59  	at groovy.json.JsonSlurper.parse(JsonSlurper.java:348)
09:38:59  	at com.bmuschko.gradle.docker.internal.RegistryAuthLocator.lookupAuthConfig(RegistryAuthLocator.groovy:109)
09:38:59  	at com.bmuschko.gradle.docker.internal.RegistryAuthLocator.lookupAuthConfig(RegistryAuthLocator.groovy:81)
09:38:59  	at com.bmuschko.gradle.docker.tasks.image.DockerPushImage.runRemoteCommand(DockerPushImage.groovy:55)
...
09:38:59  Caused by: java.io.FileNotFoundException: /home/jenkins/.docker/config.json (No such file or directory)
09:38:59  	at java.base/java.io.FileInputStream.open0(Native Method)
09:38:59  	at java.base/java.io.FileInputStream.open(FileInputStream.java:219)
09:38:59  	at java.base/java.io.FileInputStream.<init>(FileInputStream.java:157)
09:38:59  	at groovy.util.CharsetToolkit.<init>(CharsetToolkit.java:79)
09:38:59  	at org.codehaus.groovy.runtime.ResourceGroovyMethods.newReader(ResourceGroovyMethods.java:1776)
09:38:59  	at org.apache.groovy.json.internal.BaseJsonParser.parse(BaseJsonParser.java:152)
09:38:59  	... 90 more

I have added a repo here: https://github.com/michaelruocco/docker-gradle-plugin-bug. Let me know if any useful information is missing or needs to be added.