InfoSec812 / sonarqube-docker

A VERY configurable docker container for running SonarQube
Apache License 2.0
4 stars 8 forks source link

SonarQube Configurable Docker Container

Overview

This docker container runs SonarQube and allows for linking a SQL database container (MySQL, PostgreSQL, MSSQL, or Oracle). You can also use an external SQL database or the embedded H2 database by setting the appropriate configuration variables.

Prerequisites

Building The Container

git clone https://github.com/InfoSec812/sonarqube.git
cd **sonarqube
git checkout <version>
make docker

The version can be something like "5.1.2" or "4.5.5-LTS". To see a list, run "git tag"

You can also build a specific version of the container by changing the VERSION file in the root of the repository and then running:

make docker

Database

By default, SonarQube supports PostgreSQL, Oracle, MSSQL, MySQL, and an embedded H2 database. You should be able to use any database which has a JDBC driver, but that would require customization of this container. After running the container a single time with the H2 driver, the data volume will be populated with the defaults and you could then add the JDBC driver to /sonar/extensions/jdbc-driver//.

For example, to enable Oracle as the database:

Quick Start

By default, this container will use the embedded H2 database running on port 9092 (which you will need to export from the container). To access the embedded DB you will need to modify the docker-compose.yml file to expose the database port as shown below:

sonarqube:
  image: infosec812/sonarqube:5.1.2
  ports:
    - "9000:9000"
    - "9092:9092"
  name:
    - "sonarqube"
  volumes:
    - "/path/to/persistent/data:/data"
  command: /usr/bin/start

If you want to use an external database, you will need to pass in the options detailed in the README.md file (below). The easiest way to accomplish this is to modify the docker-compose.yml file to set up the required environment variables as demonstrated below for an external PostgreSQL database.

sonarqube:
  image: infosec812/sonarqube:5.1.2
  ports:
    - "9000:9000"
  name:
    - "sonarqube"
  environment:
    sonar__jdbc__url: jdbc:postgresql://192.168.1.210:5432/sonar
    sonar__jdbc__username: sonar
    sonar__jdbc__password: sonar
  volumes:
    - "/path/to/persistent/data:/data"
  command: /usr/bin/start

This will configure SonarQube to connect to an external PostgreSQL database with an IP address of '192.168.1.210' using the user/pass of "sonar/sonar". The database "sonar" will have to already have been created manually, but SonarQube will create all of the required tables and database schema.

Upgrading

In most cases, upgrading from one version of this container to the next consists of:

You may need to adjust the URL above depending on your configuration. Also, upgrading plugins may be required.

Restarting the SonarQube Service

In order to install/upgrade plugins you need to restart the SonarQube service. You can do so without having to restart the container if desired. Use the __docker exec__ command as follows:

docker exec -it **sonarqube_sonarqube_1 /usr/bin/restart

Configuration Environment Variables

None of the options below are 'required', but without some of them, the data stored will be lost every time the container is restarted. All default values are listed in parenthesis.