Skip to content

Instantly share code, notes, and snippets.

@andanhm
Last active February 19, 2018 09:09
Show Gist options
  • Save andanhm/20e4948b78ab1e59eee0949d13dd7971 to your computer and use it in GitHub Desktop.
Save andanhm/20e4948b78ab1e59eee0949d13dd7971 to your computer and use it in GitHub Desktop.
Sonar MySQL Docker composer
version: '3'
services:
db:
container_name: mysql_sonarqube
image: mysql:latest
ports:
- "3308:3306"
environment:
- MYSQL_ROOT_PASSWORD=sonar
- MYSQL_DATABASE=sonar
- MYSQL_USER=sonar
- MYSQL_PASSWORD=sonar
sonarqube:
image: sonarqube:latest
container_name: sonarqube
ports:
- "9000:9000"
environment:
- SONARQUBE_JDBC_USERNAME=sonar
- SONARQUBE_JDBC_PASSWORD=sonar
- SONARQUBE_JDBC_URL=jdbc:mysql://localhost:3308/sonar?useSSL=false&useUnicode=true&characterEncoding=utf8&rewriteBatchedStatements=true
depends_on:
- db
@andanhm
Copy link
Author

andanhm commented Feb 19, 2018

Issues may encounter and solution to resolve

  1. Sonar Qube is not getting started
    MySql connection issue update localhost to your IP address
    bash $ ifconfig | grep "inet " | grep -v 127.0.0.1

Example: python sonar with code coverage

Code coverage

Install following pip packages

$ pip install nose
$ pip install coverage
$ cd /usr/bin
$ sudo easy_install nose

Running

$ nosetests --with-coverage --cover-package=pylogger --cover-branches --cover-xml
# Required metadata
sonar.projectKey=logger
sonar.projectName=BMS 2.0 Python logger
sonar.projectVersion=0.0.5
sonar.language=py
sonar.sourceEncoding=UTF-8

# Path to source directories (required)
sonar.sources=pylogger

# Enable linting
sonar.python.pylint=/usr/local/bin/pylint
sonar.python.pylint_config=.pylintrc

# Code coverage properties
sonar.python.xunit.reportPath=nosetests.xml
sonar.python.coverage.reportPath=coverage.xml
sonar.python.coveragePlugin=cobertura
sonar.python.pylint.reportPath=pylint-report.txt

# Advanced parameters
# sonar.login=000c10d8733c71e57f843e9a053a77514efb83b2
# sonar.host.url=http://172.16.68.4:9000

# Exclude all classes ending by "test"
sonar.exclusions=**/test/**

# plugin default sonar have 30 rules to extend the rules set download the jar from https://docs.sonarqube.org/display/PLUG/SonarPython 
# docker cp ~/Documents/sonar-python-plugin-1.9.0.2010.jar sonarqube:/opt/sonarqube/extensions/plugins

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment