diff --git a/CHANGELOG.md b/CHANGELOG.md
index 11af454354..3370daaf4c 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -11,3 +11,4 @@ All notable changes to this project will be documented in this file.
## 0.1.1
### Added
- Simple example `helloworld` project under `examples/` ([#62](https://github.com/google/jib/pull/62))
+- Infers common credential helper names (for GCR and ECR) ([#64](https://github.com/google/jib/pull/64))
diff --git a/README.md b/README.md
index 530b526412..bd584fb894 100644
--- a/README.md
+++ b/README.md
@@ -41,7 +41,7 @@ Configure the plugin by changing `registry`, `repository`, and `credentialHelper
#### I am using Google Container Registry (GCR)
-*Make sure you have the [`docker-credential-gcr` command line tool](https://cloud.google.com/container-registry/docs/advanced-authentication#docker_credential_helper).*
+*Make sure you have the [`docker-credential-gcr` command line tool](https://cloud.google.com/container-registry/docs/advanced-authentication#docker_credential_helper). Jib automatically uses `docker-credential-gcr` for obtaining credentials. To use a different credential helper, set the [`credentialHelperName`](#extended-usage) configuration.*
For example, to build the image `gcr.io/my-gcp-project/my-app`, the configuration would be:
@@ -49,13 +49,12 @@ For example, to build the image `gcr.io/my-gcp-project/my-app`, the configuratio
gcr.io
my-gcp-project/my-app
- gcr
```
#### I am using Amazon Elastic Container Registry (ECR)
-*Make sure you have the [`docker-credential-ecr-login` command line tool](https://github.com/awslabs/amazon-ecr-credential-helper).*
+*Make sure you have the [`docker-credential-ecr-login` command line tool](https://github.com/awslabs/amazon-ecr-credential-helper). Jib automatically uses `docker-credential-ecr-login` for obtaining credentials. To use a different credential helper, set the [`credentialHelperName`](#extended-usage) configuration.*
For example, to build the image `aws_account_id.dkr.ecr.region.amazonaws.com/my-app`, the configuration would be:
@@ -63,7 +62,6 @@ For example, to build the image `aws_account_id.dkr.ecr.region.amazonaws.com/my-
aws_account_id.dkr.ecr.region.amazonaws.com
my-app
- ecr-login
```
diff --git a/jib-maven-plugin/src/main/java/com/google/cloud/tools/jib/maven/BuildImageMojo.java b/jib-maven-plugin/src/main/java/com/google/cloud/tools/jib/maven/BuildImageMojo.java
index 8fede77960..87342894b9 100644
--- a/jib-maven-plugin/src/main/java/com/google/cloud/tools/jib/maven/BuildImageMojo.java
+++ b/jib-maven-plugin/src/main/java/com/google/cloud/tools/jib/maven/BuildImageMojo.java
@@ -55,6 +55,19 @@ public class BuildImageMojo extends AbstractMojo {
/** {@code User-Agent} header suffix to send to the registry. */
private static final String USER_AGENT_SUFFIX = "jib-maven-plugin";
+ /** Attempts to infer a known credential helper name from a specified registry. */
+ @VisibleForTesting
+ @Nullable
+ static String inferCredentialHelperName(String registry) {
+ if (registry.endsWith("gcr.io")) {
+ return "gcr";
+
+ } else if (registry.endsWith("amazonaws.com")) {
+ return "ecr-login";
+ }
+ return null;
+ }
+
@Parameter(defaultValue = "${project}", readonly = true)
private MavenProject project;
@@ -101,6 +114,18 @@ public void execute() throws MojoExecutionException, MojoFailureException {
// Parse 'from' into image reference.
ImageReference baseImage = getImageReference();
+ // Infer common credential helper names if credentialHelperName is not set.
+ if (credentialHelperName == null) {
+ credentialHelperName = inferCredentialHelperName(registry);
+ if (credentialHelperName != null) {
+ getLog()
+ .info(
+ "Using docker-credential-"
+ + credentialHelperName
+ + " for authentication - specify a 'credentialHelperName' to override");
+ }
+ }
+
BuildConfiguration buildConfiguration =
BuildConfiguration.builder()
.setBuildLogger(new MavenBuildLogger(getLog()))
diff --git a/jib-maven-plugin/src/test/java/com/google/cloud/tools/jib/maven/BuildImageMojoTest.java b/jib-maven-plugin/src/test/java/com/google/cloud/tools/jib/maven/BuildImageMojoTest.java
index 0f8aab9892..c67084c946 100644
--- a/jib-maven-plugin/src/test/java/com/google/cloud/tools/jib/maven/BuildImageMojoTest.java
+++ b/jib-maven-plugin/src/test/java/com/google/cloud/tools/jib/maven/BuildImageMojoTest.java
@@ -42,6 +42,17 @@ public class BuildImageMojoTest {
private final BuildImageMojo testBuildImageMojo = new BuildImageMojo();
+ @Test
+ public void testInferCredentialHelperName() {
+ Assert.assertEquals("gcr", BuildImageMojo.inferCredentialHelperName("gcr.io"));
+ Assert.assertEquals("gcr", BuildImageMojo.inferCredentialHelperName("asia.gcr.io"));
+ Assert.assertEquals("ecr-login", BuildImageMojo.inferCredentialHelperName("amazonaws.com"));
+ Assert.assertEquals(
+ "ecr-login",
+ BuildImageMojo.inferCredentialHelperName("aws_account_id.dkr.ecr.region.amazonaws.com"));
+ Assert.assertNull(BuildImageMojo.inferCredentialHelperName("localhost"));
+ }
+
@Test
public void testBuildImage_pass() throws MojoExecutionException {
testBuildImageMojo.buildImage(mockBuildImageSteps);