0

I'm attempting to utilize jib-core to build and push images programmatically. What I wish to achieve is to pull an image from one container cloud registry, and push it to another cloud registry. I believe the code should look something like:

/*
* Generate random text - we use this random generated text to change the sha-256 digest to signify that its a new image
* */
private void generateRandomText() {
    //generate random 4 KB of data and write them to a file
    String uid = UUID.randomUUID().toString();
    try (RandomAccessFile f = new RandomAccessFile(RANDOM_TEXT, "rw")) {
        // an UUID is 36 bytes times 113 makes 4KB
        f.writeBytes(String.join("", Collections.nCopies(113, uid)));
    } catch (IOException e) {
        e.printStackTrace();
    }
}


/**
 * pull and push an image from one registry to another
 * @param fromRegistry - the registry we will be pushing the image from
 * @param toRegistry - the registry we will push the image to
 * */
public void pullAndPushImageToRegistry(String fromRegistry, String toRegistry) {
    generateRandomText();
    try {
        Jib.from(ImageReference.parse(fromRegistry))
                .addLayer(Arrays.asList(Paths.get(RANDOM_TEXT)), AbsoluteUnixPath.get("/"))
                .containerize(
                        Containerizer.to(RegistryImage.named(toRegistry)
                                .addCredential("username","password")));
    } catch (InterruptedException | RegistryException | IOException | CacheDirectoryCreationException | ExecutionException | InvalidImageReferenceException e) {
        LOG.error("Failed to push image " + e.getMessage());
        //e.printStackTrace();
    }
}

I'm getting this error of with such a sample for pullAndPushImageToRegistry(otherregistry.azurecr.io/samples/nginx, myregistry.azurecr.io/samples/nginx):

Failed to push image java.lang.NoSuchMethodError: com.google.api.client.http.HttpRequest.setUseRawRedirectUrls(Z)Lcom/google/api/client/http/HttpRequest

and not to sure how to resolve this issue.

AfternoonTiger
  • 357
  • 1
  • 4
  • 10

1 Answers1

2

Your project is pulling in an old version of the Google HTTP Client library that Jib depends on. As of now, the related dependencies and their versions are

  • com.google.http-client:google-http-client:1.38.1
  • com.google.http-client:google-http-client-apache-v2:1.38.1
  • com.google.auth:google-auth-library-oauth2-http:0.22.2 (not part of the Google HTTP Client library, but this depends on it)

It may be that some other project libraries also depend on the Google HTTP Client library (either directly or transitively) and the build system (whether Gradle or Maven) ends up pulling in an old version.

In Gradle and Maven, there are different ways and approaches to resolve this kind of dependency conflicts, and here's an example in Maven.

Chanseok Oh
  • 3,920
  • 4
  • 23
  • 63