我正在尝试使用configMaps在Kubernetes上部署SonarQube。
我使用的最新 7.1 映像在 sonar.properties 中嵌入了$SONARQUBE_HOME/conf/
中的配置。该目录不为空,还包含一个 wrapper.conf 文件。
我想将 configMap 安装在我的容器中,而不是/opt/sonar/conf/并指定 sonarQube 读取属性的新路径。
有没有办法做到这一点?(环境变量 ?JVM 参数 ?...)
不建议以任何方式修改此标准配置。但是我们可以看看SonarQube源代码。在此文件中,您可以找到用于读取配置文件的代码:
private static Properties loadPropertiesFile(File homeDir) {
Properties p = new Properties();
File propsFile = new File(homeDir, "conf/sonar.properties");
if (propsFile.exists()) {
...
} else {
LoggerFactory.getLogger(AppSettingsLoaderImpl.class).warn("Configuration file not found: {}", propsFile);
}
return p;
}
因此,conf-path 和文件名是硬编码的,如果文件不存在,您会收到警告。主目录是这样找到的:
private static File detectHomeDir() {
try {
File appJar = new File(Class.forName("org.sonar.application.App").getProtectionDomain().getCodeSource().getLocation().toURI());
return appJar.getParentFile().getParentFile();
} catch (...) {
...
}
所以这也不能改变。上面的代码在这里使用:
@Override
public AppSettings load() {
Properties p = loadPropertiesFile(homeDir);
p.putAll(CommandLineParser.parseArguments(cliArguments));
p.setProperty(PATH_HOME.getKey(), homeDir.getAbsolutePath());
p = ConfigurationUtils.interpolateVariables(p, System.getenv());
....
}
这表明您可以使用命令行参数或环境变量来更改设置。
对于我的问题,我定义了环境变量来在我的 Kubernetes 部署中配置数据库设置:
env:
- name: SONARQUBE_JDBC_URL
value: jdbc:sqlserver://mydb:1433;databaseName=sonarqube
- name: SONARQUBE_JDBC_USERNAME
value: sonarqube
- name: SONARQUBE_JDBC_PASSWORD
valueFrom:
secretKeyRef:
name: sonarsecret
key: dbpassword
我还需要使用 ldap 插件,但在这种情况下无法配置环境变量。由于/opt/sonarqube/conf/
不为空,因此我无法使用 configMap 将配置与图像内容分离。因此,我构建了自己的声纳库贝映像,在声纳中添加了ldap jar插件和ldap设置。
# General Configuration
sonar.security.realm=LDAP
ldap.url=ldap://myldap:389
ldap.bindDn=CN=mysa=_ServicesAccounts,OU=Users,OU=SVC,DC=net
ldap.bindPassword=****
# User Configuration
ldap.user.baseDn=OU=Users,OU=SVC,DC=net
ldap.user.request=(&(sAMAccountName={0})(objectclass=user))
ldap.user.realNameAttribute=cn
ldap.user.emailAttribute=mail
# Group Configuration
ldap.group.baseDn=OU=Users,OU=SVC,DC=net
ldap.group.request=(&(objectClass=group)(member={dn}))