Skip to content

Commit

Permalink
Honour DOCKER_CONFIG env var in jib the same way as in jib-core
Browse files Browse the repository at this point in the history
Support for DOCKER_CONFIG has been added in #27460. However, in jib,
the DOCKER_CONFIG should point to a directory containing a `config.json`,
while in the quarkus implementation it must point to the `config.json`
file itself. This is very confusing, especially since there is no
documentation.

This commit fixes the `JibProcessor`, so it behave exactly as described
in the jib documentation (see
https://github.com/GoogleContainerTools/jib/blob/master/jib-maven-plugin/README.md#authentication-methods).
That is, if `DOCKER_CONFIG` is set, it is expected to point to a folder
with a `config.json` file.

To keep backward compatibility, if `DOCKER_CONFIG` points to a file,
it will be left untouched.

See also `com.google.cloud.tools.jib.plugins.common.DefaultCredentialRetrievers.java`.

(cherry picked from commit d5e2991)
  • Loading branch information
derlin authored and gsmet committed Oct 4, 2022
1 parent 44a769e commit 9946571
Showing 1 changed file with 8 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -335,7 +335,13 @@ private RegistryImage toRegistryImage(ImageReference imageReference, Optional<St
registryImage.addCredentialRetriever(credentialRetrieverFactory.dockerConfig());
String dockerConfigEnv = System.getenv().get("DOCKER_CONFIG");
if (dockerConfigEnv != null) {
registryImage.addCredentialRetriever(credentialRetrieverFactory.dockerConfig(Path.of(dockerConfigEnv)));
Path dockerConfigPath = Path.of(dockerConfigEnv);
if (Files.isDirectory(dockerConfigPath)) {
// this matches jib's behaviour,
// see https://github.com/GoogleContainerTools/jib/blob/master/jib-maven-plugin/README.md#authentication-methods
dockerConfigPath = dockerConfigPath.resolve("config.json");
}
registryImage.addCredentialRetriever(credentialRetrieverFactory.dockerConfig(dockerConfigPath));
}
}
return registryImage;
Expand Down Expand Up @@ -804,4 +810,4 @@ public boolean test(Path path) {
return path.getFileName().toString().endsWith(".class");
}
}
}
}

0 comments on commit 9946571

Please sign in to comment.