使用 Docker 时未加载 Keycloak SPI 提供程序和层

Bru*_*sar 5 docker wildfly keycloak

我正在尝试使用一些自定义内容(例如 logback 扩展)设置 docker 映像,因此我有一些 CLI 脚本,如下所示:

/subsystem=logging: remove()
/extension=org.jboss.as.logging: remove()

/extension=com.custom.logback: add()
/subsystem=com.custom.logback: add()
Run Code Online (Sandbox Code Playgroud)

我还有 CLI 脚本来配置数据源池、主题、在keycloak-server子系统上添加一些 SPI 等。我将这些脚本放在/opt/jboss/startup-scripts目录中。但是,当我创建容器时,事情运行得不太好。脚本未按预期加载,并且 keycloak 启动时出现错误,未加载领域使用的密码策略等提供程序。

当我使用独立的 Keycloak 时,所有 SPI 提供程序都会正常加载,如下日志所示:

2019-07-25 18:27:07.906 WARN  [org.keycloak.services] (ServerService Thread Pool -- 65) KC-SERVICES0047: custom-password-policy (com.custom.login.password.PasswordSecurityPolicyFactory) is implementing the internal SPI password-policy. This SPI is internal and may change without notice
2019-07-25 18:27:07.909 WARN  [org.keycloak.services] (ServerService Thread Pool -- 65) KC-SERVICES0047: custom-event (com.custom.event.KeycloakServerEventListenerProviderFactory) is implementing the internal SPI eventsListener. This SPI is internal and may change without notice
2019-07-25 18:27:08.026 WARN  [org.keycloak.services] (ServerService Thread Pool -- 65) KC-SERVICES0047: custom-mailer (com.custom.mail.MessageSenderProviderFactory) is implementing the internal SPI emailSender. This SPI is internal and may change without notice
2019-07-25 18:27:08.123 WARN  [org.keycloak.services] (ServerService Thread Pool -- 65) KC-SERVICES0047: custom-user-domain-verification (com.custom.login.domain.UserDomainVerificationFactory) is implementing the internal SPI authenticator. This SPI is internal and may change without notice
2019-07-25 18:27:08.123 WARN  [org.keycloak.services] (ServerService Thread Pool -- 65) KC-SERVICES0047: custom-recaptcha-username-password (com.custom.login.domain.RecaptchaAuthenticatorFactory) is implementing the internal SPI authenticator. This SPI is internal and may change without notice
Run Code Online (Sandbox Code Playgroud)

如果我使用与 Docker 相同的包作为jboss/keycloak:6.0.1映像库,则提供程序不会加载。我将它用作模块,将它们添加到$JBOSS_HOME/modules文件夹中并像下面的脚本一样进行配置:

/subsystem=keycloak-server/: write-attribute(name=providers,value=[classpath:${jboss.home.dir}/providers/*,module:com.custom.custom-keycloak-server])

/subsystem=keycloak-server/theme=defaults/: write-attribute(name=welcomeTheme,value=custom)
/subsystem=keycloak-server/theme=defaults/: write-attribute(name=modules,value=[com.custom.custom-keycloak-server])

/subsystem=keycloak-server/spi=emailSender/: add(default-provider=custom-mailer)
Run Code Online (Sandbox Code Playgroud)

当我在容器内执行脚本时,一切正常。

我尝试使用卷将 jar 与提供程序映射,并在构建自定义映像时复制 jar,但这些方法都不起作用。

我使用的是jboss:keycloak:6.0.1docker 镜像和 Keycloak 6.0.1 独立版,层和模块放在同一目录中。

我究竟做错了什么?将 SPI 提供程序与 Docker 一起使用的技巧是什么,或者该映像不适合生产或此类需求?

LE *_*oît 3

好的,我找到了为什么会发生这种情况

它来自opt/jboss/tools/docker-entrypoint.sh

#################
# Configuration #
#################

# If the server configuration parameter is not present, append the HA profile.
if echo "$@" | egrep -v -- '-c |-c=|--server-config |--server-config='; then
    SYS_PROPS+=" -c=standalone-ha.xml"
fi
Run Code Online (Sandbox Code Playgroud)

它将以集群形式启动 keycloak,因为我认为他们认为独立的产品对于生产来说不安全

独立操作模式仅在您想要运行一个且仅一个 Keycloak 服务器实例时才有用。它不适用于集群部署,并且所有缓存都是非分布式且仅限本地的。不建议您在生产中使用独立模式,因为这样会出现单点故障。如果您的独立模式服务器出现故障,用户将无法登录。此模式实际上仅对测试驱动器和使用 Keycloak Blockquote 的功能有用

要保持“独立模式”,请覆盖图像以添加属性-c standalone.xml作为参数:

CMD ["-b", "0.0.0.0", "-c", "standalone.xml"]
Run Code Online (Sandbox Code Playgroud)