add sonarqube configuration & README.md && additionally improving gitlab configuration

master
TBS093A 2023-03-15 16:42:10 +01:00
parent 786cf3a97d
commit 73d60721e5
2 changed files with 95 additions and 0 deletions

View File

@ -0,0 +1,66 @@
# Sonarqube Configuration
## Setup Sonarqube
before first run, change permissions on sonarqube volumes dirs from root to 1000:
```bash
sudo chown 1000:1000 -R ./volumes/sonarqube
```
before start sonarqube vm.max_map_count must be changed on your host:
```bash
sudo sysctl -w vm.max_map_count=262144
```
after running, you can login with default credentials (admin:admin)
## Configure projects
first step is create access token in gitlab and set it in sonarqube app
next one is choice of repository, if you did choice, you will saw instruction.
we must create ```sonar-project.properties``` file in choosen repo:
```properties
sonar.projectKey=<repo_name_and_hash>
sonar.qualitygate.wait=true
```
we must define also ```.gitlab-ci.yml``` file in choosen repo:
```yml
sonarqube-check:
image:
name: sonarsource/sonar-scanner-cli:latest
entrypoint: [""]
variables:
SONAR_USER_HOME: "${CI_PROJECT_DIR}/.sonar" # Defines the location of the analysis task cache
GIT_DEPTH: "0" # Tells git to fetch all the branches of the project, required by the analysis task
cache:
key: "${CI_JOB_NAME}"
paths:
- .sonar/cache
script:
- |
sonar-scanner \
-Dsonar.projectKey="${SONAR_REPO_ID}" \
-Dsonar.sources=. \
-Dsonar.host.url="${SONAR_HOST_URL}" \
-Dsonar.login="${SONAR_TOKEN}"
allow_failure: true
only:
- develop
```
last step is define envs in gitlab -> choosen repo -> Settings -> CI/CD -> Variables:
```env
SONAR_REPO_ID=<repo_name_and_hash>
SONAR_HOST_URL=http://<sonarqube_url_or_dns>:<sonarqube_shared_port>
SONAR_TOKEN=<sonar_token>
```
you can generate ```SONAR_TOKEN``` in Overview -> Locally
you can get ```SONAR_REPO_ID``` from Overview -> Gitlab-CI in ```sonar-project.properties``` file creating statement

View File

@ -0,0 +1,29 @@
version: "3.9"
services:
sonarqube:
container_name: sonarqube
image: sonarqube:9-community
ports:
- 9000:9000
environment:
SONARQUBE_JDBC_USERNAME: tbs093a
SONARQUBE_JDBC_PASSWORD: aCD32Sfqw
SONARQUBE_JDBC_URL: jdbc:postgresql://postgresql:5432/sonar
volumes:
- ./volumes/sonarqube/data:/opt/sonarqube/data
- ./volumes/sonarqube/logs:/opt/sonarqube/logs
- ./volumes/sonarqube/extensions:/opt/sonarqube/extensions
postgresql:
container_name: postgresql
image: postgres:15.2-alpine
environment:
POSTGRES_USER: tbs093a
POSTGRES_PASSWORD: aCD32Sfqw
ports:
- 5432
volumes:
- ./volumes/postgresql:/var/lib/postgresql