プログラムを中心とした個人的なメモ用のブログです。 タイトルは迷走中。
内容の保証はできませんのであしからずご了承ください。

2017/12/06

SonarQube を docker-compose で動かしてみる

event_note2017/12/06 2:12

C# で作成したアプリケーションの静的解析を行うために、SonarQube をインストールしてみました。

尚、いつもの通り Docker を使ってインストールします。
(Docker に慣れてくると全て Docker で構築したくなってきます。)

環境

  • Docker for Windows

docker-compose.yml

作成した docker-compose.yml は以下のような感じです。
SonarQube は公式のイメージがあるのでそれを使用します。

version: '2'
services:
  sonarqube:
    image: sonarqube
    container_name: sonarqube
    restart: always
    ports:
      - 9000:9000
    environment:
      - SONARQUBE_JDBC_URL=jdbc:postgresql://sonarqube_db:5432/sonar
    volumes:
      - conf:/opt/sonarqube/conf
      - data:/opt/sonarqube/data
      - extensions:/opt/sonarqube/extensions
      - bundled-plugins:/opt/sonarqube/lib/bundled-plugins

  sonarqube_db:
    image: postgres
    container_name: sonarqube_db
    restart: always
    environment:
      - POSTGRES_USER=sonar
      - POSTGRES_PASSWORD=sonar
    volumes:
      - postgresql:/var/lib/postgresql
      # This needs explicit mapping due to https://github.com/docker-library/postgres/blob/4e48e3228a30763913ece952c611e5e9b95c8759/Dockerfile.template#L52
      - postgresql_data:/var/lib/postgresql/data

volumes:
  conf:
  data:
  extensions:
  bundled-plugins:
  postgresql:
  postgresql_data:

管理者でログイン

起動したら以下の管理者 ID でログインできます。

  • Username : admin
  • Password : admin

SonarQube の設定

SonarQube の設定は /opt/sonarqube/conf/sonar.properties に記述します。

プロキシの設定

プロキシ環境下ではプロキシ設定を行っておかないとプラグインのインストールなどができません。

sonar.properties の以下の行のコメントアウトを解除して設定します。

# HTTP proxy (default none)
http.proxyHost=xxx.xxx.xxx.xxx
http.proxyPort=8080
# HTTPS proxy (defaults are values of http.proxyHost and http.proxyPort)
https.proxyHost=xxx.xxx.xxx.xxx
https.proxyPort=8080

LDAP 認証の設定

社内の Active Directory で LDAP 認証を行うための設定を行います。

まずは LDAP Plugin をインストールします。
プロキシ設定を適切に行っていれば [Administration] > [Marketplace] からインストールできます。

sonar.properties に以下を追記します。
内容は環境に応じて適宜変更します。

# LDAP
sonar.security.realm=LDAP
ldap.url=ldap://example.com:389
ldap.bindDn=hoge@example.com
ldap.bindPassword=xxxxxxxx

ldap.user.baseDn=dc=example,dc=com
ldap.user.request=(&(objectClass=user)(sAMAccountName={login}))
ldap.user.realNameAttribute=cn
ldap.user.emailAttribute=mail

SMTP の設定

管理者アカウントでログインします。
[Administration] > [Configuration] > [General] の [Email] で設定します。

参考 URL