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
- https://qiita.com/ot-aoyagi/items/d97b2431fefbf5635e93
- https://qiita.com/teradonburi/items/776e4735395af872320a
- https://qiita.com/yo1000/items/0af36c8bc5e944c1e42a
- https://github.com/SonarSource/docker-sonarqube/blob/master/recipes.md
- https://qiita.com/okamu_/items/1c8e5fde742ca165fa12#sonarqube
- http://blog.applibot.co.jp/blog/2017/09/14/static-code-analysis-with-sonarqube/