LoginSignup
2
1

More than 3 years have passed since last update.

Sonarqubeを6.4→7.9LTSにVerUpしてみた。

Last updated at Posted at 2020-06-24

已む無き事情によりVerUp。本来はあんまりやりたくなかった…。
元々はDocker-composeで構築しており、こんな感じ。(他も色々入っているが省略)

docker-compose.yml
  sonarqube:
    image: sonarqube:6.4
    environment:
      - SONARQUBE_JDBC_USERNAME=sonarqube
      - SONARQUBE_JDBC_PASSWORD=sonarqube
      - SONARQUBE_JDBC_URL=jdbc:postgresql://db:5432/sonarqube
    volumes:
      - /data/sonarqube-conf:/opt/sonarqube/conf
      - /data/sonarqube-data:/opt/sonarqube/data
      - /data/sonarqube-extensions:/opt/sonarqube/extensions
      - /data/sonarqube-plugins:/opt/sonarqube/lib/bundled-plugins
    links:
      - database
    restart: always
    logging:
      driver: "json-file"
      options:
        max-size: "50m"
        max-file: "3"

  database:
    build: postgres
    environment:
      POSTGRES_USER: postgres
      POSTGRES_PASSWORD: postgres
    volumes:
      - /data/db-data:/var/lib/postgresql/data
    stop_signal: SIGINT
    restart: always
    logging:
      driver: "json-file"
      options:
        max-size: "50m"
        max-file: "3"

このサーバであるが、色々開発環境に利用するものが入っており、そうそう簡単に止められないサーバなのである。なので、SonarqubeだけをVerUpするのにはかなり慎重に実施しなければならない状況であった。

6.7.7LTSに上げる。

重要 まずはDBのバックアップをpg_dumpで取る。
元々6.4なので、一旦、6.7.7LTSにあげてから7.9.xLTSに上げる必要がある。

Upgrading across multiple, non-LTS versions is handled automatically. However, if you have an LTS version in your migration path, you must first migrate to this LTS and then migrate to your target version.

Example 1 : 6.1 -> 8.1, migration path is 6.1 -> 6.7.7 LTS -> 7.9.x LTS -> 8.1

まあこれなんだろうな、と思いつつ、やってみるとなぜかうまくいかない。
https://hub.docker.com/layers/sonarqube/library/sonarqube/6.7.7-community/images/sha256-5e6ccd3c1c5247dc8c2280d4886cbb6cc4242e765800c278436a557d4b6478b8?context=explore

確認の仕方は、当然以下である。log確認しないとなんだかわからないし。

docker-compose stop sonarqube
docker-compose up -d sonarqube
docker-compose logs -f sonarqube

全然わからないが、これってもうちょっと前のVerでやるとうまくいくのかなあ、と思い、Community版とか分離されていない頃の6.7.5で試してみる。
https://hub.docker.com/layers/sonarqube/library/sonarqube/6.7.5/images/sha256-fa0aa847b3afe0dcd893774b147238092533468db30563376cba7817b4f0a6e6?context=explore
これだと普通にうまくいく。setupでDB再構築も済ませ、再度6.7.7に上げるとすんなりうまくいく。
あれなんだったんだこれ。
碌にどんなエラーだったかも残してなかった…。

7.9.xLTSに上げる前に…。

requirementsを見ると、OpenJDK11が必須なことを知る。詰んだ…、と思った。

Java

SonarQube scanners require version 8 or 11 of the JVM and the SonarQube server requires version 11. Versions beyond Java 11 are not officially supported.

というのも今回は省略しているが、docker-composeで他に利用しているサービスがあり、そのWebサービスのVerではJava8までしか動作保証しておらず、そこまでVerUpすると芋づる式に確認項目が増えていき、やる気が失せてしまった。
ただ、6.7.7LTSではMarketplaceからのpluginインストールが出来ず、全部マニュアルインストールにしなければならず、しかも最新のものは全く対応できていないため、これではVerUpの意味がない。
https://docs.sonarqube.org/7.9/setup/install-plugin/
うーんどうしようと悩み続け、7.5ならJava8でも動作対応しているし、これにしようかと思ったが、よくよく当該サーバのjava -versionを見るとまだJava7であることが判明。

[root]~# java -version
java version "1.7.0_151"

あれれと思い、sonarqubeの/admin/system?expand=System%2CWebからSystem情報を確認してもやっぱり、Java8である。dockerの中入って、確認してもopenjdk8がインストールされている。
あれこれなんでだ?と思って、6.7.7のDockerfileを確認すると、

ENV JAVA_VERSION=8u212-b04
ENV JAVA_BASE_URL=https://github.com/AdoptOpenJDK/openjdk8-upstream-binaries/releases/download/jdk8u212-b04/OpenJDK8U-
ENV JAVA_URL_VERSION=8u212b04

お。そういうことね。
じゃあサーバにインストールされているJDKは無視できるということで、7.9に上げることを決意。

7.9LTSに上げてみる。

当然のようにこの辺にはまりまくる。

  • vm.max_map_count is greater or equals to 262144
  • fs.file-max is greater or equals to 65536
  • the user running SonarQube can open at least 65536 file descriptors
  • the user running SonarQube can open at least 4096 threads

その中で詰まった箇所を以下に解説。

Error max file descriptors [4096]

Error max file descriptors [4096] for elasticsearch process is too low, increase to at least [65535]

一番悩みまくったのがこれ。これはよくあるファイルディスクプリタの不足で普通は/etc/security/limits.confを修正すればいいんだけど、どう修正しても反映されず、何度docker-composeを再起動しても同じエラーが出まくる。。。 [^1]

探しまくった結果、docker-composeの中でulimitsを設定できることが判明。
http://docs.docker.jp/compose/compose-file.html#ulimits

やっとこれで起動…。

java.lang.OutOfMemoryError: Java heap space

/setupでDBマイグレーションしたらつぎのエラー

sonarqube_1 | 2020.06.23 07:20:47 WARN web[][i.n.c.AbstractChannelHandlerContext] An exception 'java.lang.OutOfMemoryError: Java heap space' [enable DEBUG level for full stacktrace] was thrown by a user handler's exceptionCaught() method while handling the following exception:
sonarqube_1 | java.lang.OutOfMemoryError: Java heap space
sonarqube_1 | 2020.06.23 07:20:47 ERROR web[][o.e.ExceptionsHelper] fatal error

まあ事象はわかるんだけど、どこに設定すればいいのかで悩む。
結論としては、docker-composeファイルにこう設定すればよい。

docker-compose.yml
command: -Dsonar.web.javaOpts=-Xmx2048m

ここまでやって、起動した、と思ったら最後にpluginのVerが合わないので起動できない、でエラー。これも結論としては、全部入れなおせばよいので、以下のファイルを全削除して再起動。

下は既に入れ替え済みのpluginだが。

[root]/data/sonarqube-extensions/plugins# ls -ltr
total 83496
-rw-r--r-- 1 999 999 11757904 Jun 23 16:41 checkstyle-sonar-plugin-4.33.jar
-rw-r--r-- 1 999 999  2488257 Jun 23 16:41 sonar-cobertura-plugin-2.0.jar
-rw-r--r-- 1 999 999  3800973 Jun 23 16:42 sonar-scm-git-plugin-1.11.1.2008.jar
-rw-r--r-- 1 999 999  1890087 Jun 23 16:42 sonar-auth-gitlab-plugin-1.3.2.jar
-rw-r--r-- 1 999 999  3218281 Jun 23 16:43 sonar-python-plugin-2.8.0.6204.jar
-rw-r--r-- 1 999 999 18712457 Jun 23 16:49 sonar-java-plugin-6.3.0.21585.jar
-rw-r--r-- 1 999 999 26676423 Jun 23 16:49 sonar-findbugs-plugin-4.0.0.jar

これで起動。やったね!

と思ったら、どのpluginを最初入れていたのかよくわからなくなったので、プラグイン削除する前に一覧を残しておいた方がいい。(当たり前の話なんだけど、一つ一つ削除してエラーを繰り返してたら面倒になってしまって…)

設定ファイル

変更点を含んだ最終系はこちら。変更点はsonarqubeのみなのでそこの部分だけ。

docker-compose.yml
  sonarqube:
    image: sonarqube:lts
    environment:
      - SONARQUBE_JDBC_USERNAME=sonarqube
      - SONARQUBE_JDBC_PASSWORD=sonarqube
      - SONARQUBE_JDBC_URL=jdbc:postgresql://db:5432/sonarqube
    command: -Dsonar.web.javaOpts=-Xmx2048m
    ulimits:
      nofile:
        soft: 65536
        hard: 65536
    volumes:
      - /data/sonarqube-conf:/opt/sonarqube/conf
      - /data/sonarqube-data:/opt/sonarqube/data
      - /data/sonarqube-extensions:/opt/sonarqube/extensions
      - /data/sonarqube-plugins:/opt/sonarqube/lib/bundled-plugins
    links:
      - datebase
    restart: always
    logging:
      driver: "json-file"
      options:
        max-size: "50m"
        max-file: "3"

補足

Coverageレポートは今までsonar.jacoco.reportPathsを使ってたんだけど、deprecatedになっていることが判明。
https://docs.sonarqube.org/pages/viewpage.action?pageId=1442166
なので、sonar.coverage.jacoco.xmlReportPathsを利用することにする。


test {
            xml.enabled true
}

といっても、基本は上記のみでOK。
xmlファイルはデフォルトで{buildDir}/reports/jacoco/test/jacocoTestReport.xmlとして出力されるが、デフォルト設定で本xmlを読みに行くので、sonar.coverage.jacoco.xmlReportPathsの設定は必要ない。敢えて言えば、(元々設定されていたので)property "sonar.jacoco.reportPaths", "{buildDir}/jacoco/test.exec"のProperties設定を消すのみ。

[^1] :https://qiita.com/fake-deli-ca/items/c3c790e058328d1dde1e

2
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
1