Container Image

Quarkus 为构建(和推送) 容器镜像提供了一些 extensions 。 当前它支持:

容器镜像 extensions

Jib

quarkus-container-image-jib extension 是由 Jib 提供的,用于构建容器镜像。 使用 Quarkus 的 Jib的主要好处是,所有依赖项 (在 target/lib 下找到的一切) 都被缓存到不同于实际应用程序的层中,使重建真正快而小(当它被推送时)。 使用此 extension 的另外一个好处是它无需额外的客户端工具(像 Docker) 或守护进程(像 Docker daemon)就能创建容器镜像并推送到容器镜像注册中心。

要使用此功能,请在您的项目中添加以下扩展:

./mvnw quarkus:add-extension -Dextensions="container-image-jib"
有时只构建容器镜像不推送到注册中心(主要是设置 quarkus.container-image.build=true 然后留着 quarkus.container-image.push 不设置 - 它默认是 false),此 extension 会创建容器镜像并使用 Docker daemon 注册。 这意味着虽然构建镜像时没有使用 Docker ,但它是必要的。 还请注意,使用此模式构建的容器镜像 在执行 docker images 时看到。

Docker

quarkus-container-image-docker extension 使用 Docker 程序和 src/main/docker 下生成的 Dockerfiles 来执行 Docker 构建。

要使用此功能,请向您的项目添加以下 extension。

./mvnw quarkus:add-extension -Dextensions="container-image-docker"

S2I

quarkus-container-image-s2i extension 使用 S2I binary 以便在 OpenShift 集群内执行容器构建。 二进制构建背后的想法是,你只是将制品及其依赖上传到集群,在构建过程中,它们将被合并到预构建镜像(默认为 fabric8/s2i-java)。

这种方式的好处是,它可以与 OpenShift 的 DeploymentConfig 结合起来,它使得对集群进行更改变得容易。

要使用此功能,请向您的项目添加以下extension。

./mvnw quarkus:add-extension -Dextensions="container-image-s2i"

S2I 构建需要创建一个 BuildConfig 和两个 ImageStream 资源,一个用于 builder image ,另一个用于输出镜像。 Quarkus Kubernetes extension 负责创建这些。

构建

要为您的项目构建一个容器镜像,需要使用 Quarkus 支持的任何方式设置 quarkus.container-image.build=true

./mvnw clean package -Dquarkus.container-image.build=true

推送

要为您的项目构建一个容器镜像,需要使用 Quarkus 支持的任何方式设置 quarkus.container-image.pus=true

./mvnw clean package -Dquarkus.container-image.push=true
如果没有设置注册中心(使用 quarkus.container-image.registry),默认使用 docker.io

定制

以下属性可以用于定制容器镜像构建过程。

容器镜像选项

Configuration property fixed at build time - All other configuration properties are overridable at runtime

Configuration property

Type

Default

The group the container image will be part of

string

${user.name}

The name of the container image. If not set defaults to the application name

string

${quarkus.application.name:unset}

The tag of the container image. If not set defaults to the application version

string

${quarkus.application.version:latest}

The container registry to use

string

The username to use to authenticate with the registry

string

The password to use to authenticate with the registry

string

Whether or not insecure registries are allowed

boolean

false

Whether or not a image build will be performed.

boolean

false

Whether or not an image push will be performed.

boolean

false

Jib选项

除了通用的容器镜像选项外,container-image-jib 也提供了以下选项:

Configuration property fixed at build time - All other configuration properties are overridable at runtime

Configuration property

Type

Default

The base image to be used when a container image is being produced for the jar build

string

fabric8/java-alpine-openjdk11-jre

The base image to be used when a container image is being produced for the native binary build

string

registry.access.redhat.com/ubi8/ubi-minimal

Additional JVM arguments to pass to the JVM when starting the application

list of string

-Dquarkus.http.host=0.0.0.0,-Djava.util.logging.manager=org.jboss.logmanager.LogManager

Additional arguments to pass when starting the native application

list of string

-Dquarkus.http.host=0.0.0.0

Environment variables to add to the container image

Map<String,String>

required

Docker 选项

除了通用的容器镜像选项外, container-image-docker 还提供以下选项:

Configuration property fixed at build time - All other configuration properties are overridable at runtime

Configuration property

Type

Default

Path to the the JVM Dockerfile. If not set ${project.root}/src/main/docker/Dockerfile.jvm will be used If set to an absolute path then the absolute path will be used, otherwise the path will be considered relative to the project root

string

Path to the the JVM Dockerfile. If not set ${project.root}/src/main/docker/Dockerfile.native will be used If set to an absolute path then the absolute path will be used, otherwise the path will be considered relative to the project root

string

S2I 选项

除了通用的容器镜像选项外, container-image-s2i 也提供了以下选项:

Configuration property fixed at build time - All other configuration properties are overridable at runtime

Configuration property

Type

Default

The base image to be used when a container image is being produced for the jar build

string

fabric8/s2i-java:2.3

The base image to be used when a container image is being produced for the native binary build

string

quay.io/quarkus/ubi-quarkus-native-binary-s2i:19.3.0

Additional JVM arguments to pass to the JVM when starting the application

list of string

-Dquarkus.http.host=0.0.0.0,-Djava.util.logging.manager=org.jboss.logmanager.LogManager

Additional arguments to pass when starting the native application

list of string

-Dquarkus.http.host=0.0.0.0

The directory where the jar is added during the assemble phase. This is dependant on the s2i image and should be supplied if a non default image is used.

string

/deployments/

The resulting filename of the jar in the s2i image. This option may be used if the selected s2i image uses a fixed name for the jar.

string

The directory where the native binary is added during the assemble phase. This is dependant on the s2i image and should be supplied if a non-default image is used.

string

/home/quarkus/

The resulting filename of the native binary in the s2i image. This option may be used if the selected s2i image uses a fixed name for the native binary.

string

The build timeout.

Duration

PT5M

About the Duration format

The format for durations uses the standard java.time.Duration format. You can learn more about it in the Duration#parse() javadoc.

You can also provide duration values starting with a number. In this case, if the value consists only of a number, the converter treats the value as seconds. Otherwise, PT is implicitly prepended to the value to obtain a standard java.time.Duration format.

quarkus.pro 是基于 quarkus.io 的非官方中文翻译站 ,最后更新 2020/04 。
沪ICP备19006215号-8
QQ交流群:1055930959
微信群: