diff --git a/sonarqube/README.md b/sonarqube/README.md new file mode 100644 index 0000000..71c68e1 --- /dev/null +++ b/sonarqube/README.md @@ -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= +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= +SONAR_HOST_URL=http://: +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 \ No newline at end of file diff --git a/sonarqube/docker-compose.yml b/sonarqube/docker-compose.yml new file mode 100644 index 0000000..49f964d --- /dev/null +++ b/sonarqube/docker-compose.yml @@ -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 + \ No newline at end of file