gradle-docker-plugin: dockerPushImage: Docker credential helpers don't apply
First of all, thank you for the awesome plugin! Couldn’t find your patreon page though…
Expected Behavior
./gradlew dockerPushImage should work on a properly tagged image (docker push <mytag> works fine).
Current Behavior
./gradlew dockerPushImage fails with error
> Could not push image: unauthorized: You don't have the needed permissions to perform this operation, and you may have invalid credentials. To authenticate your request, follow the steps in: https://cloud.google.com/container-registry/docs/advanced-authentication
However, if I do docker push gcr.io/my-project/my-image then it works fine. Because I already followed the steps by that link above and did gcloud auth configure-docker. Looks like it wrote auth tokens to gcr.io to ~/.docker/config.json. So it seems like gradle-docker-plugin just doesn’t use it.
Context
I have the following in my gradle.build.kts:
tasks {
docker {
// https://bmuschko.github.io/gradle-docker-plugin/#java-application-plugin
javaApplication {
baseImage.set("openjdk:11-jre-slim")
maintainer.set("")
ports.set(listOf())
tag.set("gcr.io/my-project/my-image")
}
}
}
And the following in ~/.docker/config.json:
"credHelpers": {
"asia.gcr.io": "gcloud",
"eu.gcr.io": "gcloud",
"gcr.io": "gcloud",
"marketplace.gcr.io": "gcloud",
"staging-k8s.gcr.io": "gcloud",
"us.gcr.io": "gcloud"
}
Your Environment
id(“com.bmuschko.docker-java-application”) version “4.4.0” Docker version 18.09.1, build 4c52b90 Google Cloud SDK 231.0.0
About this issue
- Original URL
- State: closed
- Created 5 years ago
- Comments: 20 (11 by maintainers)
I am currently working on https://github.com/bmuschko/gradle-docker-plugin/issues/728 so that should make it easier to navigate the Docker Java API. But definitely feel free to get started.
@cdancy if you would like so, I can contribute RegistryAuthLocator from the above PR to docker-plugin. The issue above seems to be open for since Nove on the docker-java side… What do you think?
It even builds on docker-java! Maybe we can just rip what we need out and call it a day 😃
For inspiration: The TestContainers project tries to discover existing authentication. See https://github.com/testcontainers/testcontainers-java/blob/master/core/src/main/java/org/testcontainers/utility/RegistryAuthLocator.java.
@cdancy I am planning to have a look at it tomorrow.
@orzeh I know 😉 Ok let me throw together a PR this weekend and I’ll tag you guys. Hopefully nothing pops. Devs here have asked similar things as well so to just have this magically work I think would be a win.
@cdancy IMO sounds good. Ideally it should be done in
docker-java, but … you know 😃@cdancy You might have to set some option here: https://github.com/bmuschko/gradle-docker-plugin/blob/master/src/main/groovy/com/bmuschko/gradle/docker/tasks/AbstractDockerRemoteApiTask.groovy#L136-L159 or we are overwriting the behavior somewhere. Didn’t have the chance to look at it yet.