gradle-docker-plugin
gradle-docker-plugin copied to clipboard
Can't push images on Windows
I'm trying to use the gradle docker plugin to push docker images to repositories, but it doesn't work on Windows. The reason being that it can't find the docker-credential-gcloud command. For whatever reason on Windows there is a docker-credential-gcr.exe and a docker-credential-gcloud.cmd, and the docker plugin's way of executing processes cannot find and execute a .cmd file.
I did find that I could go into the gcloud installation and copy docker-credential-gcr.exe to docker-credenail-gcloud.exe and that got it working, but that's not very ideal... for obvious reasons.
I had a bit of a poke around in the code, and I'm guessing that it ends up being executed on line 397 ... runCommand of RegistryAuthLocator.groovy. I think the thing to do is to check for Windows there, and prefix the command with "CMD /C".... because running it with CMD /C will mean that it detects and executes a .cmd extension file. Whereas the raw Java process execution can only detect and execute .EXE files.
Happy to accept a pull request for this but I don't have a Windows machine so I can't verify. Our CI job for Windows was hard to set up and we were not able to yet to run functional tests on Windows yet.
Hmm... I don't actually know how to test a modified gradle plugin.
One thing gcloud users have run into is that it seems necessary to manually edit ~/.docker/config to replace all instances of gcloud with gcloud.cmd. I can't remember where exactly you run into problems if you don't do that. But Gradle seems to be able to execute a .cmd provided you have .cmd on the end.
Now that I look at your code, it looks like it decides what to run by reading your config.json, is that right? In which case, if you do that hack, it maybe should work because it will inherit the .cmd file extension.
I'm not such a guru with docker, I know exactly when or if your docker plugin will be running docker-auth-gcloud to know for sure if this thesis is right or not. I just did a push image through the plugin and it worked. I don't know if that means it called that or not, or succeeded because of my hack.
I'm also not sure about the status of this config.json hack, is there some reason I'm one of the few doing it, or is it widespread.
It seems to me, the thing for you to do would be to allow the build script to override the command. In my build script I've got some commands like this:
task blah {
commandLine (Os.isFamily(Os.FAMILY_WINDOWS) ? 'gcloud.cmd' : 'gcloud') blah
}
If your plugin allowed to set the docker helper command that way, it would at least be a workaround.
The other thing is, Google makes available a standalone .exe version:
https://github.com/GoogleCloudPlatform/docker-credential-gcr
But to use that, one would need to override your algorithm for calculating the name of the credential helper to change it from docker-credential-gcloud to docker-credential-gcr.
Sounds reasonable to select a .cmd executable for Windows environments. Any chance you could provide a pull request for this and try it on a Windows machine?
I don't actually know how to integrate a modified plugin into my gradle. Also, I'd prefer to see some configurable helper command, not just another hard coded.
I am going to close this issue. I do not have a Windows machine to try out a potential fix.
Erk, I don't know why you can't just make it configurable, and let us Windows guys set it to what is appropriate.