Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug in ImageData.from(Image) causes AgeBasedPullPolicy to unexpectedly pull #4275

Closed
mr-rycho opened this issue Jul 8, 2021 · 2 comments
Closed

Comments

@mr-rycho
Copy link

mr-rycho commented Jul 8, 2021

The bad fragment of ImageData.from(Image) :

return builder().createdAt(Instant.ofEpochMilli(image.getCreated())).build();

The ofEpochMilli method is used but image.getCreated() returns timestamp as epoch (seconds). This makes all images to be dated to early 1970 and AgeBasedPullPolicy always pulls images from repo, even if local images are new.
Tested with testcontainers 1.15.3
Docker:

Connected to docker: 
  Server Version: 20.10.6
  API Version: 1.41
  Operating System: Docker Desktop
@jjvrensburg
Copy link

This is still an issue in testcontainers 1.17.3.
I created the following class as a workaround:

public class CustomAgeBasedPullPolicy extends AbstractImagePullPolicy {
    Duration maxAge;

    public CustomAgeBasedPullPolicy(Duration maxAge) {
        this.maxAge = maxAge;
    }

    protected boolean shouldPullCached(DockerImageName imageName, ImageData localImageData) {
        Instant now = Instant.now();
        // Instant from image created time which is actually seconds
        Instant createdAt = Instant.ofEpochSecond(localImageData.getCreatedAt().toEpochMilli());
        Duration imageAge = Duration.between(createdAt, now);
        boolean result = imageAge.compareTo(this.maxAge) > 0;
        return result;
    }
}

@kiview
Copy link
Member

kiview commented Aug 12, 2022

Thanks for sharing the workaround @jjvrensburg.
Would you like to contribute a PR to fix the underlying issue?

leblonk added a commit to leblonk/testcontainers-java that referenced this issue Oct 12, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants