I'm trying to understand a comment that a colleague made. We're using testcontainers to create a fixture:
import org.testcontainers.containers.GenericContainer;
import org.testcontainers.utility.DockerImageName;
public class SalesforceFixture extends GenericContainer<SalesforceFixture> {
private static final String APPLICATION_NAME = "salesforce-emulator";
public SalesforceFixture() {
// super(ImageResolver.resolve(APPLICATION_NAME));
super(DockerImageName.parse("gcr.io/ad-selfserve/salesforce-emulator:latest"));
...
}
...
The commented code is what it used to be. The next line is my colleague's suggestion. And on that line he commented:
This is the part I don't know. The [ImageResolver] gets the specific version of the emulator, rather than the latest. You need a docker-info file for that though, which jib doesn't automatically generate (but I think it can).
This is what I know or have figured so far:
SalesforceFixture is a class that will be used by other projects to write tests. It spins up a container in Docker, running a service that emulates the real service's API. It's like a local version of the service that behaves enough like the real thing that if one writes code and tests using the fixture, it should work the same in production. (This is where my knowledge ends.)
I looked into
ImageResolver
—it seems to be a class we wrote that searches a filesystem for something:public static String resolve(String applicationName, File... roots) { Stream<File> searchPaths = Arrays.stream(roots).flatMap((value) -> { return Stream.of(new File(value, "../" + applicationName), new File(value, applicationName)); }); Optional<File> buildFile = searchPaths.flatMap((searchFile) -> { if (searchFile.exists()) { File imageFile = new File(searchFile + File.separator + "/target/docker/image-name"); if (imageFile.exists()) { return Stream.of(imageFile); } } return Stream.empty(); }).findAny(); InputStream build = (InputStream)buildFile.map(ImageResolver::fileStream).orElseGet(() -> { return searchClasspath(applicationName); }); if (build != null) { try { return IOUtils.toString(build, Charset.defaultCharset()).trim(); } catch (IOException var6) { throw new RuntimeException("An exception has occurred while reading build file", var6); } } else { throw new RuntimeException("Could not resolve target image for application: " + applicationName); } }
But I'm confused. What filesystem? Like, what is the present working directory? My local computer, wherever I ran the Java program from? Or is this from within some container? (I don't think so.) Or maybe the directory structure inside a .jar file? Or somewhere in gcr.io?
What does he mean about a "specific version number" vs. "latest"? I mean, when I build this project, whatever it built is all I have. Isn't that equivalent to "latest"? In what case would an older version of an image be present? (That's what made me think of gcr.io.)
Or, does he mean, that in the project using this project's image, one will not be able to specify a version via Maven/pom.xml—it will always spin up the latest.
Sorry this is long, just trying to "show my work." Any hints welcome. I'll keep looking.