【问题标题】:SonarQube - specify location of sonar.propertiesSonarQube - 指定 sonar.properties 的位置
【发布时间】:2018-12-14 21:37:18
【问题描述】:

我正在尝试使用 configMaps 在 Kubernetes 上部署 SonarQube。

我使用的最新 7.1 image 在 sonar.properties 中有一个配置嵌入在 $SONARQUBE_HOME/conf/ 中。该目录不为空,还包含一个 wrapper.conf 文件。

我想将 configMap 安装在我的容器内的 /opt/sonar/conf/ 以外的其他位置,并为 sonarQube 指定读取属性的新路径。

有没有办法做到这一点? (环境变量?JVM参数?...)

【问题讨论】:

    标签: sonarqube


    【解决方案1】:

    不建议以任何方式修改此标准配置。但是我们可以看看 SonarQube 源代码。在this文件中可以找到读取配置文件的代码:

    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 路径和文件名是硬编码的,如果文件不存在,您会收到警告。主目录是这样找到的:

    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());
        ....
    }
    

    这表明您可以使用命令行参数或环境变量来更改您的设置。

    【讨论】:

    • 我接受这个答案,谢谢。环境变量很有用,但不幸的是,无法使用它们配置 sonar.properties 中的所有 sonarqube 设置。
    【解决方案2】:

    对于我的问题,我在 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 将配置与图像内容分离。因此,我构建了自己的 sonarqube 图像,在 sonar.properties 中添加了 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}))
    

    【讨论】:

      猜你喜欢
      • 2017-11-26
      • 1970-01-01
      • 1970-01-01
      • 2018-01-25
      • 1970-01-01
      • 1970-01-01
      • 2015-05-11
      • 1970-01-01
      • 2011-12-11
      相关资源
      最近更新 更多