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.