View on GitHub

CAT Lab

CNES Code Analysis Tools Laboratory

CAT - User guide

This guide will explain how to install and start Docker-CAT. Docker-CAT may work better on linux systems.

Quick setup

For a quick setup, you can read the readme file from the official repo.

Complete setup

Pre-requisite

Before using Docker-CAT please check that docker is installed and running.

Getting docker image

From the docker hub

The easiest way to get Docker-CAT is to retrieve Docker image from docker hub with docker pull lequal/docker-cat

Build the image yourself

If needed, you can build the image yourself. If you edit the Docker-CAT image feel free to create a pull request !

To build your own image, just clone the repo and use docker build.

git clone https://github.com/cnescatlab/docker-cat
cd docker-cat
docker build -t <tag> .

Configure & start Docker-CAT

Before starting Docker-CAT you must identify the shared folder and files that should be accessible by SonarQube.

Choose the shared folder

The docker have root access to the shared folder. It is recommended to use a dedicated folder.

Autorize SonarQube to access files inside the shared folder

The ALLOWED_GROUPS variable let you define a list of GID (Group ID) associated with the sonarqube user. All files inside the shared folder should be accessible by at least one of this group to run code analysis.

To find GID in your case, you can follow these steps:

Once you know all GID, add -e ALLOWED_GROUPS="<GID1>;<GID2>;<...>" in the docker start command.

Start Docker-CAT

Now, you just have to use this command to get started ! Just replace <shared_folder> and <GID>.

docker run -d --name docker-cat -v <shared_folder>:/media/Sf_Shared:rw -p 9000:9000 -p 9001:9001 -e ALLOWED_GROUPS="<GID>" lequal/docker-cat:latest

If everything is ok, you can test Docker-CAT at http://localhost:9000

Using Docker-CAT

To interact with Docker-CAT, you have to use the SonarQube web interface. Docker-CAT includes some plugins in SonarQube.

WARNING: if you want persistent data, be sure to link a database (see the corresponding section).

TIPS: After an analysis, docker-CAT generates a report. If you loose it you can generate the report again by selecting “More => CNES Report” in the menu. Then, you can save your report in a safe place.

To run an analysis, copy your code in shared folder then:

Choose a profile

With docker-CAT you have a lot of profile. For most of the languages there is a profile called “Sonar way”. This is a default profile created by SonarQube developers, this general profile can fit most of the projects.

You can also find CNES profiles. They are marked with A, B, C or D (for example: CNES_CPP_D). This profile are created based on CNES standards (RNC) and the letters represent a criticity level. If you are doing a project with CNES, you can contact the Quality Assurance departement to get the best profile for your project. You can also check rules by using the “Rules” tab in the SonarQube interface.

If you want to check all the rules you can use profiles prefixed with “ALL_”. It’s an easy way to do a very complete analysis but with a large project you may find a lot of issues in your code.

You can also find some profile from FindBugs (JAVA). For more information about FindBugs you can refer to the FindBugs repo.

If you already have a database you can just set these environment variables on docker:

In your docker start command you need to add -e SONARQUBE_JDBC_USERNAME=value -e SONARQUBE_JDBC_PASSWORD=value -e SONARQUBE_JDBC_URL=value

If you did not have database, you can use docker to create your database. Just download the docker-compose.yml from the repo, install docker-compose with your package manager (apt, yum, …) and use docker-compose up in your terminal. It will start Docker-CAT and PgSQL

Add plugin

There is 2 ways to add plugin: