[英]Getting a specific version of an image with Jib (Maven, Docker, testcontainers)
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.
[ImageResolver] 获取模拟器的特定版本,而不是最新版本。 You need a docker-info file for that though, which jib doesn't automatically generate (but I think it can).
不过,您需要一个 docker-info 文件,jib 不会自动生成该文件(但我认为它可以)。
This is what I know or have figured so far:到目前为止,这是我所知道或已经想到的:
SalesforceFixture is a class that will be used by other projects to write tests. SalesforceFixture 是一个 class,其他项目将使用它来编写测试。 It spins up a container in Docker, running a service that emulates the real service's API.
它在 Docker 中启动一个容器,运行一个模拟真实服务的 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:我查看了
ImageResolver
它似乎是我们编写的 class,它在文件系统中搜索某些东西:
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?
我的本地计算机,无论我从哪里运行 Java 程序? Or is this from within some container?
还是来自某个容器? (I don't think so.) Or maybe the directory structure inside a.jar file?
(我不这么认为。)或者可能是 a.jar 文件中的目录结构? Or somewhere in gcr.io?
或者在 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.)
(这就是让我想到 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.或者,他的意思是,在使用这个项目的镜像的项目中,一个人将无法通过 Maven/pom.xml 指定一个版本——它总是会启动最新的。
Sorry this is long, just trying to "show my work."对不起,这很长,只是想“展示我的作品”。 Any hints welcome.
欢迎任何提示。 I'll keep looking.
我会继续寻找。
I can't comment on specifics of your own internal implementations, but ImageResolver
seems to work on your local filesystem, eg it looks into your target/
directory and also touches the classpath.我无法评论您自己的内部实现的细节,但
ImageResolver
似乎可以在您的本地文件系统上运行,例如,它会查看您的target/
目录并触及类路径。 I can imagine this code was just written for resolving an actual image name (not an image), since it also returns a String
.我可以想象这段代码只是为了解析实际的图像名称(不是图像)而编写的,因为它也返回一个
String
。
Regarding latest
, using a latest
tag for a Docker image is generally considered an anti-pattern, so likely your colleague is commenting about this.关于
latest
,对 Docker 图像使用latest
标签通常被认为是反模式,因此您的同事可能正在对此发表评论。 Here is a random article from the web explaining some of the issues with latest
tag: https://vsupalov.com/docker-latest-tag/这是来自 web 的随机文章,解释了
latest
标签的一些问题: https://vsupalov.com/docker-latest-tag/
Besides, I don't understand why you ask these questions which are very specific to your project here on SO rather than asking your colleague.此外,我不明白你为什么在 SO 上问这些对你的项目非常具体的问题,而不是问你的同事。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.