Skip to content

Replace deprecated checkAndPullImage with RemoteDockerImage#5148

Merged
bsideup merged 8 commits intomasterfrom
deprecate_checkAndPullImage
Mar 28, 2022
Merged

Replace deprecated checkAndPullImage with RemoteDockerImage#5148
bsideup merged 8 commits intomasterfrom
deprecate_checkAndPullImage

Conversation

@bsideup
Copy link
Copy Markdown
Member

@bsideup bsideup commented Mar 3, 2022

No description provided.

@bsideup bsideup added this to the next milestone Mar 3, 2022
@bsideup bsideup requested review from kiview and rnorth as code owners March 3, 2022 22:52
Comment thread core/src/test/java/org/testcontainers/utility/AuthenticatedImagePullTest.java Outdated
@bsideup bsideup requested a review from rnorth March 4, 2022 11:59
Copy link
Copy Markdown
Member

@kiview kiview left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM and nice cleanup 👍

@bsideup bsideup merged commit 02782d9 into master Mar 28, 2022
@delete-merged-branch delete-merged-branch Bot deleted the deprecate_checkAndPullImage branch March 28, 2022 15:13
@perlun
Copy link
Copy Markdown
Contributor

perlun commented Oct 27, 2022

@bsideup and others, while this is probably a great change, it's quite hard for me as a user to understand how I should edit my code to use the new API. 🤔 I looked but I couldn't find anything obvious in the release notes.

use {@link RemoteDockerImage} doesn't tell me very much about how I should use that class. I gave it a try but it felt a bit non-obvious.

What we have (with 1.15.1) is something like this:

DockerClientFactory clientFactory = DockerClientFactory.instance()

try {
    clientFactory.checkAndPullImage(
            clientFactory.client(),
            containerName
    );

    return true;
}
catch ( NotFoundException e ) {
    return false;
}

In other words: attempt to pull an image, return true if it exists; otherwise, false. What's the easiest way to transform the above to use RemoteDockerImage?

@kiview
Copy link
Copy Markdown
Member

kiview commented Oct 27, 2022

Hey @perlun, can you give us the context/use-case of the code? Else it's hard to recommend what you should do instead.

@perlun
Copy link
Copy Markdown
Contributor

perlun commented Nov 16, 2022

@kiview - the use case is to check if a specifically named remote container exist or not, and if not, choose a different code path (using another image without a pre-seeded DB structure and then create the DB structure manually instead). But one of my colleagues already solved this I think, without me even knowing about it. 🙂 Here's the replacement code, sharing it in the hope that it will be useful to others:

        try {
            DockerImageName dockerImageName = DockerImageName.parse( preSeededDbContainerName );
            RemoteDockerImage remoteDockerImage = new RemoteDockerImage( dockerImageName );
            remoteDockerImage.get();
            return true;
        }
        catch ( ContainerFetchException e ) {
            return false;
        }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants