简体   繁体   English

使用 Jib 获取特定版本的图像(Maven、Docker、testcontainers)

[英]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:到目前为止,这是我所知道或已经想到的:

  1. 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.) (这就是我的知识结束的地方。)

  2. 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 的某个地方?

  3. 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 的原因。)

  4. 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.

相关问题 java maven docker jib 发布端口失败 - java maven docker jib published port fails 离线使用 jib maven 插件构建 docker 容器的问题 - Problem with using jib maven plugin offline for building docker container 如何使用 maven jib 插件创建多层图像 - How to create muttilayer image using maven jib plugin 使用jib创建docker镜像时401 Unauthorized - 401 Unauthorized when using jib to create docker image 带有 docker-compose 应用程序的 Google Jib,在将映像重建到 Docker 守护程序后重新启动应用程序的快速方法 - Google Jib with docker-compose application, Fast way to restart application after rebuild image to Docker daemon 使用自定义基础图像使用 jib 构建 docker 图像时出现未经授权的错误 - Unauthorized error when build docker image with jib, using a custom base image ClassNotFoundException - 在构建图像时使用 BitBucket 管道中的 jib-maven-plugin 将其推送到 GCR - ClassNotFoundException - when building the image & push it to GCR using jib-maven-plugin in BitBucket pipeline Maven JIB:创建 Docker 图像,POM.xml 中定义的多次执行? - Maven JIB: Creating Docker images, multiple executions defined in POM.xml? golang项目是否有任何替代JIB,它使用dockerfile创建docker图像 - Is there any alternative of JIB for golang project, which creates the docker image withour using dockerfile 使用 Jib 插件的 Docker 图像:容器运行时无法在本地命中 rest 端点? - Docker image using Jib plugin: Cant hit rest endpoint locally when container running?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM