Quarkus 环境变量与测试容器的问题

发布于 2025-01-14 14:33:11 字数 735 浏览 3 评论 0原文

使用测试容器开发集成测试。 application.properties 文件中只有几个字段作为环境变量(例如:将其作为 quarkus.datasource.username=${SER_DB_USERNAME:postgres} 传递)。

通过测试容器设置环境字段时,

GenericContainer<?> someService = new GenericContainer<>(img)
 .withEnv("SER_DB_USERNAME", DataLayer.DB_USERNAME)

测试容器已成功获取该值,但

对于以下环境变量, 在 application.properties 文件中定义的 app.security.enabled=${SER_SEC_ENABLE:true}

@IfBuildProperty(name = "app.security.enabled", stringValue = "true")

环境变量是通过 cmd 提示符使用 -DSER_SEC_ENABLED=true 设置的,但是当尝试在测试容器中传递相同的值时,它始终为空。

GenericContainer<?> someService = new GenericContainer<>(img)
.withEnv("SER_SEC_ENABLE", "true")

Developed the integration tests using Test container. Have few fields as environment variables(Eg: passing it as quarkus.datasource.username=${SER_DB_USERNAME:postgres}) in application.properties file.

When setting environment field through test container

GenericContainer<?> someService = new GenericContainer<>(img)
 .withEnv("SER_DB_USERNAME", DataLayer.DB_USERNAME)

This value is being successfully taken with test containers but

For the below environment variable,
app.security.enabled=${SER_SEC_ENABLE:true} defined in application.properties file

@IfBuildProperty(name = "app.security.enabled", stringValue = "true")

the environment variable is setting through cmd prompt using -DSER_SEC_ENABLED=true, but when trying to pass the same value in test containers, it's always null.

GenericContainer<?> someService = new GenericContainer<>(img)
.withEnv("SER_SEC_ENABLE", "true")

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

临风闻羌笛 2025-01-21 14:33:12

如果没有更多的项目上下文,我至少可以观察到,app.security.enabled 是一个构建属性而不是运行时属性,因此它可能已经在构建时进行了评估。如果您使用已构建的映像/应用程序启动容器,则环境变量很可能不起作用。

此外,使用 -D 标志在 JVM 上设置属性不会产生环境变量,这明确是 JVM 上的系统属性。

Without having more context of the project, I can at least observe, that app.security.enabled is a build property rather than a runtime property, so it might be evaluated at build time already. If you start the container with an already built image/application, it is very likely, that the environment variable has no effect.

Furthermore, setting a property on the JVM using the -D flag does not result in an environment variable, this is explicitly a system property on the JVM.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文