LoginSignup
1
1

More than 5 years have passed since last update.

AzureでSonarQube Serverを立てる話

Last updated at Posted at 2018-11-14

はじめに

  • SonarCloudを使わずに仮想マシン上にSonarQube Serverを立てる手順をメモ:writing_hand:

  • 構築できた暁には、Azure DevOps(VSTS)と連携させたい

  • まずはどうやれば一番楽チンにできるかを考えてみる

【案1】Docker HubにあるSonarQube公式Imageを使う

⇒ ✕:↓ここを見るとDatabaseがembedded H2とのこと。ちゃんと使うにはDatabaseのセットアップが必要。

Database configuration
By default, the image will use an embedded H2 database that is not suited for production.

ということで次。

【案2】Bitnamiの提供している仮想マシンイメージを使う

⇒ ✕:Azure契約上、3rd Partyが使えなかった(涙)Billingの問題??

では、次の案。

【案3】BitnamiのコンテナImageをACI(Azure Container Instances)使う

⇒ ✕:SonarQubeとPostgresをdocker-composeで立てるので、ACIじゃ無理だった。

【案4】Linux VMを立ててその上でdocker-composeを使う

⇒ ◯:面倒だが、これでやることにする

  • ということで、【案4】で進める

事前準備

  • Azureアカウント

参考資料

  • 以下の先生の記事を参考しながら、進めます。先生に感謝。

Ubuntuにdockerをインストールする

Docker公式

Docker Compose - インストール

github : docker/compose

Dockerを一般ユーザで実行する

github : bitnami/bitnami-docker-sonarqube
* https://github.com/bitnami/bitnami-docker-sonarqube#readme

作業の流れ

  1. 仮想マシンの作成
  2. ポートの開放
  3. SSHでログイン
  4. Dockerのインストール
  5. Docker-Composeのインストール
  6. 権限設定変更
  7. SonarQubeのインストール
  8. 接続テスト
  9. HTTPS化

【手順1】仮想マシンの作成

  • Azureポータルで、Azure上に仮想マシンを立てる
    • この例では、Ubuntu 18.04 を使っています

【手順2】ポートの開放

  • Azureポータルで、NSGの設定変更を行う
  • SSH(22)HTTP(80)HTTPS(443) を有効にする

【手順3】SSHでログイン

  • SSHで作成した仮想マシンにログインする

Note: AzureポータルのSerial ConsoleからでもOKです。その場合、SSH(22)のポート開放は不要です。

【手順4】Dockerのインストール

  • Dockerをインストールする

リポジトリのセットアップ

# Update the apt package index
$ sudo apt-get update

# Install packages to allow apt to use a repository over HTTPS
$ sudo apt-get install -y \
    apt-transport-https \
    ca-certificates \
    curl \
    software-properties-common

# Add Docker’s official GPG key
$ curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -

# Use the following command to set up the stable repository
$ sudo add-apt-repository \
   "deb [arch=amd64] https://download.docker.com/linux/ubuntu \
   $(lsb_release -cs) \
   stable"

Dockerのインストール

# Update the apt package index
$ sudo apt-get update

# Install the latest version of Docker CE, or go to the next step to install a specific version
$ sudo apt-get install -y docker-ce

インストール後にバージョン確認

# Version Check
$ docker version

【手順5】Docker-Composeのインストール

  • Docker-Composeをインストールする
# Download docker-compose
$ sudo curl -L https://github.com/docker/compose/releases/download/1.23.0/docker-compose-`uname -s`-`uname -m` -o /usr/local/bin/docker-compose

# Change Permission
$ sudo chmod +x /usr/local/bin/docker-compose

【手順6】権限設定変更

  • docker infoコマンドを実行したところエラーが発生した場合、権限を変更する。

  • 以下コマンドを実行

# dockerグループ作成
$ sudo groupadd docker

# 対象ユーザをdockerグループに追加
$ sudo usermod -g docker <your user name>

# サービス再起動
$ sudo /bin/systemctl restart docker.service
  • 一度SSHを抜けて再度入り直し。docker infoコマンドが正常実行できることを確認する

【手順7】SonarQubeのインストール

  • 以下コマンドを実行
# docker-compose定義ファイルをダウンロード
$ curl -LO https://raw.githubusercontent.com/bitnami/bitnami-docker-sonarqube/master/docker-compose.yml

# SonarQubeとPostgresを起動する
$ docker-compose up -d

【手順8】接続テスト

  • Webブラウザでhttp://<your-ip-address>にアクセスしログイン画面が表示されるか確認
    • ホストOSのHTTP(80) にマッピングされているため、ポート名(:9000)は指定しない

【手順9】HTTPS化

  • このままだと暗号化されず丸腰なのでHTTPS化する
  • SonarQubeのHELPによると、リバースプロキシを使ってHTTPS化しろと言っている

Server Configuration
To run the SonarQube server over HTTPS, you must build a standard reverse proxy infrastructure.

  • HTTPS化の手順は以下を参照ください。

ubuntu + nginx + Let's Encrypt でリバースプロキシを立てる話

まとめ

  • Azure上にSonarQubeServerができた!
  • 公式ImageにDatabase(Postgres)内蔵してくれればそれでいいのに。。。
1
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
1
1