SonarQube: Difference between revisions

From bibbleWiki
Jump to navigation Jump to search
Line 18: Line 18:
Now got is working I move to docker-compose. We can use the existing volumes from above with external keyword.
Now got is working I move to docker-compose. We can use the existing volumes from above with external keyword.
<syntaxhighlight lang="yaml">
<syntaxhighlight lang="yaml">
version: '3.7'
     server {
services:
        listen 80;
  sonarqube:
        server_name localhost;
     image: sonarqube
    container_name: sonarqube-bill
    ports:
      - '9000:9000'
      - '9092:9092'
    volumes:
      - 'sonarqube-conf:/opt/sonarqube/conf'
      - 'sonarqube-data:/opt/sonarqube/data'
      - 'sonarqube-logs:/opt/sonarqube/logs'
      - 'sonarqube-extensions:/opt/sonarqube/extensions'


volumes:
        location / {
  sonarqube-conf:
            return 301 https://$host$request_uri;
     external: true
        }
     name: sonarqube-conf
     }
  sonarqube-data:
 
     external: true
     server {
    name: sonarqube-data
        large_client_header_buffers 4 32k;
   sonarqube-logs:
 
    external: true
        listen 443 ssl;
    name: sonarqube-logs
        server_name localhost;
   sonarqube-extensions:
 
     external: true
        ssl_certificate /etc/ssl/certs/sonarqube.crt;
     name: sonarqube-extensions
        ssl_certificate_key /etc/ssl/private/sonarqube.key;
 
        location / {
            proxy_pass        http://172.17.0.1:9000;
            proxy_redirect     off;
            proxy_http_version 1.1;
            proxy_cache_bypass $http_upgrade;
            proxy_set_header  Upgrade $http_upgrade;
            proxy_set_header  Connection keep-alive;
            proxy_set_header  Host $host;
            proxy_set_header   X-Real-IP $remote_addr;
            proxy_set_header  X-Forwarded-For $proxy_add_x_forwarded_for;
            proxy_set_header  X-Forwarded-Proto $scheme;
            proxy_set_header   X-Forwarded-Host $server_name;
            proxy_buffer_size          128k;
            proxy_buffers              4 256k;
            proxy_busy_buffers_size     256k;
        }
     }
</syntaxhighlight>
</syntaxhighlight>



Revision as of 08:51, 16 November 2023

Introduction

This is how to install

docker pull sonarqube

docker volume create sonarqube-conf
docker volume create sonarqube-data
docker volume create sonarqube-logs
docker volume create sonarqube-extensions

docker run -d --name sonarqube -p 9000:9000 -p 9092:9092 -v sonarqube-conf:/opt/sonarqube/conf -v sonarqube-data:/opt/sonarqube/data -v sonarqube-logs:/opt/sonarqube/logs -v sonarqube-extensions:/opt/sonarqube/extensions sonarqube

Remember you can restart docker container if one exists with

docker restart <container>

Move to docker-compose

Now got is working I move to docker-compose. We can use the existing volumes from above with external keyword.

    server {
        listen 80;
        server_name localhost;

        location / {
            return 301 https://$host$request_uri;
        }
    }

    server {
        large_client_header_buffers 4 32k;

        listen 443 ssl;
        server_name localhost;

        ssl_certificate /etc/ssl/certs/sonarqube.crt;
        ssl_certificate_key /etc/ssl/private/sonarqube.key;

        location / {
            proxy_pass         http://172.17.0.1:9000;
            proxy_redirect     off;
            proxy_http_version 1.1;
            proxy_cache_bypass $http_upgrade;
            proxy_set_header   Upgrade $http_upgrade;
            proxy_set_header   Connection keep-alive;
            proxy_set_header   Host $host;
            proxy_set_header   X-Real-IP $remote_addr;
            proxy_set_header   X-Forwarded-For $proxy_add_x_forwarded_for;
            proxy_set_header   X-Forwarded-Proto $scheme;
            proxy_set_header   X-Forwarded-Host $server_name;
            proxy_buffer_size           128k;
            proxy_buffers               4 256k;
            proxy_busy_buffers_size     256k;
        }
    }

Setting up the Scanner

export SONAR_SCANNER_VERSION=4.7.0.2747
export SONAR_SCANNER_HOME=$HOME/.sonar/sonar-scanner-${SONAR_SCANNER_VERSION}-linux
curl --create-dirs -sSLo $HOME/.sonar/sonar-scanner.zip https://binaries.sonarsource.com/Distribution/sonar-scanner-cli/sonar-scanner-cli-$SONAR_SCANNER_VERSION-linux.zip
unzip -o $HOME/.sonar/sonar-scanner.zip -d $HOME/.sonar/
export PATH=$SONAR_SCANNER_HOME/bin:$PATH
export SONAR_SCANNER_OPTS="-server"

I changed by .bashrc to have for next time

export SONAR_SCANNER_VERSION=4.7.0.2747
export SONAR_SCANNER_HOME=$HOME/.sonar/sonar-scanner-${SONAR_SCANNER_VERSION}-linux
export PATH=$SONAR_SCANNER_HOME/bin:$PATH
export SONAR_SCANNER_OPTS="-server"

From there we can generate a token by going to http://localhost:9000/admin/users and look for the token column

Once you have one of there you can do

export SONAR_TOKEN=squ_3c567e0e8c92686895ddblahblah
sonar-scanner -Dsonar.projectKey=testvite2 -Dsonar.sources=. -Dsonar.host.url=http://localhost:9000

Parameters to set in Sonar

"sonar.exclusions": "**/*.test.tsx",
"sonar.tests": "./src",
"sonar.test.inclusions": "**/*.test.tsx,**/*.test.ts",
"sonar.typescript.lcov.reportPaths": "coverage/lcov.info",
"sonar.testExecutionReportPaths": "test-report.xml"

And testing

"sonar.exclusions": "**/myTests/**",
"sonar.tests": "./src/myTests",
"sonar.test.inclusions": "./src/myTests/**/*.test.tsx,./src/myTests/**/*.test.ts"